Why You Should Incorporate Digital Input Sampling in Your Embedded System
I particularly enjoy shopping in the supermarket on the weekend. In the grocery section, there are samples of various food products that range from tuna spread to white coffee. While I enjoy hopping from one sample stations to another, my 5 years old son shamelessly always asks for a second helping.
In electronics, sampling carries a different meaning than leisurely eating a variety of snacks. In an embedded system, digital input signals play an important role in telling the system what is the next course of action. I realized how important digital input sampling is when a vehicle parking machine that I was servicing decided to slam down the automatic barrier on a luxury car before it passes through. This is how you can use digital input sampling to avoid having to deal with these sorts of scenarios.
What Is Input Sampling And Why It’s Important
The first signal sampling concept that I picked up in my college days is the Nyquist Sampling Theorem, where a bandlimited signal can be reconstructed when it is sampled by at least twice of its original frequency. In my design, I find this approach helpful, not in reconstructing waveforms but in eliminating my systems from behaving erratically.
Theoretically, digital signals are translated to logic 1 and 0. In an embedded system, they are often represented by a voltage value. If a microcontroller operates at 3.3V, logic 1 will be 3.3V and logic 0 will be at 0V. On paper, these logic level looks like a perfect horizontal line that runs continuously until the logic state changes. In reality, these signals are often punctuated by electrical noises that cause sudden spike or drop in voltage level.
In an auto payment parking system, there are automatic barriers on the entrance and exit in a designated parking area. Drivers usually access these areas by retrieving a ticket from the machines or by flashing a proximity card. The parking machines that guard the entrance and exit are equipped with vehicle detectors. These detectors use logic levels to indicate the presence of a vehicle in its sensing area.
In the case where the automatic barrier came down on the luxury car, the system falsely detected a negative signal from the entrance detector when the vehicle was passing through. It closed the barrier while the vehicle was under it. When this incident repeated itself in a few different sites, I requested to look into the firmware for the machines. I realized, in horror, that the decision to close the barrier was being made by evaluating a single instance of the vehicle detector’s signal.
The last thing you want is for the automatic barrier to slam on your car, just because it falsely believe your car has passed through.
How To Sample Digital Inputs In An Embedded System
Generally, digital sampling involves capturing the value of a signal at a specific interval and storing it in a cyclic buffer. A cyclic buffer is a method of buffering in microcontrollers. A value is stored as a variable array in the Static Random Access Memory (SRAM) and when it reaches its end, it overwrites at the beginning. Depending on the application, a number of samples could vary between 5 to 10, with a sampling period of 1 millisecond.
Using this method, the microcontroller has more than one value to base its next action in its logic algorithm. In the case of electrical noises in the vehicle detector, the microcontroller may get one false value reading out of 10 samples, and prevent closing the automatic barrier before the car passes through. In critical applications, the programmer can make even stricter requirements for evaluating samples. This is done by requiring all of the samples to have the same logic before proceeding with the algorithm.
Implementing digital sampling in firmware is easy, and they stabilize the system effectively.
In my situation with the parking system, I made a quick fix to the firmware that incorporated this straightforward sampling method. That way the problematic parking system couldn’t inflict more damage on other vehicles, When the updated firmware was deployed, the parking machines stopped closing the barrier unpredictably. Of course, it goes without saying that digital sampling within the firmware can be less effective if the PCB itself was not properly designed with signal integrity in mind.
Since parking machines need to operate reliably in a robust environment and can experience heavy usage, stability and durability are both important design criteria. I’ve since upgraded designs using circuit design software, like Altium Designer and Altium’s CircuitStudio, and keep high-speed signals away from critical digital inputs with its routing design rules.
Have questions about increasing the reliability of your embedded system with digital sampling? Talk to our experts at Altium now.