Create a precision timer with HAL and interrupt
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-11-20 3:41 AM
Posted on November 20, 2015 at 12:41
Hi guys,
I'm using CubeMx with HAL STM32F051. I need to activate a one shot timer with interrupt.Something likr this:void StartTimer(unsigned short microSecond){ ... ...}volatile unsigned char TimerIsOver = 0; void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) { TimerIsOver = 1;}void main(void) { LedOff(); TimerIsOver = 0; StartTimer(20); while(!TimerIsOver); LedOn(); TimerIsOver = 0; HAL_Delay(50); LedOff(); StartTimer(340); while(!TimerIsOver); LedOn(); } #stm32-hal-tim
Labels:
- Labels:
-
STM32Cube MCU Packages
This discussion is locked. Please start a new topic to ask your question.
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-11-20 10:20 AM
Posted on November 20, 2015 at 19:20
Any question?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-11-20 1:33 PM
Posted on November 20, 2015 at 22:33
For micro-seconds, where you're going to idle in a loop, why not just have that timer free run, and delta the tick count from TIMx->CNT ?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-11-22 11:18 PM
Posted on November 23, 2015 at 08:18
Please could you write for me StartTimer function?
Thank you very much...Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-11-23 6:14 AM
Posted on November 23, 2015 at 15:14
Sorry, I'm not writing HAL examples.
A free running timer would be a matter of configuring the time base in a maximal count mode, in your case probably with a 1us (1MHz) prescaled clock. Read the count at the start of the loop, and delta it over the duration. Interrupting at 1 MHz is NOT viable, so software counters aren't a solution.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
