STM32F4 Change timer period in code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-30 11:25 AM
Hello
I'm using TIM3 on my STM32F4. Currently TIM3 period is set on 500 (using CubeMX). Is it possible to change it with pressing 'User button'?For example
'if (currentPress == 1) { htim3.Init.Period = 200; } else if (currentPress == 2) { htim3.Init.Period = 400; ...}'
I guess it could be done via TIM3->.... but I'm not sure how to make it, because I'm beginner.
What I was trying to do was using TIM3->CCR1 = 200, etc.. but it seems like it doesn't work.Thanks for help in addition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-30 11:12 PM
TIM3->ARR = 200 - 1; // Remember count counts 0 thru N-1, ie N counts
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-01 10:36 AM
Sounds good, but works only for 3-4 clicks. After that Led starts to shine all the time, or doesn't shine at all untill I press reset button.
Any other ideas?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-01 10:43 AM
Check the timer overflow value is updated at overflow (I think it's about shadowing). If not, changing the max value from 400 to 200 when the timer is at 300 may get the timer stuck. Some timer spec reading needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-01 10:53 AM
Probably wouldn't want to enable 'Preload', in the normal mode the new ARR is held in a holding/shadow register and loaded into the active one at the Update event (ie CNT == 0).
If preload is enabled it basically writes through directly, then you'd want to be wary of where CNT is in the cycle
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-01 11:17 AM
Centauris.Alpha
‌ andTurvey.Clive.002
‌. Thank you both for you answer. Since I'm total beginner (only a week or two) I don't have much idea how to make it. But thanks for ideas, I'm gonna check out what else I can do.