Shop OBEX P1 Docs P2 Docs Learn Events
Making a pwm almost endless loop - Page 2 — Parallax Forums

Making a pwm almost endless loop

2»

Comments

  • Ady111Ady111 Posts: 15
    edited 2011-07-10 15:12
    Mike G wrote: »
    Ady111, all PULSOUT commands have to execute in the same tight loop. You should not nest a FOR...NEXT loop in your tight loop.

    Here's a simple example. Do not use this with your motors as it uses the DEBUG command and a 1 second pause. At some point you'll also need to update speed/position values and that takes time as well.
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    
    i     VAR   Byte  ' For next loop
    m1    VAR   Word  ' Motor 1
    m2    VAR   Word  ' Motor 2
    m3    VAR   Word  ' Motor 3
    cnt   VAR   Nib   ' Conter
    dir   VAR   Bit   ' Direction
    
    'Initialize
    m1 = 650
    m2 = 700
    m3 = 200
    dir = 0
    
    ' Main loop
    Main:
      PULSOUT 8, m1
      PULSOUT 1, m2
      PULSOUT 2, m3
    
      GOSUB LoadValues
      PAUSE 10
    
      GOSUB Display
    GOTO Main
    
    ' Load new speed/position values
    LoadValues:
      IF dir THEN
        m1 = m1 + 1
        m2 = m2 + 1
        m3 = m3 + 1
      ELSE
        m1 = m1 - 1
        m2 = m2 - 1
        m3 = m3 - 1
      ENDIF
    
      cnt = cnt + 1
      IF cnt = 15 THEN dir = dir + 1
    RETURN
    
    ' Dump values for testing loop
    Display:
      DEBUG ?m1, ?m2, ?m3, ?cnt, ?dir
      PAUSE 1000
      DEBUG CLS
    RETURN
    

    Good luck... I'd pick up a PWM controller.
    I'm not sure that's the way i should make it work. I want to try and make a simple program. If you have seen the picture that i inserted in #18 you can make a better idea about my project. Tomorrow must be ready. i want to make a series of FORs so that the program goes from loop to loop until reaches the end. I want just to make the hover to go forward for a time, right and left that's all, of course without the interruption of the brushless motor.
Sign In or Register to comment.