Reading writing 10 bits counter1 attiny 261

Thread Starter

LaurenceR

Joined Feb 7, 2013
107
Hello All,
I am having difficulty reading and writing the 10 bit value from ADC into either OCR1C or OCR1D of attiny 261 PWM timer/counter1. I am programming in assembly code.

Initialize Counter:
LDI PWb, 0B00000011
LDI PWa, 0B11111111
OUT TC1H, PWb
OUT OCR1C Pwa

Read ADC and write into Timer/counter1:
IN PWc, ADCL
IN PWd, ADCH
OUT TC1H, Pwd
OUT OCR1D, PWc

I am trying to have a max count of 1024 and a max ADC value of 1024.

Thanks for any help.
 

MrChips

Joined Oct 2, 2009
30,618
Initialize Counter:
LDI R17, 0B00000011
LDI R16, 0B11111111
OUT TCNT0H, R17
OUT TCNT0L, R16

Read ADC and write into Timer/counter1:
IN R16, ADCL
IN R17, ADCH
OUT TCNT0H, R17
OUT TCNT0L, R16
 

Thread Starter

LaurenceR

Joined Feb 7, 2013
107
Initialize Counter:
LDI R17, 0B00000011
LDI R16, 0B11111111
OUT TCNT0H, R17
OUT TCNT0L, R16

Read ADC and write into Timer/counter1:
IN R16, ADCL
IN R17, ADCH
OUT TCNT0H, R17
OUT TCNT0L, R16
Many thanks, this makes it much clearer. Read low first, write high first.
Does this look ok to you for changing the Top count and set point in a phase and frequency correct PWM?

I would first initialize TCNT1 to 0b00000000
Then make the top count (frequency):
IN R16, ADCL
IN R17, ADCH
OUT OCR1C, R17
OUT OCR1C, R16

Then from a separate ADC input the value to change the duty cycle:
IN R16, ADCL
IN R17, ADCH
OUT OCR1D, r17
OUT OCR1D, r16
 
Top