Strange behaviour on certain analog reads

Status
Not open for further replies.

frankzappa

Well-known member
Hello. I'm getting some kind of "stepping" problems on certain pins as though the average signal goes up one step and stays there and sometimes it's a step lower. I'm averaging the signal and it seems the behaviour is different depending on how I shift it. If I add say a value of 0.5 to the sensor readings to shift the readings up by a value of 0.5 it might jump up or down by a value of maybe 1.5 or so.

It almost seems like it's rounding errors of some kind.

However it only occurs on two of the 8 pins I'm using.

Any ideas?

I'm reading two sensors at a time and going through all 8 pins very fast using the ADC library.
Does it matter which two sensors I read simultaneously on the two ADC's? Maybe it's not a good idea to read two adjacent sensors simultaneously and I should read two that are apart from eachother? Right now they are kind of scrambled.

It could also be electrical problems but I don't think so as it seems to only occur on two of the pins. Almost seems like some pins are worse quality than others since the signal quality I'm getting on the other pins is ridiculously good.

Thanks.
 
Hello. I'm getting some kind of "stepping" problems on certain pins as though the average signal goes up one step and stays there and sometimes it's a step lower. I'm averaging the signal and it seems the behaviour is different depending on how I shift it. If I add say a value of 0.5 to the sensor readings to shift the readings up by a value of 0.5 it might jump up or down by a value of maybe 1.5 or so.

It almost seems like it's rounding errors of some kind.

Which Teensy? How are you averaging? Can you post your code in fact?
 
Which Teensy? How are you averaging? Can you post your code in fact?

Teensy 4.

My program is huge but I can upload the code for the filter, it's an ewma filter:

Code:
constexpr float C_FILTERALPHA = 0.04; 


float filterEWMA(float sensorValue, uint32_t i)
{
float filteredValue = C_FILTERALPHA * sensorValue  +  (1 - C_FILTERALPHA) * g_previousFilteredValue[i];
g_previousFilteredValue[i] = filteredValue;

return filteredValue;
}

As for the ADC stuff it's just reading two sensors at a time and while it's reading the sensors I work on the previous two sensor readings.
 
This is very weird. When I change the C_FILTERALPHA to a double in stead of float the signal gets worse on some sensors and better on others.

I think it could be a math problem.
 
I think I figured it out.

Before I did two calculations on the sensor signal before going to the filter. Now I'm going to the filter first, looks very clean now.
 
Hence the existence of the Forum rule that you initially ignored! You get many eyes on the problem.
 
Status
Not open for further replies.
Back
Top