Shop OBEX P1 Docs P2 Docs Learn Events
Atmega644 +pwm+ servo — Parallax Forums

Atmega644 +pwm+ servo

bezwannabezwanna Posts: 3
edited 2010-01-29 19:14 in General Discussion
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 confused.gifconfused.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-29 17:13
    This is a support forum for Parallax. Unfortunately, your question has nothing to do with Parallax or anything they deal with. R/C servos are fairly simple devices. They require a logic level control pulse about 50 times a second ranging from 1ms to 2ms in length. This will generally move a servo over about a 180 degree range with 1.5ms corresponding to the center of the range. Some servos will accept pulses from 0.5ms to 2.5ms in length. Continuous motion servos use the pulse to control the speed and direction of the servo with 1.5ms corresponding to a stopped servo and shorter pulses causing rotation in one direction and longer pulses causing rotation in the other direction.

    We can't help you with programming for an Atmega microcontroller. You'll have to look for Atmega support forums for help there.
  • bezwannabezwanna Posts: 3
    edited 2010-01-29 17:19
    Thank you for your comment, But Iam using the Parallax Continuous Rotation Servo, and it is si difficult to make the pwm to totate this kind of servo.
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-01-29 17:25
    bezwanna said...
    Thank you for your comment, But Iam using the Parallax Continuous Rotation Servo, and it is si difficult to make the pwm to totate this kind of servo.
    The documentation for that servo has a pretty detailed explanation of how to communicate with it:

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-29 17:31
    I understand you're having problems with your programming. Parallax's servos are no different from any other continuous rotation servo. They require control pulses as I've described. These pulses are easy to produce. Parallax has all sorts of examples on their website using their own microcontrollers like the Stamps, the SX, and the Propeller. You can use Parallax's code as an example or you can use your manufacturer's (Atmega's) examples. Sorry.
  • W9GFOW9GFO Posts: 4,010
    edited 2010-01-29 18:04
    Did you first send a 1.500 mS pulse once every 20 mS to the servo and adjust the potentiometer so that there was no movement? Without performing that centering procedure the servo will not behave as it should.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • bezwannabezwanna Posts: 3
    edited 2010-01-29 19:00
    Hi W9GFO
    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.
  • W9GFOW9GFO Posts: 4,010
    edited 2010-01-29 19:14
    I wish I could be of more help but I have no experience with the Atmega. I am sure you would have better luck on an Atmega forum.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
Sign In or Register to comment.