cancel
Showing results for 
Search instead for 
Did you mean: 

Pausing a STM32 TIMER

sanctified
Associate II

Hi,

I am using the STM32F401RE microcontroller to control 4 seven segment displays which together represent a countdown timer.

In order to control the displays I am multiplexing and therefore using the general purpose TIMER 2 in interrupt mode for a fast refresh rate.

My challenge right now is i want to be able to pause the time. That is,when i press a button the countdown timer should be interrupted and stops counting down (7 segement displays still showing the time, only pause) and when pressed again, it should continue from where it stopped. For this to happen, the TIMER 2 should still be enabled, but not counting, or so goes my idea.

So I thought if I reset CEN bit in CR1 register (that is disable the counter) of TIMER 2 , it should pause the time. and set it again to continue the time.

When i try this, what happens is the TIMER 2 does gets paused but then only one of the displays stay on and this happens because the TIMER 2 is no longer able to do the multiplexing and fast refresh rate.

So my question is, is there a way to pause the TIMER 2 or pause the counter of TIMER 2 and still does multiplexing and fast refresh.

Now i think of this, i feel its stupid because if the counter is disabled, then of course TIMER 2 wont keep refreshing or am I wrong?

Any suggestion on how to achieve this will be greatly appreciated.😊

P.S : I did not paste any code because i thought it unnecessary. If some code is needed, please let me know.

4 REPLIES 4

What is "countdown timer"? How do you "count it down", exactly?

JW

Bob S
Principal

It sounds like you are using TIMER2 as BOTH the countdown time AND the LED multiplex timer. Is that correct? I'm not sure how that would work. Do you have the TIMER2 interrupt decrement "count down" value every N times through the interrupt? If so, then you need a flag that says "don't decement the count-down time value" but still allows the LED updates to happen.

Thanks for your reply.

Its just a clock made with 4 seven segment displays.

I count it down every second using an array with the numbers.

But I figured out how to do it, so now worries 🙂

No, thats not right. Sorry, i should have explained better.

Thank you for your solution. It led me to the right idea.

And I was able to do it 🙂