Library that to count pulses by hardware
- include "mbed.h"
- include "HardwarePulseCounter.h"
/ Simple program to measure frequency from external pulse /
Timer t;
int main(){
/*The PulseCounter instance receives 3 parameters. They are: Timer, GPIO and PIN
- Timer: Can be: TIM2, TIM3, TIM4
- GPIO: Can be: GPIOA, GPIOB, GPIOC, GPIOD
- PIN: Can be: GPIO_PIN_x x is the number of pin. Per example: GPIO_PIN_1 is (PIN 1), GPIO_PIN_2 is (PIN2)
- /
PulseCounter TimerCounter(TIM2, GPIOA, GPIO_PIN_0);
/*Here we have set Timer as TIM2, GPIO as GPIOA, and PIN as Pin(0) > In this case we set PIN PA0 from the board,
this is the input pin of the external pulses.
-Each timer has its associated pin, see the documentation to find out.
- /
/*Start all configurations*/
TimerCounter.Start_Configurations();
while(1){ t.start();
if(t.read_ms() == 1000){
/*The getTime method returns a number of accumulated pulses over a given period of time. In this case, 1000 milliseconds -It must be stored in a variable of type uint32_t
- /
uint32_t frequency = TimerCounter.getTimerValue();
/*The clearTimeValue method resets the pulse value to zero.*/
TimerCounter.clearTimerValue();
t.stop(); t.reset(); } } }
Files at revision 4:437833c86cdd
Name | Size | Actions |
---|---|---|
[up] | ||
HardwarePulseCounter.cpp | 3165 | Revisions Annotate |
HardwarePulseCounter.h | 859 | Revisions Annotate |