<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Max' Tech Blog]]></title><description><![CDATA[Adventures of a technology enthusiast.]]></description><link>http://blog.stiefel.tech/</link><image><url>http://blog.stiefel.tech/favicon.png</url><title>Max&apos; Tech Blog</title><link>http://blog.stiefel.tech/</link></image><generator>Ghost 3.42</generator><lastBuildDate>Sun, 12 Apr 2026 06:55:04 GMT</lastBuildDate><atom:link href="http://blog.stiefel.tech/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Integrating a dog kennel in your garden]]></title><description><![CDATA[<p>When we bought a puppy about a year ago we did not have the facilities that a typical dog owner should have home. Particularly useful is a dog kennel so you can for instance hang up your wet laundry in peace. Also you create a refuge for the dog. A</p>]]></description><link>http://blog.stiefel.tech/integrating-a-dog-kennel-in-your-garden/</link><guid isPermaLink="false">6700eca1cc518800013041f8</guid><category><![CDATA[Dog]]></category><dc:creator><![CDATA[Maximilian Stiefel]]></dc:creator><pubDate>Tue, 08 Oct 2024 19:32:12 GMT</pubDate><media:content url="http://blog.stiefel.tech/content/images/2024/10/SAM_0477-1.JPG" medium="image"/><content:encoded><![CDATA[<img src="http://blog.stiefel.tech/content/images/2024/10/SAM_0477-1.JPG" alt="Integrating a dog kennel in your garden"><p>When we bought a puppy about a year ago we did not have the facilities that a typical dog owner should have home. Particularly useful is a dog kennel so you can for instance hang up your wet laundry in peace. Also you create a refuge for the dog. A dog kennel is often recognized as a safe space for your furry friend. </p><p>As always there are many roads leading to Rome. I would like to share how we have done it. Buying wasn't really an option- way too easy! Moreover, one is under the impression to be able to save money on the D.I.Y. side of things. </p><ol><li>We dug about 60 cm to 1 m into the ground. The ditch was about 30 cm to 60 cm wide.</li><li>Then we plunged concrete blocks into the ground. They should rest upon a bed of sand or gravel. We used gravel and some old concrete plates making it easier to level the whole construction later. In this step it is handy to use a cord in order to get 90° angles and straight lines. </li><li>In the third step we connected the concrete blocks w/ long planks (120 mm x 45 mm) creating the frame for the kennel just a few centimeters above the ground. Important to mention is that our concrete blocks feature a post anchor optimized for 45 mm. Before fastening the planks to the concrete blocks with screws it is important that the frame is leveled. It can be necessary to add or remove material under the concrete blocks if you do not have adjustable post anchors. In our case we tried to hoist or lower the concrete blocks and only for the last 1 cm to 2 cm we shifted the planks inside the post anchors. </li><li>Next up you raise the vertical posts. Our construction utilized 120 mm x 28 mm planks. One could argue that these posts are maybe a bit to puny. The solution is to double them if deemed necessary i a certain place. Anchorage w/ the lower frame was achieved by a L shaped cutout and long screws from the inside of the kennel. </li><li>For the sake of stability we created a second frame connecting all the tops of the posts. 120 mm x 28 mm was used again because it was cheap. When the planks were to short they would have been connected w/ L shaped cutouts, wood glue and screws. </li><li>In this step we designed a simple door and connected the kennel to the deck. Around the door we used some brackets and multiple planks on top of each other to get a sturdier construction. </li><li>Painting. Some elements got colored in "Falu rödfärg" and others white. It is worth mentioning that all wood used in this project is pressure treated since the construction is exposed to a harsh and wet climate. </li><li>Installing fence. We bought a 1.8 m chain wire fence for above the ground and laid a 0.5 m fence in the ground to make escape through dug tunnels impossible. </li></ol><figure class="kg-card kg-image-card"><img src="http://blog.stiefel.tech/content/images/2024/10/SAM_0477.JPG" class="kg-image" alt="Integrating a dog kennel in your garden"></figure>]]></content:encoded></item><item><title><![CDATA[DIY grill]]></title><description><![CDATA[Self-made grill from scrap materials. ]]></description><link>http://blog.stiefel.tech/diy-grill/</link><guid isPermaLink="false">61e16186e76d4f000129e178</guid><category><![CDATA[Welding]]></category><category><![CDATA[Tech]]></category><category><![CDATA[Food]]></category><category><![CDATA[Recycling]]></category><category><![CDATA[Sustainability]]></category><dc:creator><![CDATA[Maximilian Stiefel]]></dc:creator><pubDate>Tue, 11 Jan 2022 16:38:00 GMT</pubDate><media:content url="http://blog.stiefel.tech/content/images/2022/01/20211230_192200.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://blog.stiefel.tech/content/images/2022/01/20211230_192200.jpg" alt="DIY grill"><p>When it is cold and dark in winter some people like to gather, light a fire and denaturate junks of proteins together w/ the help of its heat once it burned down a bit. To do so a sucture is necessary, that gives room for, but also can contain the cheering flames, on the one side. On the other side the setup needs to allow to hold a grill grate once it is time to broil that tasty spareribs. Another important requirement is, that the arrangement can hold a beer, because, it is reasonable to become a little thirsty when cooking over an open fire, that brings the sweat to your face. Of course, it is also convenient to be able to place an empty bord, barbecue cutlery or spices directly next to where the meat is being cooked. Everybody can buy a grill. Everybody can grill with gas. Not everybody can use a scrap barrel and give it a new purpose. I was really trying to get my head arround this complex, but important problem for some time and this is the design I came up with:</p>
<!--kg-card-end: markdown--><figure class="kg-card kg-gallery-card kg-width-wide kg-card-hascaption"><div class="kg-gallery-container"><div class="kg-gallery-row"><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20211230_210235-1.jpg" width="3120" height="4208" alt="DIY grill"></div><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20211230_200655-1.jpg" width="3120" height="4208" alt="DIY grill"></div><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20211230_192209-1.jpg" width="4208" height="3120" alt="DIY grill"></div></div><div class="kg-gallery-row"><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20211230_190733-1.jpg" width="4208" height="3120" alt="DIY grill"></div><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20210213_120857-1.jpg" width="5984" height="3392" alt="DIY grill"></div><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20210213_120844-1.jpg" width="5984" height="3392" alt="DIY grill"></div></div><div class="kg-gallery-row"><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20210213_120826-1.jpg" width="5984" height="3392" alt="DIY grill"></div><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20210213_120823-1.jpg" width="5984" height="3392" alt="DIY grill"></div><div class="kg-gallery-image"><img src="http://blog.stiefel.tech/content/images/2022/01/20210213_120733-1.jpg" width="5984" height="3392" alt="DIY grill"></div></div></div><figcaption>DIY grill from a cut in half brake cleaner barrel and a welded frame.</figcaption></figure><!--kg-card-begin: markdown--><p>Two Xes hold together by three threaded rods make up for the basic structure. The legs are fitted with pads welded onto them so that the grill stands propely and does for instance not get tilted by one leg sinking into the snow. Also it features a stop to be able to get the right angle with each X. With an angle grinder a barrel of brake cleaner was cut in half, that is where wood and/or charcoal can be burned. On one side two arms are attached in a way, that wodden planks could be mounted to form a small surface.</p>
<p>Lesson learned: The grate could be a bit bigger. It is dimensioned to be only slightly bigger than the barrel. If it ended up being just a little misaligned in the heat of the battle, it could easily happen to fall down into the embers.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Electromobility: A rich man 's game?]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>To be honest, I borrowed a bigger junk of the headline from <a href="https://hackaday.com/author/jennylist/">Jenny List</a>, an active <a href="http://hackaday.com">Hackaday</a> author. A recent article of hers<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> inspired me to write something about the whole <em>environmental sustainability is not affordable</em> opinion, that she started off to plead for with cars in her article.</p>]]></description><link>http://blog.stiefel.tech/electromobility-a-rich-mans-game/</link><guid isPermaLink="false">61cc80cde76d4f000129e012</guid><category><![CDATA[Electromobility]]></category><category><![CDATA[Leaf]]></category><category><![CDATA[Tech]]></category><dc:creator><![CDATA[Maximilian Stiefel]]></dc:creator><pubDate>Sun, 09 Jan 2022 21:33:17 GMT</pubDate><media:content url="http://blog.stiefel.tech/content/images/2022/01/photo_2022-01-09_22-31-23.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://blog.stiefel.tech/content/images/2022/01/photo_2022-01-09_22-31-23.jpg" alt="Electromobility: A rich man 's game?"><p>To be honest, I borrowed a bigger junk of the headline from <a href="https://hackaday.com/author/jennylist/">Jenny List</a>, an active <a href="http://hackaday.com">Hackaday</a> author. A recent article of hers<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> inspired me to write something about the whole <em>environmental sustainability is not affordable</em> opinion, that she started off to plead for with cars in her article.</p>
<p>People who know me would describe me as a rather conservative consumer always being very careful and frugal about all sorts of investments. Just like almost every tech guy / girl, I have also been interested in Electric Vehicles (EVs) for a long time. When I was an undegraduate in 2013, as students, we had the possibility offered by the <em>Deutsche Bahn</em> to rent a <a href="https://de.wikipedia.org/wiki/Renault_Zoe">Renault Zoe ZE</a> for 1 € per 15 minutes. I think this programme of the DB is called <a href="https://www.bahn.de/angebot/urlaub/mietwagen/carsharing-flinkster">Flinkster</a> nowadays. The campus was located on the outskirts of the city, but we had one of those car sharing places on it. Four people driving to the city during lunchbreak for an hour to eat a pizza was an offer coming at an attractive price. Ever since, I wanted to own a car with an electric drivetrain. The technology is simply superior due to many aspects, but the economical one, right?</p>
<p>In many cases, driving an EV is quite certainly <em>&quot;a lifestyle choice enabling the well heeled to pat themselves on the back for their chequebook environmentalism&quot;</em> as Ms. List writes in her article. I sure do agree on that one. However, her message about electric cars is wrong from my point of view. It is irrational, as far as I can see, not really fact-based, which is not how a technologist should approach a topic. She writes <em>&quot;I can just about find one that’s maybe a decade old, but when its range is less than I can easily cycle without getting tired it becomes little more than a very expensive automotive project in terms of its use to me&quot;</em>. It would hardly be an exaggeration to say, that cycling a daily commute of 50 km is too much for the average Jill or Joe. A <em>Nissan Leaf</em> with only about 50 % State of Health (SoH) left can easily achieve this task in winter. And this is really only happening after many kilometers of driving, mine has arround 83 % SoH left w/ 8 years on its back. Personally, I do believe Ms. List neither has an integral view on the expenses of a car during the time it is owned by someone in general nor did she look very well into the second-hand market in Great Britain, which is known to be the second biggest sales market for <em>Nissan Leafs</em> in Europe<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup>.</p>
<p>I was wondering about this questions whether an EV is really a way to safe money or not and I came to the conclusion: it depends! If you buy a brand new <a href="https://www.polestar.com/de-ch/polestar-2/">Polestar 2</a> when you would rather buy a second-hand, few years old <em>BMW X1</em> w/ a diesel engine, sure the Scandinavian glamour boy will cost you maybe 70 % less per kilometer, but you will have a long time to catch up with the initial extra costs. On the contrary, if you for instance get a second car w/ an electric drivetrain for you and your family and try to avoid kilometers w/ your combustion car, you may find, that your investment will be amortized in a short time. However, it is important to throw in the determining factors.</p>
<p><img src="http://blog.stiefel.tech/content/images/2022/01/plot_ex_0.png" alt="Electromobility: A rich man 's game?"></p>
<p>I worked on a calculation model and casted it into a <a href="https://git.stiefel.tech/m3x1m0m/EconomicsOfAnElectricVehicle">small script</a>, that I would like to introduce here. The result for <strong>my personal situation</strong> is, that by avoiding to put kilometers on my diesel off-road vehicle by using my <em>Leaf</em> instead, I will have its purchase price completely amortized after ca. 2 1/2 years or ca. 50 000 km, which sounds fine to me.</p>
<p>As always in life, this &quot;financial strategy&quot; comes at a certain risk. If the battery degrades by a too high percentage during this 50 000 km, the amortization would be postponed, because I could not take the car for longer rides. But empirical evidence<sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup> is showing, that the degradation happens at an almost constant rate. Most likely in my climate (central Europe) the 24 kWh 2013 model <em>Leaf</em> battery is subject to calendaric aging only if it is charged / discharged avoiding excessive heat.</p>
<p><img src="http://blog.stiefel.tech/content/images/2022/01/Leaf_SoH_24_kWh_30_kWh_vs_age.jpg" alt="Electromobility: A rich man 's game?"><br>
Source<sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup>: <em>Myall, D.; Ivanov, D.; Larason, W.; Nixon, M.; Moller, H. Accelerated Reported Battery Capacity Loss in 30 kWh Variants of the Nissan Leaf. Preprints 2018, 2018030122 (doi: 10.20944/preprints201803.0122.v1).</em></p>
<p>17 % degradation in 8 years is being equal to approx. 2 1/8 % a year. Extrapolating this number linearly, I will end up with less than 5 1/2 % degradation when the car is amortized. This is a simplification, because the authors of the paper found out, that there is a slight increase of the aging rate of the 24 kWh battery.</p>
<p>Perhaps, this estimation approach is completely wrong, since the battery starts degarding much faster when its approaching its end of life. I could not find much reliable data on the internet about batteries as old as mine. But even assuming a worst-case of another 17 % degaradation, would leave me with 66 % SoH. This would mean that I could still drive for about 80 km until the battery is empty. I commute less than that and the Swiss🇨🇭 average definitely commutes less than that as well, with ca. 15 km a day (one-way)<sup class="footnote-ref"><a href="#fn5" id="fnref5">[5]</a></sup>.</p>
<p>To warp up, I am convinced, that we reached the point in time where you can strike marvelous deals on the second-hand EV market. Depending on your personal circumstances, e.g.</p>
<ul>
<li>Can you charge for free at a lot of places (employer, supermarket etc.)?</li>
<li>Are there tax or insurance bonuses in your state or area?</li>
<li>Are the gas prices high and the electricity prices low?</li>
<li>Can you divert excessive energy from your homestead solar system into the car's battery?</li>
</ul>
<p>chances are higher or lower, that an EV is the more economic choice. Electromobility is definitely not only a rich man's game anymore, but we mortals can play it as well.</p>
<p>For my script<sup class="footnote-ref"><a href="#fn6" id="fnref6">[6]</a></sup> communicating your personal situation to the computer happens by creating a JSON file. It is easiest to copy the one in the <a href="https://git.stiefel.tech/m3x1m0m/EconomicsOfAnElectricVehicle">repository</a> and adapt the values of the objects. I think they should be pretty self-explanatory. Here is the example:</p>
<pre><code class="language-json">{
    &quot;currency&quot;: &quot;CHF&quot;,	
    &quot;kwh_price_home&quot;: 0.2,
    &quot;kwh_price_commercial&quot;: 0.5,
    &quot;juice_litre_price&quot;: 1.75,
    &quot;kilometers_per_year&quot;: 20000.0,
    &quot;ecar&quot;: {
	&quot;label&quot;: &quot;Nissan Leaf 2013&quot;,
        &quot;price&quot;: 7600,
        &quot;taxes&quot;: 0,
        &quot;insurance&quot;: 354,
        &quot;kwh_per_kilometer&quot;: 0.16,
        &quot;maintenance&quot;: 100,
        &quot;charging_behaviour&quot;: {
            &quot;percent_free_charges&quot;: 90,
            &quot;percent_home_charges&quot;: 5,
            &quot;percent_commercial_charges&quot;: 5
         }
    },
    &quot;ccar&quot;: {
        &quot;label&quot;: &quot;Suzuki Grand Vitara 2008&quot;,
        &quot;price&quot;: 7000,
        &quot;taxes&quot;: 350,
        &quot;insurance&quot;: 362,
        &quot;litres_per_kilometer&quot;: 0.08,
        &quot;maintenance&quot;: 1000
    }
}
</code></pre>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p><a href="https://hackaday.com/2021/10/26/being-green-its-a-rich-mans-game/">Being Green, It’s A Rich Man’s Game</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn2" class="footnote-item"><p><a href="https://en.wikipedia.org/wiki/Nissan_Leaf#Global_sales">Wikipedia: Nissan Leaf, Global sales</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn3" class="footnote-item"><p><a href="https://insideevs.com/news/337372/nissan-leaf-30-kwh-battery-degrades-more-rapidly-than-24-kwh-pack/">Inside EVs: Nissan LEAF 30-kWh Battery Degrades More Rapidly Than 24-kWh Pack</a> <a href="#fnref3" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn4" class="footnote-item"><p><a href="https://www.preprints.org/manuscript/201803.0122/v1">Preprints: Accelerated Reported Battery Capacity Loss in 30 kWh Variants of the Nissan Leaf.</a> <a href="#fnref4" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn5" class="footnote-item"><p><a href="https://www.bfs.admin.ch/bfs/de/home/statistiken/mobilitaet-verkehr/personenverkehr/pendlermobilitaet.html">Budesamt f. Statistik: Pendlermobilität</a> <a href="#fnref5" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn6" class="footnote-item"><p><a href="https://git.stiefel.tech/m3x1m0m/EconomicsOfAnElectricVehicle">Script: EconomicsOfAnElectricVehicle</a> <a href="#fnref6" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Electrifying an old farm house]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Our summer cottage entirely reflects the farmer lifestyle of most of our ancestors in Europe. It was a simple life, but most likely also a peaceful one. The husband was typically a lumberjack 👨🪓🌳 in the winter and the wife would take care of the farm during that time besides her</p>]]></description><link>http://blog.stiefel.tech/electrifying-an-old-farm-house/</link><guid isPermaLink="false">613ddcaee76d4f000129decd</guid><category><![CDATA[Solar]]></category><category><![CDATA[Off-grid]]></category><category><![CDATA[Tech]]></category><dc:creator><![CDATA[Maximilian Stiefel]]></dc:creator><pubDate>Mon, 13 Sep 2021 21:10:26 GMT</pubDate><media:content url="http://blog.stiefel.tech/content/images/2021/09/SAM_0175.JPG" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://blog.stiefel.tech/content/images/2021/09/SAM_0175.JPG" alt="Electrifying an old farm house"><p>Our summer cottage entirely reflects the farmer lifestyle of most of our ancestors in Europe. It was a simple life, but most likely also a peaceful one. The husband was typically a lumberjack 👨🪓🌳 in the winter and the wife would take care of the farm during that time besides her many other duties in the household. When the temperatures rose they would both be busy haying for the cattle and farming crops and berries. This property was established in 1937 and a dream must have come true for our predecessors who built this house and lived here.</p>
<p>A Swedish politician named Per Albin introduced a cheap mortage in the 1930s the state would issue for the population on the countryside, that made it possible for many people of the working class to move into their own homestead <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> and <sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup>.</p>
<p>However, there was no running water, electricity or a water closet. According to an old receipt, that was collected and retained carefully by the previous owners along with other important documents, the first time electricity was draged into the house was in the 1970s, but when we took over the house we only found leftovers like cabling and lightbulb lamps in the barn. Most likely the power lines were removed due to the annual basic costs. <em>The most romantic foundation for a clean off-grid energy production from my point of view.</em></p>
<p>So I started reading into the subject. I must admit, that although I have a technical background, this is not as easy as repainting the house with <em>Rödfärg</em>, the typical Swedish red house paint<sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup>. The system I came up with is fully customized to the market situation, as well as the unique energy consumption and storage requirements of an off-grid facility. <a href="https://git.stiefel.tech/m3x1m0m/Mjoelnir">I want to share my design</a> mainly because it was a bit difficult to find something comparable on the WWW, since one needs to adhere to the local regulation, which, however, seems pretty much comparable between different countries at least in Europe.</p>
<h3 id="ouroffgridsolardesign">Our off-grid solar design</h3>
<p>The system can be simplified to something like this:</p>
<p><img src="http://blog.stiefel.tech/content/images/2021/09/block_diagram_solar_overview-1.png" alt="Electrifying an old farm house"></p>
<p>Some quick facts about the system:</p>
<ul>
<li>Maximum peak power output of the generator: <strong>6.56 kW</strong></li>
<li>Four strings à four panels w/ 410 W</li>
<li>Two string à four batteries 120 Ah @ 12V which is about <strong>11.5 kWh</strong> storage capacity</li>
<li>Maximum charge current of 60 A = 2.88 kW.</li>
<li>Completly off-grid, no (integrated) backup generator so far</li>
<li>Electric energy abundance between March and September</li>
<li>3 kW inverter</li>
<li>48 V / 24 V conversion incl. fuse box for LED lights and other appliances that can be DC driven</li>
</ul>
<p>The solar generator is the part that actually converts sunlight into an electric current through the photovoltaic effect <sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup>. Depending on the type of solar cells and the coupling scheme the output voltage varies, but generally speaking, the output voltage here can be rather dangerous, because it is a high DC voltage, no zero crossing. The tracker / charger, comercially available under the term <em>Maximum Power Point Tracker (MPPT)</em>, presents a certain impedance to the generator and converts it to a necessary impedance presented to the batteries. From hereon we are in the 48 V domain, which is uncritical to us human beings.</p>
<p>The illustration below can help to explain what a <em>MPPT</em> is doing: The load is adapted so, that the current and voltage end up in a knee point, where the maximum power under the given environmental circumstances (light, shadow and temperature) is obtained. In the illustration a line goes through the maximum power points. Read more on the subject and find the image source under <sup class="footnote-ref"><a href="#fn5" id="fnref5">[5]</a></sup>.</p>
<p><img src="http://blog.stiefel.tech/content/images/2021/09/Solar-Cell-IV-curve-with-MPP.png" alt="Electrifying an old farm house"></p>
<p>All energy produced ends up being &quot;consumed&quot; instantly through DC devices (ommited in the diagram above), AC devices behind the inverter or stored in the batteries. A 48 V system voltage corresponding to four 12 V batteries in series is chosen, so that the wire diameter does not get too big. For connecting the 3 kW inverter to the 48 V bus bars 50 mm² cables are employed. With insulation this equals a diameter of arround 12 mm. These kind of thick cables are already difficult to bend, so having an even lower voltage e.g. 24 V, corresponding to two lead-acid batteries in series, was not an option for me since we wanted the same convenience that you have in a modern house nowaydays. The premise was to draw loooots of power e.g. with big tools like saws or angle grinders.</p>
<h3 id="doesonlysolarmeanihavetositinthedarkfromtimetotime">Does only solar mean I have to sit in the dark from time to time?</h3>
<p>According to the Swedish ministry for statistics <em>Statistiska centralbyrån (SCB)</em> a Swedish household consumes on average 2000 kWh / anno to 5000 kWh / anno <sup class="footnote-ref"><a href="#fn6" id="fnref6">[6]</a></sup>. We assume that with our rather conservative lifestyle e.g. heating with wood, avoiding long showers etc. we would have an energy need of arround 3000 kWh / anno = 8.2 kWH / day in order to find out when we would not have enough energy available. According to the <em>Victron Energy</em> simulation tool <sup class="footnote-ref"><a href="#fn7" id="fnref7">[7]</a></sup> without additional measures we would sooner or later run out of electric energy when taking a vacation between October and February (cf. diagram below). Not a problem for a summer house is it?</p>
<p><img src="http://blog.stiefel.tech/content/images/2021/09/Daily_yield_over_a_year_solar-2.png" alt="Electrifying an old farm house"></p>
<h3 id="leadacidvslithiumionbattery">Lead-acid vs. lithium-ion battery</h3>
<p>In my opinion, just like driving an electric car (yes I am a big fan!) this is rather a question of economy than a question of technology. The aforementioned design uses flooded lead-acid batteries, that include some smart engineering to make them more durable in terms of the number of cycles and <em>Depth of Discharge (DoD)</em>, not comparable to the lead-acid batteries in your EV or combustion car. A technological reason to go for lead-acid batteries is certainly the cold climate in <em>Norrland</em>. While the Lithium battery chemistry fails you w/ temperatures below 0 °C <sup class="footnote-ref"><a href="#fn8" id="fnref8">[8]</a></sup>, the lead-acid battery still does not freeze below -65 °C <sup class="footnote-ref"><a href="#fn9" id="fnref9">[9]</a></sup>. However, the main reason is, that quality batteries cost so much less most likely due to the time the technology had to evelove. Even the cheapest Chinese Pylontech US2000C <sup class="footnote-ref"><a href="#fn10" id="fnref10">[10]</a></sup> costs arround SEK 3250 / kWh while the technology I am using is arround SEK 700 / kWH and we talke about German quality ware. Of course, Lithium-ion batteries last longer in terms of the number of cycles, which is for our use-case not going to be high in a summer cottage.</p>
<p>The entire design is documented <a href="https://git.stiefel.tech/m3x1m0m/Mjoelnir">here</a>. I will try to keep it up-to-date including the modifications that will likely come in the future.</p>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p><a href="https://www.op.se/artikel/sa-har-kunde-det-se-ut-pa-landsbygden-1942-folj-med-in-i-torpet">Så här kunde det se ut på landsbygden 1942 – följ med in i torpet, 2016</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn2" class="footnote-item"><p><a href="https://www.campiste.com/sw/point-interet/583333-per-albin-torp-byggnadernas-historia">Per Albin-torp - byggnadernas historia</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn3" class="footnote-item"><p><a href="https://en.wikipedia.org/wiki/Falu_red">Falu red</a> <a href="#fnref3" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn4" class="footnote-item"><p><a href="https://en.wikipedia.org/wiki/Photovoltaic_effect">Photovoltaic effect</a> <a href="#fnref4" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn5" class="footnote-item"><p><a href="https://en.wikipedia.org/wiki/Maximum_power_point_tracking">Maximum power point tracking</a> <a href="#fnref5" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn6" class="footnote-item"><p><a href="https://www.scb.se/hitta-statistik/statistik-efter-amne/energi/tillforsel-och-anvandning-av-energi/arlig-energistatistik-el-gas-och-fjarrvarme/">Årlig energistatistik (el, gas och fjärrvärme)</a> <a href="#fnref6" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn7" class="footnote-item"><p><a href="https://mppt.victronenergy.com/#djE7Y3VzdG9tLDQsNCw1NCwtMzAsNTAsNDgsMTAuNzcsMC4wNDksMTEuOCw0MTAsMzguMSwtMC4yOSw0NS43LDEwLDY=">MPPT sizing calculator </a> <a href="#fnref7" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn8" class="footnote-item"><p><a href="https://electronics.stackexchange.com/questions/263036/why-charging-li-ion-batteries-in-cold-temperatures-would-harm-them">Why charging Li-Ion batteries in cold temperatures would harm them?</a> <a href="#fnref8" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn9" class="footnote-item"><p><a href="http://www.elektronikinfo.de/strom/bleiakkus.htm">Bleiakkumulatoren</a> <a href="#fnref9" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn10" class="footnote-item"><p><a href="https://www.victronenergy.com/live/battery_compatibility:pylontech_phantom">Victron &amp; Pylontech UP2500, US2000, US3000, US2000C, US3000C, UP5000, Phantom-S, Force-L1 &amp; L2</a> <a href="#fnref10" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Suboptimal Deutsche Bahn Wifi FIXED]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Recently, I was traveling with the train again and it so happened, that I was coming to Germany🇩🇪. It is not a secret, that things the train operators in neighbouring countries master effortlessly, seem to set a difficult challenge for the <em>Deutsche Bahn (DB)</em>. To feed this statement with numbers:</p>]]></description><link>http://blog.stiefel.tech/suboptimal-deutsche-bahn-wifi-fixed/</link><guid isPermaLink="false">60d06bb7e76d4f000129dd9e</guid><category><![CDATA[Tech]]></category><category><![CDATA[Traveling]]></category><category><![CDATA[Linux]]></category><category><![CDATA[Sailfish]]></category><category><![CDATA[SOCKS]]></category><category><![CDATA[SSH]]></category><dc:creator><![CDATA[Maximilian Stiefel]]></dc:creator><pubDate>Mon, 21 Jun 2021 11:41:47 GMT</pubDate><media:content url="http://blog.stiefel.tech/content/images/2021/06/wifionice.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://blog.stiefel.tech/content/images/2021/06/wifionice.jpg" alt="Suboptimal Deutsche Bahn Wifi FIXED"><p>Recently, I was traveling with the train again and it so happened, that I was coming to Germany🇩🇪. It is not a secret, that things the train operators in neighbouring countries master effortlessly, seem to set a difficult challenge for the <em>Deutsche Bahn (DB)</em>. To feed this statement with numbers: around 20 % of all trains in Germany were late in 2020 and that does not include the trains, that were cancelled for good or trains, that were less than 6 minutes late <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup>.</p>
<p>So it comes as no surprise, that I had problems connecting my Linux distribution workstation to the <em>DB</em> Wifi available on all ICEs<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup>.</p>
<pre><code class="language-bash">$ cat /etc/os-release 
PRETTY_NAME=&quot;Debian GNU/Linux 10 (buster)&quot;
NAME=&quot;Debian GNU/Linux&quot;
VERSION_ID=&quot;10&quot;
VERSION=&quot;10 (buster)&quot;
VERSION_CODENAME=buster
ID=debian
HOME_URL=&quot;https://www.debian.org/&quot;
SUPPORT_URL=&quot;https://www.debian.org/support&quot;
BUG_REPORT_URL=&quot;https://bugs.debian.org/&quot;
</code></pre>
<p>And ofcourse I was not the first person in 2021 that complained, but apparently the <em>DB</em> did not put any measures in place. One problem is the poorely chosen IP addresses range, as people report <sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup> or <sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup>.</p>
<p>The best (quickest) solution I came up with was to connect my <a href="https://sailfishos.org/">Sailfish OS phone</a>🐟 to the Wifi and use it as a Wifi adapter. Since Sailfish OS version 4.0.1.48 (Koli) does up to the best of my knowledge not support Wifi to USB tethering, I had to put in some work.</p>
<p>The trick was to setup a <a href="https://en.wikipedia.org/wiki/SOCKS">SOCKS5</a>🧦 tunnel to the phone using USB as a physical layer. I am gonna start in laying out how I setup the connnection.</p>
<p>You fire up your terminal and type</p>
<pre><code class="language-bash">$ ssh -D 5100 -C -N -q nemo@192.168.2.15
</code></pre>
<p>This forwards all traffic directed to <strong>127.0.0.1:5100</strong> to the phone, which has internet access over Wifi. Data can ofcourse also come back through that port. For more details about SOCKS and the command parameters checkout <sup class="footnote-ref"><a href="#fn5" id="fnref5">[5]</a></sup>. <em>Mattias Geniar</em> explains this much better than I ever could.</p>
<p>Sidenote:</p>
<blockquote>
<p>SOCKS is definitely good for many things especially if you suspect a network, where your traffic is routed through, to have malicious susbscribers, trying to spy on you.</p>
</blockquote>
<p>Next you need to tell your system or individual programs to route the data through the tunnel.</p>
<p>Firefox:<br>
<img src="http://blog.stiefel.tech/content/images/2021/06/firefox_socks5.png" alt="Suboptimal Deutsche Bahn Wifi FIXED"></p>
<p>Telegram:<br>
<img src="http://blog.stiefel.tech/content/images/2021/06/telegram_socks5.png" alt="Suboptimal Deutsche Bahn Wifi FIXED"></p>
<p>Thunderbird:<br>
<img src="http://blog.stiefel.tech/content/images/2021/06/thunderbird_socks5.png" alt="Suboptimal Deutsche Bahn Wifi FIXED"></p>
<p>Optimally, your phone is connected to a VPN or your server using SOCKS as well, since you cannot really trust a public Wifi like that. Enjoy!</p>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p><a href="https://www.ingenieur.de/technik/fachbereiche/verkehr/bahn-das-sind-die-strecken-mit-den-meisten-verspaetungen/">Bahn: Das sind die Strecken mit den meisten Verspätungen, ingenieur.de, 2021</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn2" class="footnote-item"><p><a href="https://inside.bahn.de/wifionice-wlan-ice-login/">WLAN im ICE und Intercity: So nutzen Sie WIFI@DB und WIFIonICE, 2021 </a> <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn3" class="footnote-item"><p><a href="https://community.bahn.de/questions/warum-klappt-login-im-neuen-wifionice-mit-ubuntu-nicht-mehr">Warum klappt Login im neuen WifionICE mit Ubuntu nicht mehr?</a> <a href="#fnref3" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn4" class="footnote-item"><p><a href="https://community.bahn.de/questions/wie-kann-ich-die-wlan-anmeldeseite-in-der-db-lounge-manuell-eingeben-wenn-si--2">Wie kann ich die WLAN-Anmeldeseite in der DB Lounge manuell eingeben, wenn si...</a> <a href="#fnref4" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn5" class="footnote-item"><p><a href="https://ma.ttias.be/socks-proxy-linux-ssh-bypass-content-filters/">Create a SOCKS proxy on a Linux server with SSH to bypass content filters</a> <a href="#fnref5" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Beautiful, custom figures in LaTeX, created the easy way]]></title><description><![CDATA[In this article I am going to describe how to excel expectations of your boss or professor with professionally looking, perfectly embedded images in your LaTeX document without the hassle of using cumbersome libraries such as TikZ.]]></description><link>http://blog.stiefel.tech/nice-images-in-latex-the-easy-way/</link><guid isPermaLink="false">5f416252c357a90001b6a337</guid><category><![CDATA[LaTeX]]></category><category><![CDATA[Tech]]></category><dc:creator><![CDATA[Maximilian Stiefel]]></dc:creator><pubDate>Sun, 23 Aug 2020 10:04:45 GMT</pubDate><media:content url="http://blog.stiefel.tech/content/images/2020/08/screenshot_pulse-2.png" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><h1 id="introduction">Introduction</h1>
<img src="http://blog.stiefel.tech/content/images/2020/08/screenshot_pulse-2.png" alt="Beautiful, custom figures in LaTeX, created the easy way"><p>When I was writing my master thesis<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> I wanted the figures to look professional, meaning I wanted at least the same font in the figure as used all over my document. However, <em>TikZ</em><sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup> was not an option, because I wanted to focus on the actual programming (and signal processing) tasks and not too much on my love for beautiful documents in the little time I was given. I searched the world wide web and I had a Morpheus moment when I came across the <em>inkscape</em><sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup> <em>--export-latex</em> option.</p>
<p><img src="http://blog.stiefel.tech/content/images/2020/08/morpheus_latex-1.jpg" alt="Beautiful, custom figures in LaTeX, created the easy way"></p>
<p>Sounds pretty good, right? The suggested workflow with <em>inkscape</em> is a follows.</p>
<p><img src="http://blog.stiefel.tech/content/images/2020/08/workflow-1.svg" alt="Beautiful, custom figures in LaTeX, created the easy way"></p>
<h1 id="createasvgwpython">Create a SVG w/ Python</h1>
<p>Let's get our hands dirty right away. As a first step an image needs to be created. Theoretically, it does not matter how the <em>SVG</em> is produced. I tried <em>Python</em> and <a href="http://draw.io">draw.io</a>.</p>
<p>The image decorating this post is a screenshot of a <em>LaTeX</em> compiled <em>PDF</em>. To give an example, I am going to show how to make those two plots leveraging <em>Python</em> in conjuction with <em>matplotlib</em><sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup>. Here comes an excerpt of the code, which created those two waveforms.</p>
<pre><code class="language-python">from matplotlib import pyplot as plt
import numpy as np
from matplotlib.ticker import EngFormatter

