Problem
If the loop runs only one simulated pin and uses a filter, it will output normally (analog 1600~2200, filter 0~500), but creating an array to store multiple filtered simulated pin values will cause problems, and the output will be abnormal (10000~80000).
If analog read six sensors, and their value is 1600~2200.
It used the code below.
#include "EMGFilters.h"
#define SERIAL_TX_BUFFER_SIZE 4096 //修改串口接收缓冲区大小为2048
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);
Serial1.begin(250000);
analogReadResolution(12);
}
void loop()
{
long time = millis();
int x[6] = {0,0,0,0,0,0};
int analog[6] = {0,0,0,0,0,0};
for (int index = 0; index < 6; index++)
{
//x[index] = myFilter[index].update(analogRead(SensorInputPin[index]));
analog[index] = analogRead(SensorInputPin[index]);
}
while ((millis() - time) < 2)
{
delayMicroseconds(100);
}
Serial.printf("filter:%d %d %d %d %d %d analog:%d %d %d %d %d %d\n", x[0], x[1], x[2], x[3], x[4], x[5],analog[0],analog[1],analog[2],analog[3],analog[4],analog[5]);
Serial1.printf("<%d,%d,%d,%d,%d,%d>", x[0], x[1], x[2], x[3], x[4], x[5]);
}
Change index<6
to index<2
, and uncomment \\x[index] = myFilter[index].update(analogRead(SensorInputPin[index]));
It will be a normal output using two inputs and filters.
But changing index=0;index<2
to index=0;index<6
will be abnormal output.
If changing to index=3;index<4
or index=2;index<3
...etc, it will be normal output:
Sketch:
XIAO MCU schematic in the HTML: https://files.seeedstudio.com/wiki/Seeeduino-XIAO/res/Seeeduino-XIAO-v1.0-SCH-191112.pdf
I don't have a sensor schematic.
Filter code: https://github.com/oymotion/EMGFilters/blob/master/EMGFilters.cpp
I hope each simulation output to look like the first Gif(normal output), what should I do to achieve this?
myFilter
. But you can define multiple filters in the same way and put them into an array for use in the for loop. Something like this:EMGFilters myFilters[6];
(define an array of 6 EMGFilters). Insetup()
:for(int i=0;i<6;i++) myFilters[i].init(sampleRate, humFreq, true, true, true);
. And in the for loop:envelops[i * 6 + x] = square(myFilters[x].update(analogRead(SensorInputPin[x])));
.