<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Eric on Medium]]></title>
        <description><![CDATA[Stories by Eric on Medium]]></description>
        <link>https://medium.com/@ericmwas01?source=rss-9e67776a3a78------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j7_10Pr8l9XW3rm6hPVNLA.jpeg</url>
            <title>Stories by Eric on Medium</title>
            <link>https://medium.com/@ericmwas01?source=rss-9e67776a3a78------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:02:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ericmwas01/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Walk Through Implementing a Single Consumer Single Producer Queue]]></title>
            <link>https://medium.com/@ericmwas01/a-walk-through-implementing-a-single-consumer-single-producer-queue-8f3afa5574a3?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f3afa5574a3</guid>
            <category><![CDATA[cpp-programming]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Sat, 04 Jul 2026 21:57:18 GMT</pubDate>
            <atom:updated>2026-07-04T21:57:18.174Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently started implementing a single consumer single producer queue. On paper, it sounds like a small data structure. In practice, it opens the door to many of the ideas that show up in concurrent software, operating systems, and embedded systems.</p><p>The queue itself is simple.</p><p>The interesting part is everything around it.</p><p>How do two independent systems exchange data without stepping on each other? How do you make that communication efficient? What changes once multiple threads enter the picture?</p><p>Those questions are what make this implementation worth exploring.</p><h3>What Is a Single Consumer Single Producer Queue?</h3><p>Imagine two software components that need to exchange information.</p><p>One component creates data. The other consumes it.</p><p>There are several ways they can communicate.</p><p>One approach is to copy the data from one place to another. This works, but copying becomes expensive as the amount of data grows.</p><p>Another option is shared memory. The producer writes data into a shared memory region and the consumer reads from the same location. This removes the cost of copying, but now both sides must agree on how and when that memory is accessed.</p><p>The third option is a mailbox.</p><p>The producer places a message into the mailbox and continues with its work. The consumer checks the mailbox whenever it is ready and retrieves the message. Neither side needs to wait for the other.</p><p>That is exactly how a single consumer single producer queue works.</p><p>The producer pushes data into the queue. The consumer removes data from the queue whenever it is ready to process it. The queue becomes the meeting point between two independent pieces of software.</p><p>This simple idea makes systems much less dependent on each other and allows both sides to work at their own pace.</p><h3>Why Implement One?</h3><p>A basic queue is easy to write.</p><p>A single threaded implementation can be completed in a short amount of time because there is only one execution path. Reading and writing happen one after another, so there is no competition over shared data.</p><p>Things become more interesting as the system grows.</p><p>Memory suddenly becomes a design decision instead of an implementation detail.</p><p>Should the queue allocate memory using the standard allocator? Should it reserve memory up front? Should it grow when it fills up? The answer depends on the application, the timing requirements, and the available resources.</p><p>Then comes concurrency.</p><p>Once the producer and consumer run on separate threads, they are both accessing the same queue at the same time. Without careful coordination, both threads can modify shared data simultaneously and corrupt the queue.</p><p>This is where queue implementations stop being simple.</p><h3>The Problem With Locks</h3><p>The most common solution is to protect the queue with a mutex.</p><p>Only one thread is allowed inside the queue at any given time. While this guarantees correctness, it also means one thread may spend time waiting for the other.</p><p>That starts to work against the idea of a mailbox.</p><p>The producer should be free to publish data without depending on the consumer. Likewise, the consumer should be able to read available data without unnecessary delays.</p><p>Locks solve one problem while introducing another.</p><h3>Moving Toward Lock Free Programming</h3><p>An alternative is to avoid locks altogether.</p><p>Instead of preventing simultaneous access with a mutex, lock free designs rely on atomic operations.</p><p>An atomic operation updates a shared value as a single indivisible operation. No other thread can observe or interrupt the update halfway through. This makes it possible for multiple threads to coordinate safely without traditional locks.</p><p>Atomic variables become the building blocks that allow the producer and consumer to move through the queue independently while keeping the shared state consistent.</p><p>This is one of the reasons the single consumer single producer queue is such a popular learning exercise. It introduces many of the ideas behind concurrent programming without becoming overwhelmingly complex.</p><h3>The Implementation</h3><p>The implementation linked below intentionally starts with a queue that has no thread safety.</p><p>A producer thread continuously generates random values and publishes them to the queue.</p><p>At the same time, a consumer thread reads values from the same queue.</p><p>Since both threads access shared data without synchronization, the program eventually encounters a data race. Running the program with Thread Sanitizer exposes the issue and shows exactly where the unsafe access occurs.</p><p>Starting with a broken implementation makes the next step much more meaningful. Once the problem is visible, introducing synchronization techniques such as mutexes or atomic operations becomes much easier to understand because they solve a problem you have already observed rather than one that only exists in theory.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f3afa5574a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MAX485 chaos]]></title>
            <link>https://medium.com/@ericmwas01/max485-chaos-0f4f60b78a0e?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f4f60b78a0e</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[system]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[plc]]></category>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Sat, 03 May 2025 07:57:32 GMT</pubDate>
            <atom:updated>2025-05-03T07:57:32.055Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been working on a reactor system that relies on Modbus RTU to read data from temperature and pressure sensors. It’s not my first go — the last reactor I worked on was built around Siemens S7–1200 PLCs and ran well. This one’s a bit different. It uses in-house designed PCBs, which is pretty awesome, and runs on FreeRTOS.</p><p>The system handles multiple processes, controls ball valves, and logs data from all the sensor controllers — including an S7–1200 slave — over Modbus TCP. Getting that TCP link stable took me over three days. But by April 30th, the whole thing was running smoothly.</p><p>Then the scope creep hit.</p><p>Out of nowhere, I was asked to add humidity sensors for data logging. I pushed back — not because it was a bad idea (humidity and ammonia data is valuable), but because you can’t change the scope mid-project without adjusting the timeline. Bolt too much onto a running system and something _will_ break.</p><p>Still, I went along with it. I stayed late, wiring up the humidity sensors and reconfiguring the ammonia sensor I’d previously hooked to an ESP32 using a TTL-to-RS485 converter. I left work at 3 AM and everything was responding perfectly to Modbus polls. Clean data in the holding registers. I figured the next day would be easy: just run the Modbus cables, hook up the sensors to the ESP32 controllers, and start logging.</p><p>Of course, that’s not what happened.</p><p>On May 2nd, the entire Modbus RTU bus went silent. None of the MAX485-based controllers in the panel were sending or receiving data. Oddly enough, when I pulled the same sensors and tested them individually using TTL-to-RS485 modules, they worked fine.</p><p>That made no sense.</p><p>I spent the whole day troubleshooting. Later, another electrical engineer — who also designed the PCBs — joined me. We checked termination resistors, swapped wires, looked for grounding issues, tested signal levels, and even tried fresh boards. The new ones worked. But we still couldn’t figure out why the originals weren’t responding. when communicating with each other but responded when using RS485 to USB converters. I had to leave work at midnight, again.</p><p>Now it’s Saturday, and I’m heading back in to swap out all four MAX485-based PCBs. I still don’t know what caused the bus to break. Could be reflections, electrical noise, something in the grounding. Or maybe it was just something dumb I missed at 3 AM while running on caffeine.</p><p>Here’s the real lesson: the system was working. Stable. Solid. But one late scope change — one “it’s just one more sensor” — and it all fell apart. When time and resources don’t scale with the work, something gives. Sometimes it’s the system. Sometimes it’s the engineer.</p><p>I’m not mad. Just tired. Having headaches and a bit of hallucination from the lack of sleep. This is another lesson learned — not just in embedded systems, but in working within chaos and trying to keep things running anyway.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f4f60b78a0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Troubleshooting Faulty RTDs]]></title>
            <link>https://medium.com/@ericmwas01/troubleshooting-faulty-rtds-0dd07e87137e?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/0dd07e87137e</guid>
            <category><![CDATA[plc-programming]]></category>
            <category><![CDATA[temperature-sensor]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[temperature]]></category>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Fri, 02 May 2025 03:35:09 GMT</pubDate>
            <atom:updated>2025-05-02T03:35:09.794Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Troubleshooting Faulty RTDs</strong></p><h3>1. <strong>Identifying a Faulty RTD</strong></h3><p>Faulty RTDs often produce erroneous values. The following guideline will help you rule out common faults and misconfigurations that account for 90% of the cases.</p><h3><strong>Common Fault Indicators</strong></h3><ol><li><strong>Extremely High Value</strong></li></ol><p>When using 16-bit ADC or any other ADC, a faulty RTD will result in the maximum RTD value and in this case<strong> 65536</strong>.<br>This often indicates an open circuit or disconnected sensor.</p><p>2. <strong>Negative Values</strong><br> RTDs are not expected to return negative raw values when the medium is in ambient or above ambient conditions.<br> <br> <strong>Possible causes of negative values</strong>:<br> <br> 1.<strong> Byte Interpretation Error</strong><br> <br> — Errors in converting bytes to float (e.g., from raw sensor data).<br> <br> — Especially relevant when using custom functions for byte shifting.<br> <br> 2. <strong>Hardware Wiring Error</strong><br> <br> — Inverted connections can cause the sensor to read negative values.<br> <br> — Check the orientation and terminal assignments carefully.</p><h3><strong>Corrective Procedures</strong></h3><p>Once a suspect RTD is identified, the following steps will rule out common faults and misconfigurations:</p><h4>A. <strong>Identify Sensor Location in the Circuit/ Configuration</strong></h4><p>- Map the RTD’s position to determine wiring and connection type.</p><h4>B.<strong> Electrical Testing: Impedance &amp; Continuity</strong></h4><p>After identification of the RTD sensor, electrical troubleshooting begins. Using an example of a 3-Wire RTD Configuration (1 Red + 2 Silver Wires). The following are the corrective steps:</p><ol><li><strong>Impedance measurement </strong><br> <br> Measure impedance between the red wire and each of the silver wires:<br> For <strong>PT1000</strong>: the impendence should be ~1000 Ω and for <strong>PT100</strong>: the impendence should be 100 Ω. <br>Look out for abnormal values which suggest a faulty RTD. A broken wire might register impedence in the megaOhm range and short circuit is &lt;100 Ohm. <br> <br>2. <strong>Continuity Check</strong><br> Measure continuity between the two silver wires. Lack of continuity is a broken internal circuit. Replace the RTD.</li></ol><p>C. If Sensor Passes Tests: Investigate the adjacent hardware circuit and Software configuration.</p><p>1. <strong>Hardware Isolation Tests</strong><br> Connect the RTD to a known working port or PLC module:<br> If it returns valid temperature data. Then the problem is a software or a circuit issue.<br> Swap Sensor Position in primary circuit:<br> If the same sensor works elsewhere → Likely a terminal fault.<br> <br>2.<strong> Software Debugging</strong><br> common issues:<br> <br><strong>a. Byte Shifting Errors</strong><br> <br> — Check the number of bytes being shifted.<br> <br> — Are you using the correct endianness (big-endian vs. little-endian)?<br> <br><strong>b. IEEE-754 Conversion</strong><br> <br> — Ensure you’re properly converting byte data to float.<br> <br> — 🔗 Try using this tool: [IEEE-754 Floating Point Converter](<a href="https://www.h-schmidt.net/FloatConverter/IEEE754.html">https://www.h-schmidt.net/FloatConverter/IEEE754.html</a>)<br> <br> c. <strong>Configuration Mismatches</strong><br> <br> — Are you using a 3-wire RTD in a 2-wire configuration?<br> <br> — Verify correct wiring and terminal assignments.</p><p><strong>3. Final Steps</strong></p><p>The above steps should correct 90% of RTD related issues. If none of the above resolves the issue, document the problem and if you are able to resolve the issue, document it.</p><h3>Custom RTD Modules</h3><ul><li>Check DIP switch settings for RTD interface modules for custom PCBs in this case</li><li>Always remember you have the right configurations in the PLC RTD module.i.e. Type of sensor RTD, sensor wires-three-wire or 4-wire configuration.<br> <br>- Incorrect DIP switch configuration can lead to invalid readings or no signal detection.</li></ul><h3><strong>Conclusion</strong></h3><p>Troubleshooting RTD sensor faults can seem daunting at first but following the above guide will help you eliminate common mistakes and get the system back up and running.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0dd07e87137e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Daisy chaining SPI communication]]></title>
            <link>https://medium.com/@ericmwas01/daisy-chaining-spi-communication-38ea3ccf6732?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/38ea3ccf6732</guid>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Mon, 11 Nov 2024 21:02:55 GMT</pubDate>
            <atom:updated>2024-11-11T21:02:55.334Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.ti.com/lit/an/slvae25a/slvae25a.pdf?ts=1731352798044&amp;ref_url=https%253A%252F%252Fwww.google.com%252F#:~:text=To%20control%20more%20than%2063,pins%20needed%20for%20SPI%20communication.">https://www.ti.com/lit/an/slvae25a/slvae25a.pdf?ts=1731352798044&amp;ref_url=https%253A%252F%252Fwww.google.com%252F</a></p><p>Completed reading the above article by TI on daisy chaining SPI protocol.<br>The protocol is actually simple each message frames has header, address, data and status report from each MCU.</p><p>Interesting fact this process can send up to 1024 bits. Reading and writing 63 devices in series in a matter of 0.205ms (+ a few ns for CS select), for a 50mHz MCU.</p><p>At the end of the article the protocol is implemented for multiple daisy chains. Thinking about this was actually scary, like you can have 4 chains each with 63 devices, reading and writing to each device in 0.8ms.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38ea3ccf6732" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reservoir Sampling]]></title>
            <link>https://medium.com/@ericmwas01/reservoir-sampling-c6cc302c1e9d?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6cc302c1e9d</guid>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Tue, 08 Oct 2024 04:04:32 GMT</pubDate>
            <atom:updated>2024-10-08T04:04:32.934Z</atom:updated>
            <content:encoded><![CDATA[<p>Question 1: what is a fair way of dealing with an over boarded airplane.</p><p><strong>Option 1:</strong></p><p>Fill the plane on a first come first in bases. That way if the plane has a capacity of K seats. K passengers who arrive first fill the plane and {K+1…N} members will not have a seat.</p><p><strong>Limitations</strong></p><p>Option 1 does not give each passenger a fair chance of boarding the plane.</p><p><strong>Option 2 :</strong></p><p>Have a waiting room. Fill the plane with the first K passengers. {K+1… N} have them in the waiting room. Choose at random passengers from the waiting room to replace passenger K in the plane. Each passenger in the plane has a probability of 1/K of replacement, while the complementary of that (probability of not being replaced is K/(K+1)).</p><p><strong>Tricky part</strong></p><p>For each passenger after the K passenger, all have a probability of K/I of being selected to enter the plane, where <em>I</em> is a random number in the set of {0…N}. Therefore, the probability of passengers in the waiting room boarding the plane is K/I.</p><p><strong>Question 2</strong>: When streaming ads how certain are you that the client sees every single ad.</p><p>The question can be answered using the same principle as question 1.</p><ol><li>Have a bitmap of n elements. 0 representing ad is seen and 1 ad is not seen.</li><li>Applying hashing to every subsequent ad after the first k ads, use the result of hash to flip the bits of the bitmap. <br>These are bloom filters.</li></ol><p>Question 2 could be improved by applying multiple hash functions to the ad to reduce chances of false positives.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6cc302c1e9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming scene 1 in Factory IO using openPLC and structured text]]></title>
            <link>https://medium.com/@ericmwas01/programming-scene-1-in-factory-io-using-openplc-and-structured-text-00018d69cefe?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/00018d69cefe</guid>
            <category><![CDATA[plc-programming]]></category>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Thu, 08 Feb 2024 09:16:36 GMT</pubDate>
            <atom:updated>2024-02-08T09:16:36.304Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqvXjk1MsjyU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqvXjk1MsjyU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqvXjk1MsjyU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8813b0d26238e49af2474bc9e522681d/href">https://medium.com/media/8813b0d26238e49af2474bc9e522681d/href</a></iframe><p>The program has 3 variables running, sensor and conveyor1. <br>running is mapped to FactoryIO running start/Play button. <br>sensor — digital input from sensor at the end of the conveyor belt.<br>conveyor1 — digital- output used to control the conveyor belt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*_Wsb__DHKRua-EpeE3q-vA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00018d69cefe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CAN communication]]></title>
            <link>https://medium.com/@ericmwas01/can-communication-2757557e747a?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/2757557e747a</guid>
            <category><![CDATA[bm]]></category>
            <category><![CDATA[can-communication]]></category>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Fri, 26 Jan 2024 14:43:25 GMT</pubDate>
            <atom:updated>2024-01-26T14:46:03.908Z</atom:updated>
            <content:encoded><![CDATA[<p>is a communication protocol used mainly in automobiles. It’s almost similar to I²C communication protocol in that messages are sent in a common data bus. Each message has a unique ID. Devices connected to the data bus read each message and based on the message ID they identify the message packets they require.</p><p>CAN communication can be done using stm32 series boards that have CANTX and CANRX pins and using MCP2551 or using arduino boards.</p><p><strong>Implementing CAN protocol using Arduino</strong></p><p>The component below is MCP2551. That is used to read CAN messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*EQUgwpOmFVvW-2DJtj6Y_w.jpeg" /><figcaption>MCP551 [CAN to SPI protocol]</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*89RGSwnan-8mLpHAJOMrPg.jpeg" /><figcaption>MCP2551 [CAN to UART]</figcaption></figure><p><strong>Challenges I faced implementing CAN communication<br></strong><a href="https://docs.google.com/document/d/1pMntiKeIIHtdrPG5BpbZXmdobg9khHwGtUewwnXWXc8/edit">https://docs.google.com/document/d/1pMntiKeIIHtdrPG5BpbZXmdobg9khHwGtUewwnXWXc8/edit</a></p><p><strong>Implementing CAN <br></strong>The images below are screenshots from a CAN communication channel, that sends CAN messages from one computer to another. <br>Computer 1 simulates code found in a Battery management system. When the BMS receives a CAN REMOTE packet from the CAN receiver, it responds with CAN messages containing Battery information like state of charge, cell voltages, cell currents and battery temperature.</p><p>Below is a link to the code simulating the battery management system.</p><p><a href="https://github.com/eric-14/finalYearProject/blob/main/CAN_BATTERY__copy_20231114051904.ino">https://github.com/eric-14/finalYearProject/blob/main/CAN_BATTERY__copy_20231114051904.ino</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y19t8hL3t1XmcvoH63eTUg.jpeg" /><figcaption>CAN BMS battery</figcaption></figure><p>The image below is a screen shot of the CAN receiver. <br>Here is the link to the code for CAN receiver. <a href="https://github.com/eric-14/finalYearProject/blob/main/CAN__CHARGING_STATION.ino">https://github.com/eric-14/finalYearProject/blob/main/CAN__CHARGING_STATION.ino</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbsI6kYIQ0gNmQDYiKbZXA.jpeg" /><figcaption>CAN Receiver</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6A9W8H3PCpD6L9pLKmAvQ.jpeg" /><figcaption>CAN communication circuit</figcaption></figure><p>The function below is used to read data from a BMS system using CAN communication.</p><p><a href="https://github.com/eric-14/finalYearProject/blob/master/CANfunction.c">https://github.com/eric-14/finalYearProject/blob/master/CANfunction.c</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2757557e747a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack]]></title>
            <link>https://medium.com/@ericmwas01/stack-e4e079cbb4e4?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4e079cbb4e4</guid>
            <category><![CDATA[stack]]></category>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Tue, 23 Jan 2024 17:23:24 GMT</pubDate>
            <atom:updated>2024-01-23T17:23:24.161Z</atom:updated>
            <content:encoded><![CDATA[<p>The stack is a common data structure found in the execution image of any program.</p><p>Execution image is the memory block used by a program and its registers. It consists of the <strong>data </strong>(contains initialized constant and static variables ), <strong>Text </strong>section (instructions of the program) and .<strong>bss</strong> section (uninitialized constant and static variables).</p><p>In assembly to execute a function the execution image of the current program is saved, then the new function’s execution image is initialized and execution starts.</p><p><strong>Types of stack</strong></p><ol><li>full descending</li><li>ascending stack.</li></ol><p><em>This is the most confusing bit and causes a lot of confusion.</em></p><p><strong>Full descending stack</strong></p><p>This is is the most common stack. The stack is defined by the stack pointer(SP) register and base pointer (which can be referred to as frame pointer in ARM instruction set).</p><p>SP defines the start of the stack and is a higher address in the memory space. While bp is a lower address.</p><p>Bp is the base of the stack .</p><p>In 8086</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*tBR0PCuCzKEwbY9EH4L1Zg.png" /></figure><p>In ARM</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*zFPFLoYyj9qZe3qDpn2O5g.png" /></figure><p>stmfd is used to save the execution image in a full descending stack and l dmfd pops the execution image.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4e079cbb4e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing ARM assembly code and creating bin files that are run in qemu]]></title>
            <link>https://medium.com/@ericmwas01/writing-arm-assembly-code-and-creating-bin-files-that-are-run-in-qemu-7d9cbb3fd300?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d9cbb3fd300</guid>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Thu, 18 Jan 2024 08:53:20 GMT</pubDate>
            <atom:updated>2024-01-18T08:55:16.490Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing ARM assembly code and creating bin files that are run in qemu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*h2flUnVUjANQvA-zw2pcIQ.png" /><figcaption>The asembly program</figcaption></figure><p>In the assembly program register R0 and R1 are loaded with values 1 and 2 respectively. In line 7, R0 and R1 are added and the result is stored in register R1. <br>The memory address of the result area is stored in register r2 and using str command the value in register R1 is stored in the memory location in R2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FXQkq05VWyZDm17vKZM4A.png" /><figcaption>script</figcaption></figure><p>The image above is a script file using the arm-none-eabi toolchain to assemble, link, create executable and finally binary file that is loaded to qemu address 0x10000, which is the qemu start address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*0pm6iUZn3zN0HpRwLWu49g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*iVi1C1Eb9podKLeXcH1bdw.png" /></figure><p>Once the bin file is loaded into qemu the command info registers is used to check the values inside the registers. r0 has value 1 and r1 has value 3 which is the sum of 1 + 2.</p><p>The command xp \wd “memory address” is used to read the values at that memory address, in this case xp \wd 0x000100018 has the value 3 which is the memory address of result and the value of R02.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d9cbb3fd300" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Factory IO Automated Warehouse]]></title>
            <link>https://medium.com/@ericmwas01/factory-io-automated-warehouse-5f43ee93e46f?source=rss-9e67776a3a78------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f43ee93e46f</guid>
            <category><![CDATA[factoryio]]></category>
            <category><![CDATA[plc-programming]]></category>
            <dc:creator><![CDATA[Eric]]></dc:creator>
            <pubDate>Sun, 17 Sep 2023 14:22:29 GMT</pubDate>
            <atom:updated>2023-09-17T14:22:29.737Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://youtu.be/wh62SjLF5s4">https://youtu.be/wh62SjLF5s4</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oahK9lldq2TEvVWnUSV_TQ.png" /><figcaption>ladder logic for the auto mode</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsTU8rI-fS6tkP85brJ3Rg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qr44BxLDaIHQ79DXWiwq4w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f43ee93e46f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>