counter 0 of atmega48

comp.arch.embedded counter 0 of atmega48

How is tcnt0 on the atmega48 started...??? The code below doesn't seem to have any effect. in areg, TCNT0 provides only a zero. The intent is a free running counter, up to 0xff and then to zero and up again. The PRR section section says "when tim/cnt0 is enabled, it works...". The tcnt0 section says roughly "...tim/cnt0 bit in PRR must be written to zero to enable tcnt0." Wogdog, below, shows just a continuous line at 0 volts on a scope. The definitions for the various symbols are at the bottom. And, I owe thanks to LAIRD for a suggestion to check those. All the definitions on that occasion were correct but some comments were not "commented out" resulting in, you guessed it, altered definitions. Back to this counter... it's the simplest configuration available - what's missing?

; timer0 power politics?? lds areg, PRR andi areg, 0xdf sts PRR, areg ; timer0 cntl A: ldi areg, 0 ; no output compare or pwm sts TCCR0A, areg ; timer0 cntl B: ldi areg, 5 ; sets clk/1024 sts TCCR0B, areg

wogdog: in areg, TCNT0 sbrs areg, 7 cbi TPOUT, TPHNUM sbrc areg, 7 sbi TPOUT, TPHNUM rjmp wogdog

PRR $64 TCCR0A $24 TCCR0B $25 TCNT0 $26 areg r16

Reply to
Hul Tytus
Loading thread data ...

doesn't seem

ntent is a

t works...".

zero

a scope.

. And, I owe

hat

g in,

vailable -

r pwm

$25 is the I/O address of TCCR0B, but to access that register with the STS instruction you need to add $20, making your address $45. Same goes for all the other timer registers. Or better yet, use the I/O instructions IN and OUT which will work correctly with the $2X addresses you have, and will save code space and execution time.

From the datasheet: "When using the I/O specific commands IN and OUT, the I/O addresses

0x00 - 0x3F must be used. When addressing I/O Registers as data space using LD and ST instructions, 0x20 must be added to these addresses. The ATmega48/88/168 is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the Extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used."

Mike

Reply to
Mike Silva

Many thanks Mike. This looked like something simple that I was missing.

Hul

Mike Silva wrote:

seem

zero

in,

Reply to
dbr

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.