Author Topic: MCU timer modulo vs total counts  (Read 2250 times)

0 Members and 1 Guest are viewing this topic.

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
MCU timer modulo vs total counts
« on: December 05, 2014, 03:54:12 am »
For a HC908 timer it says "When the timer counter reaches the modulo value, the TOF flag is automatically set by hardware, and the timer counter resumes counting from $0000 at the next clock." To me that says if you set the modulo value to 20 then the counter repeats every 21 counts including zero count. Does that sound right?
« Last Edit: September 30, 2018, 09:26:33 am by Circlotron »
 

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
Re: MCU timer modulo vs total counts
« Reply #1 on: September 30, 2018, 09:27:31 am »
Nearly 4 years, 659 reads and no replies!
C'mon! Can't be that hard!


P.S. I don't think there was a Microcontrollers & FPGAs section when I first posted this.
« Last Edit: September 30, 2018, 09:29:59 am by Circlotron »
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4789
  • Country: pm
  • It's important to try new things..
Re: MCU timer modulo vs total counts
« Reply #2 on: September 30, 2018, 09:49:56 am »
 :)
You wait 4 years to get such an answer?
With modulo value "20" it will do 21 cycles.

0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-0-1-2..

A mod-N counter stores an integer value, and increments that value on each clock tick, and wraps around to 0 if the previous stored value was N-1.
 

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
« Last Edit: September 30, 2018, 10:30:29 am by Circlotron »
 

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
Re: MCU timer modulo vs total counts
« Reply #4 on: September 30, 2018, 10:38:53 am »
"When the timer counter reaches the modulo value, the TOF flag is automatically set by hardware, and the timer counter resumes counting from $0000 at the next clock."
Or does that mean if the modulo is set to 20, when 20 is reached the TOF flag is set and the timer count is immediately reset to zero instead of staying at 20 because THE TIMER COUNT RESUMES COUNTING =FROM= $0000 AT THE =NEXT= CLOCK?

"FROM" zero is the important word.
« Last Edit: September 30, 2018, 10:40:48 am by Circlotron »
 

Online Benta

  • Super Contributor
  • ***
  • Posts: 5877
  • Country: de
Re: MCU timer modulo vs total counts
« Reply #5 on: September 30, 2018, 01:19:14 pm »
It's what imo said.

 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8173
  • Country: fi
Re: MCU timer modulo vs total counts
« Reply #6 on: October 03, 2018, 08:36:48 am »
As a general note, things like these need to be tested. MCU documentation errors are very typical so that the hardware doesn't match the documentation. People on the forums are sometimes right from their own experience, but sometimes just read the same documentation you already are reading to write their reply. Even those experienced may remember it wrong. So when encountered with a question like this, spend the minute or two to test it, and remember to document the behavior as a code comment.

Actual testing may also reveal totally unexpected behavior that's neither of the expected outcomes. For example, on AVR, a certain PWM timer mode (forgot which) gives very short pulses (skipping the prescaler!) when set to output "0", which is highly unexpected IMHO.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf