利用 setFilterFrequency() 函数设定低通滤波器的频率。
dcmotor.setFilterFrequency(freq);
设定低通滤波器的截止频率,监控编辑器时,在其频率高的信号将不计量。
通过 getFilterPNC() 函数可以监控低通滤波器的噪声计数值。
pnc = dcmotor.getFilterPNC();
#include <PhpocExpansion.h>
#include <Phpoc.h>
byte spcId = 1;
int freq = 1000;
int count_prev = 0;
int count;
int diff;
ExpansionDCMotor dcmotor(spcId, 1);
void setup() {
Serial.begin(9600);
while(!Serial)
;
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
Expansion.begin();
Serial.println(dcmotor.getPID());
Serial.println(dcmotor.getName());
dcmotor.setPeriod(10000);
dcmotor.setWidth(3000);
}
void loop() {
if(freq > 7000) {
dcmotor.setWidth(0);
return;
}
dcmotor.setFilterFrequency(freq);
// set the noise counter value
count = dcmotor.getFilterPNC();
diff = count - count_prev;
Serial.print("noise count at freq");
Serial.print(freq);
Serial.print(" : ");
Serial.println(diff);
freq += 200;
count_prev = count;
delay(200);
}
通过 setFilterPNC() 函数课初始化或是变更低通滤波器的噪音计数值。
dcmotor.setFilterPNC(pnc);