Several years ago, I wrote a blog post entitled Ternary Operator vs. if/else, which was supposed to be an interesting comparison between the two, except that I totally botched it! The premise is that the ternary operator and if/else statements should compile into identical, so why not just use if/else statements to make the code … Continue reading The Ternary Operator Revisited
Category: C Concepts
3 Tips for Speeding Up Interrupt Handlers
Embedded software developers today are a bit spoiled. Many microcontrollers come with an ecosystem that includes peripheral drivers, an RTOS, middleware and even example application code. Many developers can spend most of their time in high-level application code, ignoring the software that meets the hardware. The problem is that while this prebuilt ecosystem can accelerate … Continue reading 3 Tips for Speeding Up Interrupt Handlers
There is No Hardware
My favorite line from the Matrix is that “there is no spoon”, and today that is a wise statement for embedded software developers to take to heart. Embedded software developers traditionally are hardware centric, believing that they can’t move forward without the hardware (sometimes this is true). Much like Neo, developers need to accept that … Continue reading There is No Hardware
3 Strategies for Handling Errors in Embedded Software
It’s very tempting to assume that a system is going to behave as perfectly in the field as it does on the engineering bench. During development, embedded software is written under the best of conditions. The developer knows, or at least has their own concept of, how the system is supposed to work. Things usually … Continue reading 3 Strategies for Handling Errors in Embedded Software
3 Explicit Programming Tips C Developers Should Follow
You know what they say when you ASSUME, you make an ASS out of U and ME. That’s exactly what developers are doing when they implicitly write their code and ASSUME that other developers can read minds across space and time. Embedded systems developers should be as Explicit as possible in order to avoid ASSUME … Continue reading 3 Explicit Programming Tips C Developers Should Follow
Is the war between C and C++ Over?
Back when I was an engineering student and a budding young engineer, it wasn’t unusual to open (yes physically open) the latest edition of embedded systems magazine and find articles that were contributing to the raging war between C and C++. Each side would present their cases as to why one language was better than … Continue reading Is the war between C and C++ Over?
Using Callbacks with Interrupts
On a weekly basis, I receive a fair number of emails with questions about how to design embedded systems. One question that seems to be asked more frequently than others is how to write a configurable driver that uses callbacks with interrupts. If a developer is writing a driver that will be reused in multiple … Continue reading Using Callbacks with Interrupts
5 Techniques to Delay Code Execution
An interesting problem that often comes up in embedded software implementation is figuring out how to delay code execution. Sometimes a developer might just want there to be a 10-microsecond delay to allow an I/O line to stabilize before reading it or may want a specified time period between reads to debounce it. In this … Continue reading 5 Techniques to Delay Code Execution
7 Steps to Create a Stack Monitor
One of the most painstaking bugs to hunt down in an embedded system is when the stack overflows its boundaries and starts to overwrite memory regions that are nearby. The symptoms of stack overflow usually appear randomly when just the perfect storm of interrupts and function calls are occurring which leads them to be difficult … Continue reading 7 Steps to Create a Stack Monitor
7 Steps to Create a Reusable Debounce Algorithm
A quick google search reveals that there are over 212,000 websites that examine how to debounce a button. After examining a number of them it is obvious that these implementations are not meant for reuse. The implementations and strategies often lack scalability, the ability to debounce multiple buttons easily and portability. They are tightly coupled … Continue reading 7 Steps to Create a Reusable Debounce Algorithm