Shop OBEX P1 Docs P2 Docs Learn Events
Proto Board - Page 2 — Parallax Forums

Proto Board

2»

Comments

  • computer guycomputer guy Posts: 1,113
    edited 2007-03-12 05:24
    That fixed it i had to use servo 32 though. BS2 Functions didn't work, it moved the servo about 5 degrees and then stopped.
    How do i convert the BS2's 500 to 1000 servo pulses 750 being center to servo32 servo pulses.
    Servo32 seams to use higher numbers (i am assuming this is because of the propellers 5mhz external clock).

    Thank you smile.gif
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-12 05:34
    Sorry I didn't see this one earlier. The BS2 functions didn't work because it was never started which sets up the timing variables needed for things like PULSOUT.
    BS2.Start(31,30)

    I need to change that. I keep having to point this out.
    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-12 05:57
    Thanks that got it working.
    Would still like to know how to convert BS2 timing into Servo32 timing.

    Thank you smile.gif
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-12 06:04
    It looks like from the example with Servo32 that it takes 1000 to 2000. This would be 1000uS to 2000uS, or 1 to 2 mSec which is what the Servo wants.

    BS2_Functions and the BS2 only have a resolution of 2uS, so a value of 500 really means 1000uS.

    So, your range of values instead of being 500 to 1000 (750 center/stop) would be 1000 to 2000, (1500 center/stop).


    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-12 06:57
    Thank you smile.gif
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-12 07:05
    I am using this but both servo's only move once.

    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000                                'Note Clock Speed for your setup!!
    
        SpeedServo = 8
        DirectionServo = 9 
    
     
    
       
    OBJ
      SERVO : "Servo32"
    
    
    
    PUB Servo32_DEMO | temp
    
        'Preset Servo's you want to use to center position
        SERVO.Set(SpeedServo,1500)
        SERVO.Set(DirectionServo,1500)
    
        'Note: Servo pins that will be used must be preset before running "SERVO.Start".
        '      This is because the I/O direction is set here and is only executed
        '      at the beginning of "SERVO.Start".  Servo pins that aren't used will remain
        '      in their original direction state.
    
        SERVO.Start                                         'Start Servo handler
    
        repeat 200
         SERVO.Set(SpeedServo,1250)
         SERVO.Set(DirectionServo,1500)
    
        repeat 100
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,1000)
    
        repeat 200
         SERVO.Set(SpeedServo,1250)
         SERVO.Set(DirectionServo,1500)
    
        repeat 100
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,2000)
    
    



    Thank you smile.gif

    Post Edited (computer guy) : 3/12/2007 8:51:49 PM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-12 21:04
    Echo...echo smile.gif
  • CJCJ Posts: 470
    edited 2007-03-12 21:15
    try replacing the repeats with waits, when you set the servos the cog that was launched with servo.start handles all the repetitions

    like waitcnt(2*clkfreq + cnt) for the 100s
    and waitcnt(4*clkfreq + cnt) for the 200s

    the main cog is likely finishing the program before the servos move, think of it as more of a servo controller that you set only when you need to change the servo position or direction in the case of continuous rotation ones

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-12 21:56
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000                                'Note Clock Speed for your setup!!
        SpeedServo = 8
        DirectionServo = 9 
     
       
    OBJ
      SERVO : "Servo32"
     
    PUB Servo32_DEMO | temp
        'Preset Servo's you want to use to center position
        SERVO.Set(SpeedServo,1500)
        SERVO.Set(DirectionServo,1500)
        'Note: Servo pins that will be used must be preset before running "SERVO.Start".
        '      This is because the I/O direction is set here and is only executed
        '      at the beginning of "SERVO.Start".  Servo pins that aren't used will remain
        '      in their original direction state.
        SERVO.Start                                         'Start Servo handler
    repeat
         SERVO.Set(SpeedServo,1500)
         SERVO.Set(DirectionServo,1500)
         waitcnt(clkfreq + cnt)
         
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,1000)
         waitcnt(clkfreq + cnt)
     
         SERVO.Set(SpeedServo,1500)
         SERVO.Set(DirectionServo,1500)
         waitcnt(clkfreq + cnt)
     
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,2000)
         waitcnt(clkfreq + cnt)
    
    

    I tested this code, it works, you never stated what exactly you were trying to make it do, I made it so one servo moves back and forth and the other spins in one direction, each pause for a second between.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-13 00:17
    I have a motor controller that requires 2 servo pulses to tell it what to do.

    SpeedServo at 1ms moves full speed forward and at 2ms full speed backward.

    DirectionServo sets the direction so 1ms is full left and 2ms is full right.


    So what my program was meant to do was for 200 pulses go forward at half speed.

    for 100 pulses turn full left at full speed.

    for 200 pulses go forward at half speed.

    for 100 pulses turn full right at full speed.

    and then repeat (i havent gotten to doing this part yet).

    Thank you smile.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-13 00:26
    Ok, you are misunderstanding the mechanics of Servo32. It is not a PULSOUT substitute, it is a servo controller in and of itself, in that you send it a value and it generates a stream of pulses for you. Sending the value to it 200 times has no additional effect over sending it once. To use it the way that you are thinking, compute the time it will take to generate the pulses and do a waitcnt for that period (20ms*100 = 2 seconds = clkfreq << 1) and (20ms*200 = 4 seconds = clkfreq << 2)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-13 05:25
    I knew that it was a servo controller, i just didn't know what to do about the timing.

    So would i put:
    waitcnt(clkfreq << 1)
    
    



    and

    waitcnt(clkfreq << 2)
    
    



    Thank you smile.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-13 05:40
    The clkfreq << x is a relative time, you need to add this to the present time (cnt) to make the value absolute, so the commands would be waitcnt(clkfreq << 1 + cnt) and waitcnt(clkfreq << 2 + cnt). In this case it doesn't matter but as general practice place cnt at the end of a waitcnt equation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-13 05:47
    Ok i have this:

    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000                                'Note Clock Speed for your setup!!
    
        SpeedServo = 8
        DirectionServo = 9
        
    OBJ
      SERVO : "Servo32"
    
    PUB Servo32_DEMO | temp
    
        'Preset Servo's you want to use to center position
        SERVO.Set(SpeedServo,1500)
        SERVO.Set(DirectionServo,1500)
    
        'Note: Servo pins that will be used must be preset before running "SERVO.Start".
        '      This is because the I/O direction is set here and is only executed
        '      at the beginning of "SERVO.Start".  Servo pins that aren't used will remain
        '      in their original direction state.
    
        SERVO.Start                                         'Start Servo handler
    
    
    repeat
         SERVO.Set(SpeedServo,1250)
         SERVO.Set(DirectionServo,1500)
    waitcnt(clkfreq << 1 + cnt)
    
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,1000)
     waitcnt(clkfreq << 2 + cnt)
     
         SERVO.Set(SpeedServo,1250)
         SERVO.Set(DirectionServo,1500)
    waitcnt(clkfreq << 1 + cnt)
    
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,2000)
    waitcnt(clkfreq << 2 + cnt)
    
    



    but it still only moves both servo's once.
    Any idea.

    Thank you smile.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-13 05:52
    What do you mean by once? Your indent structure is off, make the waitcnt's the same indentation with the other SERVO statements. Remember indentation imparts block structure in this language.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-13 05:57
    what do you mean by my indent structure is off.
    Please explain.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-13 06:04
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000                                'Note Clock Speed for your setup!!
    
        SpeedServo = 8
        DirectionServo = 9
        
    OBJ
      SERVO : "Servo32"
    
    PUB Servo32_DEMO | temp
    
        'Preset Servo's you want to use to center position
        SERVO.Set(SpeedServo,1500)
        SERVO.Set(DirectionServo,1500)
    
        'Note: Servo pins that will be used must be preset before running "SERVO.Start".
        '      This is because the I/O direction is set here and is only executed
        '      at the beginning of "SERVO.Start".  Servo pins that aren't used will remain
        '      in their original direction state.
    
        SERVO.Start                                         'Start Servo handler
    
    
    repeat
         SERVO.Set(SpeedServo,1250)
         SERVO.Set(DirectionServo,1500)
         waitcnt(clkfreq << 1 + cnt)
    
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,1000)
         waitcnt(clkfreq << 2 + cnt)
     
         SERVO.Set(SpeedServo,1250)
         SERVO.Set(DirectionServo,1500)
         waitcnt(clkfreq << 1 + cnt)
    
         SERVO.Set(SpeedServo,1000)
         SERVO.Set(DirectionServo,2000)
         waitcnt(clkfreq << 2 + cnt)
    
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-13 06:14
    Thank you smile.gif

    I didn't realize what a big difference indentation made, will have to look out for that next time.
    Is working great now.

    Thank you hop.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-13 06:16
    Your welcome, indentation is everything in this language, it is very much like braces ( { and } ) in C.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Don DDon D Posts: 27
    edited 2007-03-13 15:14
    In the editor, try 'Ctrl I' to turn on the indentation highlights -- I leave in on all the time...

    This is one of the most useful and innovative feature I have ever seen in a structured
    programming editor!
  • computer guycomputer guy Posts: 1,113
    edited 2007-03-14 05:26
    That helps hop.gif

    Thank you smile.gif
Sign In or Register to comment.