Atmega644 +pwm+ servo
bezwanna
Posts: 3
Hi I have probem with having pulses of 20ms to get the servos in one direction , I have atmega644 cpu. anyone plz can help me with it. Iam using the following code to make the servo running.
assembler code
.NOLIST
.INCLUDE "m644def.inc"
.LIST
.DEF Tmp=r16
.DEF Temp=r17
.DEF Temp2=r18
.CSEG
.ORG 0
rjmp Reset
.ORG 20
Reset: ldi Temp,HIGH(RAMEND)
out SPH,Temp
ldi Temp,LOW(RAMEND)
out SPL,Temp
ldi Tmp,0b10000011
out TCCR0A,Tmp
sbi DDRB,3
ldi Tmp,150
out OCR0A,Tmp
ldi Tmp,0b00000010
out TCCR0B,Tmp
ldi Tmp,170
out OCR0A,Tmp
;
varv: inc Tmp
out OCR0A,Tmp
rcall Delay
rjmp varv
Delay: ldi Temp,0xff
Loop1: ldi Temp2,0xff
Loop: nop
nop
nop
nop
dec Temp2
brne Loop
dec Temp
brne Loop1
ret
assembler code
.NOLIST
.INCLUDE "m644def.inc"
.LIST
.DEF Tmp=r16
.DEF Temp=r17
.DEF Temp2=r18
.CSEG
.ORG 0
rjmp Reset
.ORG 20
Reset: ldi Temp,HIGH(RAMEND)
out SPH,Temp
ldi Temp,LOW(RAMEND)
out SPL,Temp
ldi Tmp,0b10000011
out TCCR0A,Tmp
sbi DDRB,3
ldi Tmp,150
out OCR0A,Tmp
ldi Tmp,0b00000010
out TCCR0B,Tmp
ldi Tmp,170
out OCR0A,Tmp
;
varv: inc Tmp
out OCR0A,Tmp
rcall Delay
rjmp varv
Delay: ldi Temp,0xff
Loop1: ldi Temp2,0xff
Loop: nop
nop
nop
nop
dec Temp2
brne Loop
dec Temp
brne Loop1
ret
Comments
We can't help you with programming for an Atmega microcontroller. You'll have to look for Atmega support forums for help there.
http://www.parallax.com/Portals/0/Downloads/docs/prod/motors/900-00008-CRServo-v2.0.pdf
As for the code for your controller, asking about that at the Parallax site is sort of like expecting the New York Tourism Office to explain why your car broke down on the way into New York.
It'd make a lot more sense to ask the auto manufacturer, or in this case, to ask your question on a forum for ATMega processors.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Yes I did , as you describe . I think there is somthing wrong with my code not work probably.Iam tryng with differnt methods but still the servo does not work as it should.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.