7/10/2023 0 Comments Micros arduino timer interrupt![]() ![]() In my example code, I called this function within the Arduino setup() function. To get access to my Timer2_Counter 0.5us-precision timing functions, you must first call " setup_T2() " in order to properly set up the Atmega Timer2 prescalers and such. Click the tab to view its contents, including detailed descriptions of the available functions. When the IDE opens, notice that it automatically opens the "Timer2_Counter.ino" file with it, as a second tab. From this endeavor is born my Timer2_Counter "library," which provides functions which can be used in place of the micros() function, and which provide a precision of 0.5us, which is 8x better than the micros() function!įor more detailed information on my code, as well as the latest version of my code, including a full list of its functions, please refer to my article here: Arduino micros() function with 0.5us precision - using my Timer2_Counter "Library".Ĭlick the "Timer2_Counter_Basic_Example.ino" file to open it in your Arduino IDE. Therefore, I decided to do a ton of reading and get down into the guts of the microcontroller, accessing the Atmel's timers directly, and writing my own timer function. The only solution I could find used the Atmega328 microcontroller's Timer1, which is unacceptable for my needs, because then I lose use of the Arduino servo library. So.I looked and I looked and I looked for a solution. This means that if I'm reading in a PWM signal that I know is exactly 1500us (center-stick position on a hand-held transmitter), I would see readings of 1496, 1504, 1500, and even sometimes 1492 or 1508us. The built-in Arduino micros() function is good, but not good enough for my needs. To measure the timing in these signals, I first used the Arduino micros() function, in conjunction with external interrupts. In the signals, a full stick deflection in one direction, on a hand-held radio transmitter, usually corresponds to ~1000us (microseconds), and a full stick deflection in the opposite direction corresponds to ~2000us. These RC communication signals are called PWM (Pulse Width Modulation) and PPM (Pulse Position Modulation). This is because my home projects focus around Radio Control (RC) aircraft, and RC hobby communication signals are timing-based signals. ![]() As I work on my many home projects, however, I frequently find myself needing a very precise timer. ![]() I love Arduino microcontroller programming, and I regularly use it in aerospace research, as well as in home projects. ![]()
0 Comments
Leave a Reply. |