Liangzhen Lai / Mbed 2 deprecated Orange_Ferrari_board_functional

Dependencies:   DDRO_Farrari mbed

Fork of DDRO_Farrari by Liangzhen Lai

clock.cpp

Committer:
liangzhen
Date:
2014-07-17
Revision:
3:e1a6e12233dd
Parent:
0:84a8bcfbdec9

File content as of revision 3:e1a6e12233dd:

#include "clock.h"

float ext_freq(DigitalIn* clk_pin)
{
    bool last = false;
    unsigned int count = 0;
    
    Timer t;
    t.start();
    for(int i=0; i<100000; i++){
        bool clkval = *clk_pin;
        if(clkval && !last){
            count++;
        }
        last = clkval;
    }
    float time = t.read();
    t.stop();
    if(count < 1000){
        dual_printf("Clk read inaccurate");
        pc.printf("Clk count %d\r\n", count);
    }
    //pc.printf("T: %f\r\nC: %i\r\n", time, count);
    
    return count / time;
}