Shop OBEX P1 Docs P2 Docs Learn Events
What is wrong with this code? - Protoboard and servos — Parallax Forums

What is wrong with this code? - Protoboard and servos

W9GFOW9GFO Posts: 4,010
edited 2007-08-06 18:50 in Propeller 1
Hi all,

This code seems straight forward to me but it is not working. When the code is run the servos jump for an instant, then nothing. I've spent way too much time trying to figure this out - my brain stopped working a while ago so I need someone to tell me what I'm forgetting or doing wrong.

Thanks!


CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  Servo1 = 5
  MotorR = 6
  MotorL = 7
  
  LED1   = 12
  LED2   = 13
  LED3   = 14
  LED4   = 15
        
PUB Main
  
  repeat  
    PWM(motorL, 1500)
    PWM(motorR, 1500)
    PWM(servo1, 1500)
    waitcnt((clkfreq/1000) * 20 + cnt)
  
  
PUB PWM(pin, width)

  dira[noparse][[/noparse]pin]~~                                                                       
  !outa[noparse][[/noparse]pin]                                                                       
  waitcnt(width * (clkfreq/1_000_000)+ cnt)                                                          
  !outa[noparse][[/noparse]pin]

Post Edited (W9GFO) : 8/6/2007 6:37:56 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-06 18:07
    Usually this is a power problem and has nothing to do with the program. Your program looks like it ought to work if there were a separate servo power supply. What's probably happening is that you're pulsing the servos within 4-5ms and they're all drawing current up to 1-1.5A. Depending on your power source, that will probably cause a reset of the Propeller, then the whole cycle repeats.
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-06 18:10
    You wait a VERY SHORT time (50 mys) between the pulses (1.5 ms)
  • W9GFOW9GFO Posts: 4,010
    edited 2007-08-06 18:50
    Yeah, that delay was a tad short wasn't it? That was just a brain fart the last time I re-wrote it. Seems the problem lies with my batteries. I had changed them out, twice, but they just aren't up to the task I guess. I will make up a five cell pack.

    Thanks!
Sign In or Register to comment.