To use counter, we must work with CS02:00 of the TCCR0 register.
- Timer/Counter Control Register 0 (TCCR0)
BIT 7 | BIT 0 | ||||||
FOC0 | WGM00 | COM01 | COM00 | WGM01 | CS02 | CS01 | CS00 |
When the CS02:00 = 0x06 , then TCNT0 count the falling edge pulse clock fed to pin PB0/T0.
When the CS02:00 = 0x07, then TCNT0 count the rising edge pulse clock fed to pin PB0/T0.
TCNT0 is 8-bit wise read/write register. It counts from 0x00 to 0xFF. When its value rolls from 0xFF to 0x00, then the TOV0 flag is set.
We can count any value larger than 0xFF by working with TOV0, and adding more variables with programming technique.
In this example, I create a counter device display the counting result up to 9999.
Source code is here:
A screen shot of this program.
A simulation screen shot. The counting reaches 2179 with some bugs. |
Back to main tutorial page ATMega32 tutorials in C with Atmel Studio 7.
If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.
No comments:
Post a Comment