Jitter free 8-bit ADC
I have done quite a few embedded projects using 8-bit microcontrollers such as Atmega328 or Atmega644 etc. These are the ones that are used in Arduino boards.
These chips have 10-bit DAC converters for reading analog values. The usual problem when pulling the data from these inputs is the jitter. You for example wire a potentiometer as voltage divider and pull the reading in your software. And commonly you end up with readings that tend to toggle between couple different values.
One usually proposed idea to cope with this is the count average value from few samples in series. While this improves the situation, you will still get jitter. And your signal will also react slower.
Now the question is, these are 8-bit microcontrollers, so why is the DAC 10-bit? I’m not sure if this is really the explanation for this, but coincidentially 10-bits seems to be just enough to implement a simple hysteresis algorithm to give you jitter free 8-bit value with no latency.
The idea is to store last “approved” 8-bit reading and compare new reading to it. You will only update this reading if new 10-bit reading mapped to 8-bit would differ from it. The code (Arduino/C++) would be something like:
byte approved;
void loop() {
int p = analogRead(POT);
if ( abs(approved * 4 - p) > 3 ) {
approved = p / 4;
}
}
You might be able to optimize that a bit with some bitmath magic, but it would make the code snippet more messy to understand.