# Settings
plt.rcParams['font.size'] = 12
plt.rcParams['svg.fonttype'] = 'none'

# Master thesis colors
color0 = '#00285e'

# Sexy formatter engineering style
formatter0 = EngFormatter(unit='')
formatter1 = EngFormatter(unit='s')

w = float(1)/15e3
carriers = 12
x = np.linspace(-15e3*(carriers+2),15e3*(carriers+2),1000)

# Single carrier
b = np.sinc(x*w)
plt.plot(x,b,label=&quot;\$\\frac{sin(f)}{f}\$&quot;, linewidth=3, color=color0)

# Plot formatting
axes = plt.gca()
axes.xaxis.set_major_formatter(formatter0)
axes.set_xlabel(&quot;\$f/\SI{}{\Hz}\$&quot;)
for side in ['right','top','left']:
  axes.spines[side].set_visible(False)
axes.xaxis.labelpad = 15
axes.yaxis.labelpad = 15
plt.title(&quot;Single \gls{NB-IoT} Sub-Carrier&quot;)
plt.yticks([])
plt.savefig(&quot;ofdm_nbiot_sinc.svg&quot;, format=&quot;svg&quot;, transparent=True)
plt.clf()

# Pulse shape
t = np.linspace(-(1/15e3), 1/15e3, 1000)
boxcar = [0]*(len(t)/4) + [1]*(len(t)/2) + [0]*(len(t)/4)
plt.plot(t,boxcar,label=&quot;\$s(t)\$&quot;, linewidth=3, color=color0)

