InterruptIn speed check

Dependencies:   FastPWM mbed

Fork of InterruptIn_speed by Erik -

main.cpp

Committer:
Sissors
Date:
2013-06-22
Revision:
1:8fb0b4376b5d
Parent:
0:6f6ef334f848
Child:
3:7745ac0591aa

File content as of revision 1:8fb0b4376b5d:

#include "mbed.h"
#include "FastPWM.h"

FastPWM pwm(p21);
InterruptIn interrupt(p22);

volatile int count;

void interrupt_handler(void)
{
    count++;
}


int main (void)
{
    //Start_frequency is 60kHz
    double frequency = 60e3;
    pwm = 0;
    interrupt.rise(&interrupt_handler);

    while(1) {
        //Set PWM period, reset count
        pwm.period(1/frequency);
        count = 0;

        //Enable PWM at 50% dutycycle for 1 second
        pwm = 0.5;
        wait(1);
        pwm = 0;

        printf("Expected %.0f edges, measured %d edges.\n", frequency, count);
        if (count < frequency * 0.9) {
            printf("Test failed at %.0fkHz!\n\n", frequency / 1000);
            break;
        }
        printf("Test succeeded at %.0fkHz!\n\n", frequency / 1000);
        frequency += 10e3;

    }
    while(1);
}