problem
If the loop runs only one or two simulated pin and uses a filter, it will output normally (0~30), but using three or more will output an exception (1000~20000).
#include "EMGFilters.h"
const int SensorInputPin[] = {A0, A1, A2, A3, A4, A5};
EMGFilters myFilter[6];
SAMPLE_FREQUENCY sampleRate = SAMPLE_FREQ_500HZ;
NOTCH_FREQUENCY humFreq = NOTCH_FREQ_50HZ;
void setup()
{
for (int i = 0; i < 6; i++)
{
myFilter[i].init(sampleRate, humFreq, true, true, true);
}
Serial.begin(115200);
}
void loop()
{
int x[6] = {0};
for (int index = 0; index < 3; index++)
{
x[index] = myFilter[index].update(analogRead(SensorInputPin[index]));
delayMicroseconds(500);
}
}
output:
There is no problem with the filter itself, but with the ADC reading value
filter code: https://github.com/oymotion/EMGFilters/blob/master/EMGFilters.cpp
I guess XIAO’s filtering calculations take time, but I tried adding 500 microseconds, 2 milliseconds, and 5 milliseconds, and they didn’t good work.
So I guess XIAO ADC pins exits a problem.
I try to do:
...etc
void loop()
{
Serial.println(myFilter[0].update(analogRead(SensorInputPin[per ADC pin])));
}
XIAO read the output of each pin one by one, and they output normally.
- Why does using pins that continuously read from 0 to 5 cause problems?