# Plot formatting
axes = plt.gca()
axes.set_xlabel(&quot;\$t/\SI{}{\second}\$&quot;)
axes.xaxis.set_major_formatter(formatter0)
for side in ['right','top','left']:
  axes.spines[side].set_visible(False)
axes.xaxis.labelpad = 15
axes.yaxis.labelpad = 15
plt.title(&quot;\gls{NB-IoT} Pulse-Shape&quot;)
plt.yticks([])
plt.savefig(&quot;ofdm_nbiot_boxcar.svg&quot;, format=&quot;svg&quot;, transparent=True)
plt.clf()
</code></pre>
<p>Now there are two <em>SVGs</em> in that directory, which can be further processed.</p>
<h1 id="convertingthesvgtolatex">Converting the SVG to LaTeX</h1>
<p>The second step is pretty straight forward. Once you have a <em>.svg</em> file. You can feed it into <em>inkscape</em> and their great plugin will take care of (almost) all the rest.</p>
<pre><code class="language-bash">inkscape -D --export-latex --export-filename=./figs/ofdm_nbiot_boxcar.pdf ./figs/ofdm_nbiot_boxcar.svg
</code></pre>
<p>As one can see, in that case all figures are stored in a directory called <em>figs</em>. This might concern you, since you found out, that the produced <em>.pdf_tex</em> file references to <em>ofdm_nbiot_boxcar.pdf</em> directly. I fixed this issue by calling <em>rpl</em>, a neat program to replace strings in files.</p>
<pre><code class="language-bash">rpl -q ofdm_nbiot_boxcar.pdf ./figs/ofdm_nbiot_boxcar.pdf ./figs/ofdm_nbiot_boxcar.pdf_tex
</code></pre>
<p>Fixed it! Basically, you could also open the <em>.pdf_tex</em> output file in a standard editor and just find &amp; replace every occurance (if you have nothing else to do).</p>
<h1 id="interfacingwlatex">Interfacing w/ LaTeX</h1>
<p>All you need to do next is to include the following lines into your <em>LaTeX</em> document.</p>
<pre><code class="language-latex">\begin{figure}[htbp]
  \begin{subfigure}{0.49\columnwidth}
    \centering
    \scriptsize
    \def\svgwidth{\columnwidth}
    \input{./figs/ofdm_nbiot_boxcar.pdf_tex}
    \caption{}
    \label{fig:ofdm_nbiot_boxcar}
  \end{subfigure}
  \begin{subfigure}{0.49\columnwidth}
    \centering
    \scriptsize
    \def\svgwidth{\columnwidth}
    \input{./figs/ofdm_nbiot_sinc.pdf_tex}
    \caption{}
    \label{fig:ofdm_nbiot_sinc}
  \end{subfigure}
  \caption{Pulse shape of a \gls{NB-IoT} signal (a) and spectrum of one subcarrier (b).}
  \label{fig:ofdm_shape_spectrum_1}
