Anthony Mukuka Mwila / Mbed OS InterruptCounterTimertestUnit
Committer:
Amwila
Date:
Tue Oct 03 17:54:57 2017 +0000
Revision:
1:6017f9971cc8
Parent:
0:2a502be30ec8
Child:
2:4772acaa0e64
This the Test Code template for timing the counts of an input pulse train

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Amwila 0:2a502be30ec8 1 #include "mbed.h"
Amwila 0:2a502be30ec8 2
Amwila 1:6017f9971cc8 3 // Interrupt Initialisation
Amwila 0:2a502be30ec8 4 InterruptIn BLM_CHANNEL_A(PG_5);
Amwila 0:2a502be30ec8 5
Amwila 1:6017f9971cc8 6 //Variable Initialisation
Amwila 1:6017f9971cc8 7 int A_count = 0 ;
Amwila 1:6017f9971cc8 8 int FinalCountTime =0 ;
Amwila 1:6017f9971cc8 9 Timer Count_Timer ;
Amwila 1:6017f9971cc8 10 // Interrupt Counter Increment Function
Amwila 0:2a502be30ec8 11 void IncA()
Amwila 0:2a502be30ec8 12 {
Amwila 0:2a502be30ec8 13 A_count ++ ;
Amwila 0:2a502be30ec8 14 printf("%d",A_count);
Amwila 0:2a502be30ec8 15 }
Amwila 1:6017f9971cc8 16
Amwila 1:6017f9971cc8 17 int main()
Amwila 0:2a502be30ec8 18 {
Amwila 1:6017f9971cc8 19
Amwila 0:2a502be30ec8 20 while (true) {
Amwila 0:2a502be30ec8 21
Amwila 1:6017f9971cc8 22 if (A_count == 1)
Amwila 1:6017f9971cc8 23 {
Amwila 1:6017f9971cc8 24 // Starting timer at 1 Count
Amwila 1:6017f9971cc8 25 Count_Timer.start();
Amwila 1:6017f9971cc8 26 }
Amwila 1:6017f9971cc8 27 if (A_count == 10000)
Amwila 1:6017f9971cc8 28 {
Amwila 1:6017f9971cc8 29 // Stopping timer at 10000 Counts
Amwila 1:6017f9971cc8 30 Count_Timer.stop();
Amwila 1:6017f9971cc8 31
Amwila 1:6017f9971cc8 32 // Reading Counter Time
Amwila 1:6017f9971cc8 33 FinalCountTime = Count_Timer.read();
Amwila 1:6017f9971cc8 34
Amwila 1:6017f9971cc8 35 // Outputting Final count to Terminal
Amwila 1:6017f9971cc8 36 printf("Final Count Time for 10000 counts is : %d ",FinalCountTime);
Amwila 0:2a502be30ec8 37
Amwila 1:6017f9971cc8 38 //Setting Counter to 0 again
Amwila 1:6017f9971cc8 39 A_count = 0;
Amwila 1:6017f9971cc8 40 }
Amwila 1:6017f9971cc8 41
Amwila 1:6017f9971cc8 42 // Calling of the increment function on the rising edge of a pulse
Amwila 1:6017f9971cc8 43 BLM_CHANNEL_A.rise(&IncA);
Amwila 1:6017f9971cc8 44
Amwila 1:6017f9971cc8 45
Amwila 0:2a502be30ec8 46 }
Amwila 0:2a502be30ec8 47 }
Amwila 0:2a502be30ec8 48