I'm trying to contol a servo motor with attiny45 writing the code in assembler. I figured out how to set the timer in pwm mode and how to choose a needed prescaler. And with different OCR0A values i'm getting the neutral and 0 degrees position. However, i've ran into a problem with 180 degrees. When I keep the timer settings the same and don't set the OCR0A, the servo easily goes to 180 degrees. But when i change the OCR0A to get different pulse and different motor positions and than try to come back to default OCR0A value, nothing works. So, the code:
This puts my motor in 180 degrees position
.includepath "/usr/share/avra/"
.device ATtiny45
.DEF A=R16
.equ DDRB = 0x17
.equ PORTB = 0x18
.equ TCCR0A = 0x2A
.equ TCCR0B = 0x33
.equ OCR0A = 0x29
.ORG $0000
SBI DDRB, 0x3
SBI PORTB, 0x3
ON_RESET:
SBI DDRB, 0
LDI A, 0b10000011
OUT TCCR0A, A
LDI A, 0b00000011
OUT TCCR0B,A
MAIN_LOOP:
RJMP MAIN_LOOP
This doesn't (Hope it's easy to understand what I'm trying to do here)
.includepath "/usr/share/avra/"
.device ATtiny45
.DEF A=R16
.equ DDRB = 0x17
.equ PORTB = 0x18
.equ TCCR0A = 0x2A
.equ TCCR0B = 0x33
.equ OCR0A = 0x29
.ORG $0000
SBI DDRB, 0x3
SBI PORTB, 0x3
ON_RESET:
SBI DDRB, 0
LDI A, 0b10000011
OUT TCCR0A, A
LDI A, 0b00000011
OUT TCCR0B,A
MAIN_LOOP:
LDI A, 0xFF
OUT OCR0A, A
RCALL DELAY_05
RCALL DELAY_05
RCALL DELAY_05
RCALL DELAY_05
LDI A, 192
OUT OCR0A, A
RCALL DELAY_05
RCALL DELAY_05
RCALL DELAY_05
RCALL DELAY_05
LDI A, 40
OUT OCR0A, A
RCALL DELAY_05
RCALL DELAY_05
RCALL DELAY_05
RCALL DELAY_05
RJMP MAIN_LOOP
DELAY_05:
LDI R17,8
OUTER_LOOP:
LDI R24, low(3037)
LDI R25, high(3037)
DELAY_LOOP:
ADIW R24,1
BRNE DELAY_LOOP
DEC R17
BRNE OUTER_LOOP
RET
Yes i don't know how to write a 2 sec. delay function.
So is there a way to 'reset' the OCR0A register?
Best Answer
Alright, this is solved. Stupidly easy. The default OCR0A value is 0.