DigitalOut missing the beat???

18 Jun 2012

I'm new to mbed so I could be overlooking something basic here! I traced some wierd problem with IR sensors down to something that looks like my mbed ain't working as it should.

Test code:

#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
DigitalOut irEmitter(p22);
DigitalOut myled(LED1);
int main() {
    pc.baud(9600);  
    while (1) {
        irEmitter.write(1);
        myled = 1;
        wait(0.01);
        irEmitter.write(0);
        myled = 0;
        wait(0.5);
    }
}

I stuck pin 22 on a logic analyzer (afaik a dirty one with Arduino) and I see that pin 22 (irEmitter) misses "beats" now and then. I don't get the nice and regular pattern I should get but see some holes there where pin 22 doesn't get activated! There's nothing connected to mbed for this test, just a probe on pin 22. And yes, the led blinks as it should, no gaps there it beats as expected.

Here's a screenshot of the logic analyzer output for pin 22: http://i50.tinypic.com/264q1s2.png

As you can see it misses some beats, it does not look like there's a pattern to missed beats either. Tried pin 21 with the same results. Did I get a faulty mbed or am I missing something BIG?

19 Jun 2012

I've never used a logic analyser so I may be way off here but it looks to me like it is sampling at some frequency that is slightly too low to guarantee that there will be a sample within the 0.01 seconds that the output is high. The rule is that the sampling frequency has to be at least twice the frequency of what you want to measure.

1/2 * 0.01 = 200 Hz

So there's a few things you could do to check this theory.

Are you able to check if the sampling frequency is greater that 200Hz? If it's not can you increase it?

As you say that the LED is working as you expect you could attach the logic analyser to the LED to see whether you get the same output.

You could increase the wait period to try to find the value at which you don't get this effect.

19 Jun 2012

Ok, confirmed, I don't have a faulty mbed, I have a crapy logic analyzer :) Thank you very much!