InterruptIn speed check

Dependencies:   FastPWM mbed

Fork of InterruptIn_speed by Erik -

main.cpp

Committer:
Sissors_local
Date:
2016-04-27
Revision:
5:d49b6c1a35e3
Parent:
4:f871f375cd99

File content as of revision 5:d49b6c1a35e3:

//This is a mercury test

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

FastPWM pwm(PTA13);
InterruptIn interrupt(PTD5);

volatile int count;

void interrupt_handler(void)
{
    count++;
}


int main (void)
{
    //Start_frequency is 60kHz
    double frequency = 65e3;
    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);
}