Setting and Monitoring a Low-pass Filter


Major Functions for a Low-pass Filter

Setting a Cut-off Frequency

Set a cut-off frequency of a low-pass filter by using setFilterFrequency() function.

dcmotor.setFilterFrequency(freq);

When a cut-off frequency of the low-pass filter is set, signals corresponding to frequencies higher than the cut-off frequency are not counted during encoder monitoring.

Monitoring Noise Counter Values

Monitoring noise counter values by using getFilterPNC() function.

pnc = dcmotor.getFilterPNC();

Example

#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); 
}

Other Functions

Setting a Noise Counter Value

Set or initialize a noise counter value by using setFilterPNC() function.

dcmotor.setFilterPNC(pnc);