Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
pulse_decoder.h
00001 #ifndef PULSE_DECODER_H 00002 #define PULSE_DECODER_H 00003 00004 /// @file pulse_decoder.h This library provides a simple PWM decoder class. 00005 /// 00006 /// The approach is based on installing two interrupt routines for the rising and 00007 /// falling edges of an input pin and measuring the time between the two events. 00008 /// 00009 /// Example: 00010 /// @code 00011 /// #include "mbed.h" 00012 /// void main() 00013 /// { 00014 /// pulse_decoder pulse(D7); 00015 /// 00016 /// while(true) { 00017 /// printf("Pulse high = %5d low = %5d (us) Period = %5d\n", 00018 /// pulse.get_high_period(), pulse.get_low_period(), 00019 /// pulse.get_high_period() + pulse.get_low_period()); 00020 /// wait(.2); 00021 /// } 00022 /// } 00023 /// @endcode 00024 00025 class pulse_decoder { 00026 public: 00027 ///Creates a pulse_decoder 00028 ///@param[in] pin the input pin on the microcontroller 00029 pulse_decoder(PinName pin); 00030 00031 ///Get the period of time that the pulse was in high state 00032 ///@return the period in us 00033 int get_high_period() const 00034 { 00035 return high_period; 00036 } 00037 00038 ///Get the period of time that the pulse was in low state 00039 ///@return the period in us 00040 int get_low_period() const 00041 { 00042 return low_period; 00043 } 00044 00045 private: 00046 InterruptIn interrupt; 00047 Timer high_timer; 00048 Timer low_timer; 00049 volatile int high_period; 00050 volatile int low_period; 00051 00052 void rising_edge(); 00053 void falling_edge(); 00054 }; 00055 00056 #endif //PULSE_DECODER_H
Generated on Tue Jul 12 2022 21:48:04 by
1.7.2