24bit counter on ATMEGA103

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the ATMEGA103 MCU and need a 24bit counter.
Standard the 'biggest' counter has 16 bits.
What could be the best way (if there is any) to make a 24 bit counter ?
Thank you for your response,
Carlo Veld

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Carlo,
Setup up the 16-bit counter overflow interrupt routine. In the routine just increment an 8-bit register. If you need to make a 24-bit counter overflow routine then just change the routine to be

if( 8bitregister == $FFFF )
{
do the overflow code
}
8bitregister++;

This should work pretty well and with accuracy. If you need to reset the counter just make sure to reset the 8-bit register!!!

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Ian,

Thank you for your quick response and usefull help.
Now I can try to implement this solution in C++.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may want to try cascading the counters where you use the overflow output of one, as the input of the second counter.

You would have to be careful during a counter clear, but that should allow you to use the two counters as a single wider counter.

admin's test signature