What is the meaning of rollover interrupt? - timer

Does rollover mean resetting the timer to zero after reaching the highest limit?

Related

STM32F0 - How long do timers take to set count value?

I've got an issue with STM32F0 timers. I'm doing everything register level and am disabling a timer and zeroing the count. After this I re-enable external interrupts and restart the timer on receipt of an edge.
It seems though that it the interrupt happens very soon after the count has been written, the zeroing does not take place.
I'm wondering if there is a delay when writing to the counter. I wonder if there would have to be at least one pre-scaled clock cycle?

Can I change OCR1B on the fly?

I want to solve a very particular problem with an Arduino, running on a ATmega328
I have timer1 run in fast PWM mode for generating a PWM Signal with given Period an duty cycle. The duty cycle is set by OCR1A: So at timer restart the level of the output pin gets high and after the duty period it gets low. This works.
Additionally I want to carry out an analog measurement exactly some time after the rising signal. So I enabled the OCR1B interrupt and define the time by writing to OCR1B. When the timer reaches the value in OCR1B the interrupt handler is invoked and the measurement done. This works.
Now I want to do this ADC conversion twice at different counter times, say my_OCRB1 and my_OCRB2. But there is only on OCR1B Register I can use. Is it ok to prepare the content of OCR1B to the next value my_OCRB2 after the first ADC conversion at is finished? Will it work and again rise an interrupt, when the timer is still counting up?
Is there a better solution?

How to synchronize two timers on PIC16F1827

I just got into PIC-programming on Microchips MPLAB X IDE. My programm requires two timers. TMR4 has an interrupt interval of 500ms and TMR2 interrupts every second. When starting the program, the two timers are synced up, so within a small margin of error, when the TMR4 interrupts for the second time, TMR2 also executes the interrupt code. But when I stop TMR2 for a period of time and then start it again, the two timers are completely out of Sync.
Is there a way to resynchronize the two timers or to restart them?
Why are you stopping the timers?
There is no need to be stopped when interrupt happened. TMR2 and TMR4 are functional identical. When the interrupt is triggered the TMR2IF or TMR4IF is set. If also set TMR2IE or TMR4IE then the interrupt is triggered.
The registers PR2 and PR4 (also prescaler) must be set according to desired frequency. The value of TMR2 or TMR4 is compared to that of the period register, PR2 or PR4, on
each clock cycle. When the two values match, the comparator generates a match signal as the timer output and trigger interrupt, TMR2IF or TMR4IF is set. If also set TMR2IE or TMR4IE then the interrupt is triggered. This signal also resets the value of TMR2 orTMR4 counters to 0 and timers continue running. When you finish your interrupt program just clear TMR2IF or TMR4IF to enable next timer interrupt.
If you wont to resynchronize the timer then just reset the TMR2 and TMR4 registers value to 0. If you wont to resynchronize in main program then first disable interrupts clear TMR2 and TMR4 and enable interrupts again.

Timer reading when postscalar turned ON

I have read that the postscalar of a timer specifies how many times the counter has to overflow inorder to get an interrupt.
But i have a doubt there.
So what i understand is if i put 0x55 and start timer with postscalar as 2, then timer will count from 0x55 to 0xFF and then again 0x55 to 0xFF and generate an interrupt.
Consider a case that i start the timer in an external inetrrupt. My requyirement may be to get the timegap between two interrupt. I start the timer in first interrupt, then read the timer in the next interrupt.
but if i have put postscalar then i will get the wrong time right.
I just used this as an example to make my question clear.
Edit: So will there be any issue if a timer value is read when postscalar turned ON
Usage Context: To get time difference between two interrupts
No. PostScale - Pre-Scale divide the clock input/output so you can sample at lower frequencies or intervals, depending on the application where you need more count than available. Let's say you have a XTAl of 8MHz with a Pre-Scaler of 1:8 (found on many PICS), you won't sample at 8MHz but at 1MHz.
Addind a pre-scaler - Post-Scaler will change the time between your 2 interrupts, surely. But that won't affect the reading of the counter value, assuming you count a variable each time there's one of the 2 interrupts on. You will simply count slower, or faster, depending on which timer you are using (most of them only have a pre-scaler option).

Setting up watchdog_set_period to max value causes reboot

I don't much about how watchdog timer works in embedded environment and I am facing issue related to watchdog timer
Maximum time out value defined in one of the macro is 55 and when we try to set up this value from watchdog_set_period function ,our board is getting reboot
#define Max_time_out 55
watchdog_set_period(int period) // Set watchdogs timeout counter
where period = 55
Now is it something expected or how what is the reason for reboot
We are writing this period value to some driver which we are accessing through file descriptor.
The link states this description on watchdog timers.
A watchdog timer is a piece of hardware that can be used to automatically detect software anomalies and reset the processor if any occur. Generally speaking, a watchdog timer is based on a counter that counts down from some initial value to zero. The embedded software selects the counter's initial value and periodically restarts it. If the counter ever reaches zero before the software restarts it, the software is presumed to be malfunctioning and the processor's reset signal is asserted. The processor (and the embedded software it's running) will be restarted as if a human operator had cycled the power.
You haven't posted the code so we can't judge what exactly is the problem. If you have written the code check if your code is causing any problems which is causing the watch dog timer to reset.
A watchdog timer is a special kind of timer usually found on embedded systems that is used to detect when the running software/firmware is hung up on some task. The watchdog timer is basically a countdown timer that counts from some initial value down to zero.
When zero is reached, the watchdog timer understands that the system is hung up and resets it.
Therefore, the running software must periodically update the watchdog timer(in a infinite while loop) with a new value to stop it from reaching zero and causing a reset. When the running software is locked up doing a certain task and cannot update(refresh fails) the watchdog timer, the timer will eventually reach zero and a reset/reboot will occur.
So in summary, if you enable watchdog timer then you need to periodically refresh watchdog timer. Otherwise the board reboots when the watchdog timer expires.

Resources