\end{figure}
</code></pre>
<p>In the example above each figure is scaled to the <em>\columnwidth</em> by calling <em>\def\svgwidth{\columnwidth}</em>. Moreover, the font size is set to <em>\scriptsize</em> (read all about it in <sup class="footnote-ref"><a href="#fn5" id="fnref5">[5]</a></sup>). These parameters can be modified to suit your personal needs. Above all there is a small document describing the <em>inkscape</em> plugin <sup class="footnote-ref"><a href="#fn6" id="fnref6">[6]</a></sup>.</p>
<h1 id="addingconvenience">Adding convenience</h1>
<p>Personally, I typically set up a small build system with <em>Make</em> <sup class="footnote-ref"><a href="#fn7" id="fnref7">[7]</a></sup> if I work on a larger LaTeX document for a longer time. However, there are many folks out there who appreciate the convenience, that <a href="https://www.overleaf.com/">overleaf.com</a> poses, which I fully understand. Sometimes you also just work on some small LaTeX document and do not want to set up a complicated directory structure including a custom build system. I do this as well. For this reason, I wrote the prehaps ugliest webapp in the world. This webapp does all the aforementioned steps (after you have created a <em>SVG</em>) for you.</p>
<p><a href="https://git.stiefel.tech/m3x1m0m/vector2latex">Here</a> is the source code and you can access this app under <a href="https://v2l.stiefel.tech/converter.php">v2l.stiefel.tech/converter.php</a>.</p>
<p><strong>How to use the app?</strong></p>
<ol>
<li>Enter the name of the directory where you have stored your images e.g. <em>figures</em>.</li>
<li>Upload the <em>SVG</em> file.</li>
<li>Press <em>Convert</em>.</li>
<li>Download the resulting files.</li>
</ol>
<p>If you have any suggestions what to change about this app, please let me know in the comments below.</p>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p><a href="http://uu.diva-portal.org/smash/record.jsf?pid=diva2%3A1275343&amp;dswid=-78">IOT CONNECTIVITY WITH EDGE COMPUTING, Maximilian Stiefel, 2018</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn2" class="footnote-item"><p><a href="https://www.overleaf.com/learn/latex/TikZ_package">TikZ</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn3" class="footnote-item"><p><a href="https://inkscape.org/">inkscape</a> <a href="#fnref3" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn4" class="footnote-item"><p><a href="https://matplotlib.org/">matplotlib</a> <a href="#fnref4" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn5" class="footnote-item"><p><a href="https://tex.stackexchange.com/questions/24599/what-point-pt-font-size-are-large-etc#24600">LaTeX Font Size</a> <a href="#fnref5" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn6" class="footnote-item"><p><a href="https://mirror.kumi.systems/ctan/info/svg-inkscape/InkscapePDFLaTeX.pdf">How to include an SVG image in LATEX</a> <a href="#fnref6" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn7" class="footnote-item"><p><a href="https://www.gnu.org/software/make/">GNU Make</a> <a href="#fnref7" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[GHDL and modularity- Keeping your digital design clean]]></title><description><![CDATA[VHDL supports clean modular structures enabling to easily reuse your code. In this post I will explain how to create a VHDL library for simulation utilizing GHDL in combination with GTKWave and optionally blend these with the advantages of a git submodule.]]></description><link>http://blog.stiefel.tech/ghdl-and-modularity-keeping-your-digital-design-clean/</link><guid isPermaLink="false">5f1ecf738a44df00018bc9e2</guid><category><![CDATA[VHDL]]></category><category><![CDATA[GHDL]]></category><category><![CDATA[GTKWave]]></category><category><![CDATA[git]]></category><dc:creator><![CDATA[Maximilian Stiefel]]></dc:creator><pubDate>Thu, 30 Jul 2020 21:16:01 GMT</pubDate><media:content url="http://blog.stiefel.tech/content/images/2020/07/beautiful_k210_bga.png" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://blog.stiefel.tech/content/images/2020/07/beautiful_k210_bga.png" alt="GHDL and modularity- Keeping your digital design clean"><p><a href="https://en.wikipedia.org/wiki/VHDL"><em>VHDL</em></a> supports clean modular structures enabling to easily reuse your code. In this post I will explain how to create a <em>VHDL</em> library for simulation utilizing <em>GHDL</em> <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> in combination with <em>GTKWave</em> <sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup> and optionally blend these with the advantages of a <em>git submodule</em> <sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup>.</p>
<p>Both <em>GHDL</em> and <em>GTKWave</em> are free (as in freedom) software bundles licenced under the <em>GPLv2</em> <sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup>. <em>git</em> is licences under ... well you certainly already know.</p>
<h1 id="packagesandlibrariesinvhdl">Packages and libraries in VHDL</h1>
<p>Writing your first line of <em>VHDL</em> code implies accessing a library (provided, that you write your code in a linear fashion). Every digital designer working with <em>VHDL</em> is familiar with statements like the following.</p>
<pre><code class="language-vhdl">library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
</code></pre>
<p><em>ieee</em> is the library shipped with the <em>VHDL</em> compiler and simulator, which is <em>GHDL</em> in our case. <em>std_logic_1164</em> and <em>numeric_std</em> are so called packages. <em>std_logic_1164</em> provides us with types like <em>std_logic</em> and corresponding values like <em>'1'</em> or <em>'U'</em>. Whereas <em>numeric_std</em> deals with numerical computation involving e.g. the type <em>unsigned</em>.</p>
<p>Let's dive into it and take a look at the <em>std_logic_1164</em> package. Depending on the <em>VHDL</em> standard (<em>VHDL</em> is maintained by the <em>IEEE</em> <sup class="footnote-ref"><a href="#fn5" id="fnref5">[5]</a></sup>) a different package is used. One implementation can be found in the <em>GHDL</em> repository <sup class="footnote-ref"><a href="#fn1" id="fnref1:1">[1:1]</a></sup> under <em>libraries/ieee/stdlogic1164.vhdl</em>. In this file we find a lot of interesting things to look at. For instance, we find the declarations for the edge detectors, which are typically employed when sequential logic needs to be created.</p>
<pre><code class="language-vhdl">-------------------------------------------------------------------
-- edge detection
-------------------------------------------------------------------
function rising_edge  (signal s : STD_ULOGIC) return BOOLEAN;
function falling_edge (signal s : STD_ULOGIC) return BOOLEAN;
</code></pre>
<p>Packages in <em>VHDL</em> consist of a declaration and a body. Those two parts can be in one or two seperate files (per package). To give an example, in <em>GHDL</em> for the package <em>std_logic_1164</em> there is the file <em>stdlogic1164.vhdl</em></p>
<pre><code class="language-vhdl">package std_logic_1164 is
-- Declarations
end std_logic_1164;
</code></pre>
<p>and the file <em>std_logic_1164-body.vhdl</em> in the very same directory:</p>
<pre><code class="language-vhdl">package body std_logic_1164 is
-- Implementations
end std_logic_1164;
</code></pre>
<p>The edge detectors for instance are implemented like this (in this particular <em>VHDL</em> version).</p>
<pre><code class="language-vhdl">-------------------------------------------------------------------
-- edge detection
-------------------------------------------------------------------
function rising_edge (signal s : STD_ULOGIC) return BOOLEAN is
begin
return (s'event and (To_X01(s) = '1') and
        (To_X01(s'last_value) = '0'));
end rising_edge;

function falling_edge (signal s : STD_ULOGIC) return BOOLEAN is
begin
return (s'event and (To_X01(s) = '0') and
        (To_X01(s'last_value) = '1'));
end falling_edge;
</code></pre>
<p>If you want to improve on the structure of your <em>VHDL</em> code your own library (or even libraries) are the best bet you have. The first step is to create a package and define e.g. components inside it. I am not going into the details of <em>VHDL</em> packages too much because others have done that very well before me <sup class="footnote-ref"><a href="#fn6" id="fnref6">[6]</a></sup>. Do your research and then you can take the next step.</p>
<h1 id="addingalibrarytoyourproject">Adding a library to your project</h1>
<p>If this was a cookbook the following section would present a recipe on how to cook the dish I promised in the introduction. First you should have a recent version of <em>GHDL</em>, <em>GTKWave</em> and <em>git</em> installed. As a reference I share my setup with you here.</p>
<pre><code class="language-bash">$ gtkwave --version
GTKWave Analyzer v3.3.98 (w)1999-2019 BSI
...
</code></pre>
<pre><code class="language-bash">$ ghdl --version
GHDL 1.0-dev (v0.37.0-819-g9828b513) [Dunoon edition]
...
</code></pre>
<pre><code class="language-bash">$ git --version 
git version 2.20.1
</code></pre>
<p>If you have not already, then now it is time to fire up your favorite shell.</p>
<p>So, let's assume you want to create some design, that takes <a href="https://git.stiefel.tech/m3x1m0m/max_uart_vhdl/">my UART implementation</a> as a building block. Assuming, that you use <em>git</em> already to track your design files, we start with creating a submodule.</p>
<pre><code class="language-bash">git submodule add https://git.stiefel.tech/m3x1m0m/max_uart_vhdl.git
</code></pre>
<p>Submodules <sup class="footnote-ref"><a href="#fn7" id="fnref7">[7]</a></sup> are a great way to improve the live of designer who dislikes reinventing the wheel. In a <em>VHDL</em> file, let's call it <em>top.vhd</em> in this example we want to instatiate a <em>UART</em> transmitter and interface with the rest of our design. In the section above we saw, that we need to tell the compiler about the library and the packages within, which kind of makes the creation of a package necessary in the first place. I made a very simple package <em>uart.vhd</em>. It is part of the submodule, that we just added.</p>
<pre><code class="language-vhdl">-- uart.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

package uart_pkg is
  component uart_tx is
    port(
          i_clk_baudrate  : in  std_logic;
          i_reset_n       : in  std_logic;
          i_tx_send       : in  std_logic;
          i_tx_data_vec   : in  std_logic_vector(7 downto 0);
          o_tx_pin        : out std_logic;
          o_tx_sent       : out std_logic
        );
  end component;
end package;
</code></pre>
<p>Because of the package we now can simply add the <em>UART</em> transmitter to our design adding the following lines of code to the aforementioned <em>top.vhd</em>.</p>
<pre><code class="language-vhdl">library max_uart;
use max_uart.uart_pkg.all;
-- Alternatively we could write ...
-- use max_uart.uart_pkg.uart_tx;
</code></pre>
<p>Now we reached a turning point. The remaining tasks are tool specific and I will show, which commands have to be issued to get it done with <em>GHDL</em> and <em>GTKWave</em>.</p>
<p>In <em>Lattice Diamond</em> adding libraries is also a piece of cake. I might share how I have done it in a later blog post.</p>
<h1 id="librariesinghdl">Libraries in GHDL</h1>
<p>The directory structure looks like this for my specific case.</p>
<pre><code class="language-bash">$ tree .
.
├── LICENSE
├── pixel_line_cnt.gtkw
├── pixel_line_cnt_tb.vhd
├── pixel_line_cnt.vcd
├── pixel_line_cnt.vhd
├── README.md
├── top.gtkw
├── top_tb.vhd
├── top.vcd
├── top.vhd
└── uart_vhdl
    ├── clock_divider_tb.vhd
    ├── clock_divider.vhd
    ├── LICENSE
    ├── README.md
    ├── string_sender.gtkw
    ├── string_sender_tb.vhd
    ├── string_sender.vhd
    ├── top_ecp5_eval.lpf
    ├── top.gtkw
    ├── top_tb.vhd
    ├── top.vhd
    ├── uart_tx.gtkw
    ├── uart_tx.pcf
    ├── uart_tx_tb.vhd
    ├── uart_tx.vhd
    └── uart.vhd
</code></pre>
<p>First, we tell <em>GHDL</em> about the necessary design files in the submodule. To not polute the <em>UART</em> directory with output files, it makes sense to create a work directory. The same applies for the main project.</p>
<pre><code class="language-bash">$ mkdir uart_vhdl/work &amp;&amp; mkdir work
</code></pre>
<p>There are more advanced usage options of <em>GHDL</em>, but for now we analyze individual files, check if we have everything and then execute our simulation.</p>
<p>In my particular case I need the following files to be known be <em>GHDL</em>.</p>
<pre><code class="language-bash">$ ghdl -a --workdir=uart_vhdl/work --work=max_uart uart_vhdl/uart.vhd
$ ghdl -a --workdir=uart_vhdl/work --work=max_uart uart_vhdl/uart_tx.vhd
$ ghdl -a --workdir=uart_vhdl/work --work=max_uart uart_vhdl/clock_divider.vhd

$ ghdl -a --workdir=work --work=work pixel_line_cnt.vhd
$ ghdl -a -Puart_vhdl/work --workdir=work --work=work top.vhd
</code></pre>
<p>If the top design where the library is included can be analyzed w/o <em>GHDL</em> puking, you have done everything right.</p>
<p>Basically, two libraries are created: The default work library and our own library, which is called <em>max_uart</em> in that case.</p>
<p>With the <em>--dir</em> option we can check whether it <em>GHDL</em> understood what we want from it.</p>
<pre><code class="language-bash">$ ghdl --dir --workdir=uart_vhdl/work --work=max_uart
# Library max_uart
# Directory: uart_vhdl/work/
package uart_pkg
entity clock_divider
architecture clock_divider_rtl of clock_divider
entity uart_tx
architecture uart_tx_rtl of uart_tx
</code></pre>
<p>Nice! The same we can do for our default work library to double-check if <em>GHDL</em> is set up straight. I can now analyze and execute the testbench of my top design, the entity <em>top_tb</em>.</p>
<pre><code class="language-bash">$ ghdl -a -Puart_vhdl/work --workdir=work --work=work top_tb.vhd
$ ghdl -r -Puart_vhdl/work --workdir=work --work=work top_tb --vcd=top.vcd
</code></pre>
<p><em>--vcd</em> creates a file, that we can feed into our wave viewer. I noticed, that <em>GHDL</em> can be quite bitchy with the order of CLI arguments. I guess there is no <em>argparse</em> implementation for <em>Ada</em>- haha. (<em>GHDL</em> is written in <em>Ada</em>.)</p>
<p>For further information on <em>GHDL</em> usage you should take a look at the <em>GHDL</em> manual <sup class="footnote-ref"><a href="#fn8" id="fnref8">[8]</a></sup>.</p>
<p>As a last step we ask GTKWave to display the freshly generated waveforms.</p>
<pre><code class="language-bash">$ gtkwave top.vcd top.gtkw
</code></pre>
<p>Personally, I like to have my sessions settings stored in a <em>.gtk</em> file as you can see above.</p>
<p>I hope this article helped you to get your head around how to construct a clean design structure for your VHDL project, that leverages <em>GHDL</em>, a tremendous tool.</p>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p><a href="http://ghdl.free.fr/">GHDL</a> <a href="#fnref1" class="footnote-backref">↩︎</a> <a href="#fnref1:1" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn2" class="footnote-item"><p><a href="http://gtkwave.sourceforge.net/">GTKwave</a> <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn3" class="footnote-item"><p><a href="https://git-scm.com/">Git</a> <a href="#fnref3" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn4" class="footnote-item"><p><a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPLv2</a> <a href="#fnref4" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn5" class="footnote-item"><p><a href="https://www.ieee.org/">IEEE</a> <a href="#fnref5" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn6" class="footnote-item"><p><a href="https://www.nandland.com/vhdl/examples/example-package.html">Package File - VHDL Example</a> <a href="#fnref6" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn7" class="footnote-item"><p><a href="https://git-scm.com/book/en/v2/Git-Tools-Submodules">7.11 Git Tools - Submodules</a> <a href="#fnref7" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn8" class="footnote-item"><p><a href="https://buildmedia.readthedocs.org/media/pdf/ghdl/latest/ghdl.pdf">Chapter 10.6  Library commands, GHDL manual</a> <a href="#fnref8" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>