Count down/up timers

Thread Starter

jey11

Joined Jun 7, 2010
25
16 bit, 5 time and want to count for a Mhz count up for a 3 ms interval. What value should I put in data register. How to calculate this.

Thanks for the help
Jey
 

Thread Starter

jey11

Joined Jun 7, 2010
25
16 bit 10 Mhz count down timer. If the timer data was previously set to 0x7A2B . What is the count down timer interval? How to find this.
Steps might help.

Thanks
Jey
 

MrChips

Joined Oct 2, 2009
23,228
16 bit, 5 time and want to count for a Mhz count up for a 3 ms interval. What value should I put in data register. How to calculate this.

Thanks for the help
Jey
There are two many unknowns.
What do you mean by 5 time?
What MCU?
What is the system clock frequency?
 

LesJones

Joined Jan 8, 2017
3,132
If you mean that you increment the counter every 200 nS (5 Mhz) then you need to count to 15000 (Decimal) Normally counters set their interrupt flag when they overflow so you need to pre load the counter with 15000 less than the overflow value. A 16 bit counter will overflow at a count of 65536 so you need to pre load it with a value of 65536 -15000 = 50526 which is 0xC568 Hex. In practice you have to make a correction for the time it takes to load the counter. You write the code required to load the counter then work our how long those instructions take to execute. You then add the number of cycles of 5Mhz that represent that amount of time to the value you load into the counter.

Les.
 

Thread Starter

jey11

Joined Jun 7, 2010
25
16 bit 10 Mhz count down timer. If the timer data was previously set to 0x7A2B . What is the count down timer interval? How to find this.
Steps might help.

Thanks for the help
Jey
 

Thread Starter

jey11

Joined Jun 7, 2010
25
If you mean that you increment the counter every 200 nS (5 Mhz) then you need to count to 15000 (Decimal) Normally counters set their interrupt flag when they overflow so you need to pre load the counter with 15000 less than the overflow value. A 16 bit counter will overflow at a count of 65536 so you need to pre load it with a value of 65536 -15000 = 50526 which is 0xC568 Hex. In practice you have to make a correction for the time it takes to load the counter. You write the code required to load the counter then work our how long those instructions take to execute. You then add the number of cycles of 5Mhz that represent that amount of time to the value you load into the counter.

Les.

Thanks for the help and explanation.

Can you assist on this too please.

16 bit 10 Mhz count down timer. If the timer data was previously set to 0x7A2B . What is the count down timer interval? How to find this.
Steps might help.

Thanks for the help
Jey
 

LesJones

Joined Jan 8, 2017
3,132
0x7A2B = 31275 decimal. As you are now talking about a count down timer (Rather than a count up timer.) the situation is different. (I have not seen a countdown timer on any of the microcontrollers that I have used.) I ASSUME that in this case the interrupt would occur when the counter decremented to zero. (You would have to read the datasheet on the microcontroller that you are using.) If my assumption is correct then the actual counting part would last 31275 x 100 nS = 3127.5 uS

Les.
 

MrChips

Joined Oct 2, 2009
23,228
The computer does not care whether the number is in decimal or hexadecimal. The computer works in binary alone.
Hence make your life easier and enter these numbers in decimal because that is what humans recognize easily.
 

Thread Starter

jey11

Joined Jun 7, 2010
25
0x7A2B = 31275 decimal. As you are now talking about a count down timer (Rather than a count up timer.) the situation is different. (I have not seen a countdown timer on any of the microcontrollers that I have used.) I ASSUME that in this case the interrupt would occur when the counter decremented to zero. (You would have to read the datasheet on the microcontroller that you are using.) If my assumption is correct then the actual counting part would last 31275 x 100 nS = 3127.5 uS

Les.
Thanks for you support.
 
Top