mbed code for Farrari board

Dependencies:   DDRO_Farrari mbed

Fork of DDRO_Farrari by Liangzhen Lai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers clock.cpp Source File

clock.cpp

00001 #include "clock.h"
00002 
00003 float ext_freq(DigitalIn* clk_pin)
00004 {
00005     bool last = false;
00006     unsigned int count = 0;
00007     
00008     Timer t;
00009     t.start();
00010     for(int i=0; i<100000; i++){
00011         bool clkval = *clk_pin;
00012         if(clkval && !last){
00013             count++;
00014         }
00015         last = clkval;
00016     }
00017     float time = t.read();
00018     t.stop();
00019     if(count < 1000){
00020         dual_printf("Clk read inaccurate");
00021         pc.printf("Clk count %d\r\n", count);
00022     }
00023     //pc.printf("T: %f\r\nC: %i\r\n", time, count);
00024     
00025     return count / time;
00026 }