Blog Post #2
Understanding the MCU
A Micro Controller, or MCU for short is a little bit different from the normal processor you might find in your personal computer. MCUs are special because they include everything you need right in the chip itself. In a processor you might find in a personal computer, all these peripherals need to be externally connected; a good example is the RAM sticks you install to the motherboard.
Micro Controllers are special because they are cheap and can serve exact functions and only the exact functions the developer wants it to run. It would be far too expensive to put a full fledged Intel / AMD processor in a vacuum. After all, in today’s world, the vacuum must vacuum, but it also must recharge itself, contact the motors to spin the brushes, perhaps dispense a liquid cleaning solution while running.
The code that runs on the MCU will do that and only that, whereas an Intel/AMD based processor needs BIOS, an OS like Windows or Linux, and runtime environments to execute the code. For example, in a Micro Controller, the CPU core can be instructed specifically to interrupt and run the code responsible for initiating and maintaining the charging of the battery when it’s plugged in.
Additionally, since all the peripherals of the MCU are contained within the MCU chip, this also saves on circuit board real estate. MCU’s are also considerably smaller in size than PC based processors.
This brings me to the next topic. Have you ever wondered how you could run two while loops at the “same time” on a single core?
I’m sure not many people actually wonder that, but I’ll tell you anyways!
A Real Time Operating System, or RTOS for short allows you to do just that. The reason I put the words “same time” into quotes, is because most of the time, RTOS is run on a single core. Why is that important you might ask? Well rather than just saying iykyk, the answer is that a single core only allows you to work on “one” instruction at a time. So how could you run two while loops at the same time?
The Power of Context Switching
By implementation of a context switch, we can simply tell the MCU to “save” the state of the current task, and switch to a different task.
In this way, the processor is still only doing one thing at a time, but the tasks are switched frequently enough that it appears to the user that all the tasks are happening simultaneously. This is exactly what an RTOS does.
Why does all this matter? It’s all about Priorities.
When developing MCU code, you have your superloop. The superloop is where all the functionality is built. Normally, someone might think, “I’ll just create a state machine for each of my tasks, and the state of all the tasks will be coded into their own function – wrapped state machines. The issue with this is that over time, you will learn that some of these items should not be running when more important functions need to run.
This can lead to the dreaded spaghetti code.
Before you know it, you have globals everywhere, interrupts firing on top of each other and you end up over constraining the very system you built from the ground up.
That’s where RTOS comes in. With the power of RTOS, each of your tasks is implemented into it’s own superloop. You can still develop your state machines, but you can use the RTOS framework to prioritize tasks above others. In the next post, I’ll talk more about prioritization of tasks as well as interrupts and why they are important.
Blog Post #1
Hi there, my name is Kevin and this is my attempt at blogging.
Above is an image of one of my more recent projects. What’s truly interesting about this picture is the idea that I was testing a serial communication protocol that allows two microcontrollers to communicate over 1 single wire. As you can see there’s definitely more than 1 wire here…
If you’re not familiar with serial communication protocols, its basically like a USB connection but between two “chips”. Sometimes you need communication between two processors, or from a processor to a sensor, etc.
More commonly known are UART – Universal Asynchonous Receive Transmit, Or I2C – Inner Integrated Circuit, or even SPI – Serial Peripheral Interface. All of these protocols pass information digitally and serially over wires.
In this case, the requirement was that there would only be one cable available for use to communicate between two systems that needed to communicate with each other. Thus, my idea was to use the serial protocol 1-Wire.
The real reason you see so many wires, is that to test out this idea, I had to do so using what we call evaluation boards. Here, we are dealing with circuit boards that chip manufactures make so that people can “evaluate” the chips they are trying to sell you. Among those “eval” boards were other items like level shifters, a logic analyzer, and one of my favorites, an Oscilloscope (OScope for short).
My Capstone Project
The capstone project I chose revolves around Real Time Operating Systems or RTOS for short.
An RTOS allows the embedded programmer to write their code in an event-driven and task prioritized way. I have not used RTOS before and I’m very excited to break into this methodology.
Why I love embedded
The reason I enjoy embedded systems so much is that I get an excuse to play with hardware. In my mind, when you write code and get to see a circuit come to life, there’s no better feeling. To me, there is something special about working at the low levels of hardware, drivers, communication to sensors, and specification of the hardware itself.
My previous degree is in molecular biology. My hope is to someday bridge the gap between the biological sciences and engineering by working on things like biosensors, microfluidics, lab on chip capabilities and the like.
IFF you make it this far, I would like to leave you with a thought that has always come to mind.
If you take a “Standard” human cell and you look inside, many of the functions of the cell can be mapped to components that make up a computer. A few examples:
– Mitochondria (Power house of the cell) = Power supply of the computer.
– Nucleus (Brains of the cell) = Processor
– DNA / RNA (Where all your genes are coded) = ROM / RAM
If that didn’t wow you enough, you can store about 1.5 GB of information in just one human cell. The average human body has 37.2 Trillion cells.