Shop OBEX P1 Docs P2 Docs Learn Events
Basic servo demo for propeller? — Parallax Forums

Basic servo demo for propeller?

RavenkallenRavenkallen Posts: 1,057
edited 2011-03-16 20:05 in Propeller 1
Hey, i am working on a autonomous navigation robot that will use a ping·module for its main sensory input. My robot already has its drive/ control systems installed and working. However, i need to use a servo( with the ping mounted on it) to provide at least a 180 degree rotation ability. I have used servos with other micros( Picaxe, Basic Stamp..) but never with the propeller. In fact, my robot used to have a Picaxe 40X2 as its main controller, but i switched to the propeller for more power. So, does anybody have a good servo demo for the Propeller? Something kinda easy to test out, but hopefully easy to modify. Thanks in advance..... I might upload some pics if you guys want to see what it looks like. I am pretty proud of·it...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller + Picaxe = Romeo & Juliet
«1

Comments

  • ThricThric Posts: 109
    edited 2010-07-12 02:12
    Go to the parallax object exchange and search for servo program. Heres the link:
    http://obex.parallax.com/objects/search/?q=servo&csrfmiddlewaretoken=39be308f103736d8a27c770f2b7d5024
  • ratronicratronic Posts: 1,451
    edited 2010-07-12 04:51
    Ravenkallen, here is a simple demo moving a servo back and forth from 3 positions. You can probably use this for an example how to use the servo32v5.spin that comes with the propeller tool.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-07-12 13:34
    Hey, thanks guys. I will test it out soon.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller + Picaxe = Romeo & Juliet
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-07-13 03:18
    Perfect. The servo driver worked without any problems at all. Thanks a ton guys....Now to finish my robot.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller + Picaxe = Romeo & Juliet
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-13 09:42
    I am trying control a servo using the PRC4PP shield for the Propeller Platform and I can't seem to get it to work. I'm wonding if anyone might have some insight into what I am doing wrong or how to debug the problem.

    I can blink an LED on pin0, so I know the PP pin works. It also blinks at the rate I expect (once a second).

    The PRC4PP shield basically puts a 1 K ohm resistor to a servo header and Vbat to the center pin. I use a volt meter to ensure ground is ground, and Vbat is on the center pin. I also used the ohm meter to ensure P0 has 1K ohm to the left pin. I plug the servo into the board with the white lead to left, ground to right to match the header.

    I run the program in the above post setting the pin to P0 and the servo will twitch, but not move to the correct offset. If I change pins it won't move at all, so it appears to be getting some kind of signal.

    Honestly the PRC4PP is electrically pretty simple and I've controller servos with the BS2. So I am starting to wonder if the timing in the PP is off somehow, but don't know how to validate that. I've tried with multiple servos, so I don't think that's the problem.

    Martin
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-13 09:48
    Martin,
    You've got to provide your program code. From your description of the wiring, that all sounds fine. You've got power to the servo (assuming your battery is ok) and some kind of control pulse is getting to the servo. The PP itself should be fine. That leaves the program as the likely culprit.

    Sorry, you did mention that you used ratronic's demo. His demo uses pin 8 for the servo and you mention that you're using pin 0. Try changing the program (look at the comments) or rewiring your servo.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-13 09:52
    Mike, I'm using the servo.spin ratronic posted in this thread. The only change I made was changing 8 to 0 for the pin. I even went to pin 8 to use it unmodified.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-03-13 10:00
    What are you using for power? Perhaps the servo pulls too much power and causes the Prop to reset. One way to check this would be to blink an LED at the beginning of the program, before the calls to the servo object. If the Prop resets you will see the LED blink again.

    John Abshier
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-13 10:03
    Martin,

    You mentioned you used multiple servos. Where they all the same brand?

    I've found some of my servos don't like the 3.3V logic signal. You might want to try a different servo brand or use a level shifter.

    Since the BS2 uses 5V with its signal you wouldn't have seen a problem when you used the stamp with your servos.

    Duane
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-13 10:05
    Hmmm. There's nothing I can see wrong with his demo program and the Propeller Platform is a reliable, stable Prop board. The servo wiring you described is pretty basic. When everything sounds like it ought to work, the likely cause is some kind of power problem or wiring mistake. Essentially, something that you say is so, isn't really.

    In terms of debugging, you could try a simple Spin-only servo movement test like:
    con
      _clkmode = xtal1 + pll16x      'set to run @ 80Mhz 
      _xinfreq = 5_000_000           ' "   "  "  "   "
      servo = 0                            ' servo pin
    
    PUB main
       outa[servo] := 0
       dira[servo] := 1 ' make an output
       repeat
          outa[servo] := 1 ' mid-range servo pulse
          waitcnt((clkfreq/10000) * 15 + cnt) ' wait 1.5ms
          outa[servo] := 0
          waitcnt((clkfreq/1000) * 20 + cnt) ' wait 20ms
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-13 10:21
    Martin,

    I was thinking back to times I used servos with the Propeller and remembered another thing to try.

    Try bypassing the resistor. I had a servo that wouldn't work until I replaced a resistor with a piece of wire. I'm not sure what the value of the resistor was but it wasn't higher than 10K ohms.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-13 10:29
    @Mike, that's a good idea I'll try that.

    @John Abshier and @Duane, I'm using 6 volts with Power HD servos. I had the Parallax serial terminal up in my other program and didn't notice a reset as I had a debug message at program start. I will try another brand also.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-13 13:48
    Thanks everyone for your responses. I now know the root cause of the issue and Duane Degn was right.

    I tried bypassing the resistor, no luck. I was using power HD, so I tried a GWS and that didn't work. I then tried a cheapie generic servo and it worked with a direct pin connection. I then plugged the cheapie servo into the PRC4PP and it worked there as well. I plugged all the servos into a Basic Stamp and they all worked with that.

    So this is a 3.3v versus 5v logic level incompatibility with Power HD heavy duty and GWS mini servos. Groan, this was exactly the sort of thing I was afraid of with the 3.3v propeller chip.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-03-13 15:04
    Hi Martin,

    so transfer all your depressive thoughts to marvin to feel good again ;-))
    Some small transistors or any other logic levelshifter will do it.

    best regards

    Stefan
  • PublisonPublison Posts: 12,366
    edited 2011-03-14 12:48
    Martin,

    Are these Digital or Analog servos? I have had no problems driving either one directly off the Propeller, (once I bypassed the dang translators).
    Martin_H wrote: »
    Thanks everyone for your responses. I now know the root cause of the issue and Duane Degn was right.

    I tried bypassing the resistor, no luck. I was using power HD, so I tried a GWS and that didn't work. I then tried a cheapie generic servo and it worked with a direct pin connection. I then plugged the cheapie servo into the PRC4PP and it worked there as well. I plugged all the servos into a Basic Stamp and they all worked with that.

    So this is a 3.3v versus 5v logic level incompatibility with Power HD heavy duty and GWS mini servos. Groan, this was exactly the sort of thing I was afraid of with the 3.3v propeller chip.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-14 14:57
    Given the price I would assume they are analog. Now that I know the problem is not software or Propeller Platform specific, I'm going to move over to a thread about the board. It has images so people can see what I'm talking about.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-14 19:26
    Martin,

    I think you'll need some sort of transistor to control the servos. I have a couple of these I plan to use. I haven't tried them yet but I'll find the various parts I need and try it tonight or tomorrow. I'll let you know if they work.

    The board I linked to above uses these transistor arrays. Edit: The board does not use these transistor arrays. The transistor arrays are used in a different SparkFun level shifter (RS-232).

    I'm not sure if the thread about the board it the right place to discuss the problem since the board works with most servos.

    Duane
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-14 19:57
    Duane, thanks I will be curious how that works out.

    With regards to the PRC thread or this thread. I'm willing to discuss it in this thread, and thanks for your help already. I guess I was hoping to buy a board which allowed the Propeller to control all viable servos, and not most or some servos. Granted the PRC uses the same technique that everyone says to use, but it seems like a lurking gotcha with using it or the Propeller chip in general. I certainly wasn't happy to encounter it and was really lost when it happened.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-14 21:09
    Martin,

    I found my servo that doesn't work with the Prop. The level shifter doesn't work. Dang it!

    It's really strange. I scoped the input and output of the signal to and from the shifter and it looks great as long as no servo is attached.
    LevelShifterWithoutServo.png


    Once a servo is attached the output voltage drops to near the input. Edit: It drops to below the input.
    LevelShifterWithServo.png


    I tried paralleling two of the shifters together. I looked better on the scope; the output was a little higher with a servo attached but it still didn't control the servo.

    I'm sure this is solvable. I'll work on it some more tomorrow.

    Duane

    Edit: I changed the images from huge bitmaps to small png. I also noticed the output with a servo attached is below the input voltage of the level shifter.
    556 x 545 - 17K
    556 x 545 - 17K
  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-03-15 00:36
    You should be able to use a transistor or a darlington array to do the level shifting, since it only needs to go in one direction. A 6V servo probably has a threshold of about 3.6v or so (they usually use about 0.6 * Voltage instead of 0.5). If you're getting output with a "simple" servo, like the GWS, your code is fine.
  • PublisonPublison Posts: 12,366
    edited 2011-03-15 05:49
    Try a 1R2 to 4R7 resistor inline with the servo signal after the translator. Here's a quote from a previous thread:
    I read the data sheet on the voltage level translators the PSC uses a few months ago. These level translators are bidirectional and automatically sense signal direction on a pin by pin basis. The specific method the chips use to sense signal direction is what I think is causing a problem. First, both sides of the chip are always a weak output. Next when a logic transition (say HI to LOW) is detected on a pin (say on the 3.3v side), the other side (say at 5v) of the same pin-pair briefly activates a strong output with the same state. (a logic LOW in this case) [ug, the data sheet explains this much better]

    http://forums.parallax.com/showthread.php?118121-Digital-servo-s-on-USB-servocontroller/page2&highlight=servo+problems
    Duane Degn wrote: »
    Martin,

    I found my servo that doesn't work with the Prop. The level shifter doesn't work. Dang it!

    It's really strange. I scoped the input and output of the signal to and from the shifter and it looks great as long as no servo is attached. Once a servo is attached the output voltage drops to near the input. I tried paralleling two of the shifters together. I looked better on the scope; the output was a little higher with a servo attached but it still didn't control the servo.

    I'm sure this is solvable. I'll work on it some more tomorrow.

    Duane
    Attachment not found.
    Attachment not found.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-15 06:58
    Thanks Jason and Publison,

    The level translator I'm using isn't the same kind as from the other thread. It's not bidirectional.

    I've got my stubborn servo to finally work. Ahem. . . Here's the embarrassing part. The servo works fine with the level shifter from SparkFun if . . . I have the current turned up high enough on my power supply.

    I use a current limiting power supply and I usually leave it set to a few hundred mA. Well this servo draws spikes of current of up to 495mA. Insane.

    It's a special "gyro" servo for a RC helicopter. It's supposed to be very fast. I guess the speed come at the cost of high current draw.

    The current peaks aren't noticeable normally on my multimeter (a nice Fluke). It's only when I use the Max/Min function can I catch these current spikes.

    @Martin, How is your power supply? Can it source enough current? I still needed the level shifter with my servo even with the current turned up.

    I noticed SparkFun is currently sold out of the level shifters. They usually replace stock quickly.

    I think I have an extra level shifter board. PM me your address and I'll send it off to you.

    Duane
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-15 06:58
    Duane, I'm using 4 AA batteries, the servos are connected to V batt and not to the regulator. I haven't noticed any brown outs in the propeller. I have a more robust power supply I can try tonight.


    FYI, I'm moving to this thread so all the posts will be in one place.

    In reading online about level shifters there's a fair number of ways to do it, but I am out of my depth on how to modify the PRC4PP board. I'd like to use it rather than scrap it and start again. The servo headers use an RC circuit (R is 1K ohm and C is 0.01 uF) on pins 0 to 7 to filter servo noise and limit current to the propeller. This seems pretty reasonable and looks like this ASCII schematic:
                 1K
    Prop Pin ---/\/\/\--+-- to header signal pin
                       |
                0.01uf |
          Ground --)|--+
    

    One level shift circuit I saw uses a diode and pull up resistor like this:
                           10K
                       +--/\/\/\-- Five Volts
                       |
    3.3 V Signal --|<|--+-- to header signal pin
    

    I think I could merge these two as follows:
                                  10K
                              +--/\/\/\-- Five Volts
                1K            |
    Prop Pin --/\/\/\--+--|<|--+-- to header signal pin
                      |
               0.01uf |
        Ground ---)|--+
    

    But I bread boarded the level shift circuit above and it neither helped nor hurt. The servo that worked still worked, the servos that didn't still didn't. I retested with a BS2 and all the servos worked. So at this point I have no clue how to reliably use a servo with a propeller chip. I will be curious to see how the transistor level shift works out.

    I think the chip on this board http://www.nkcelectronics.com/5v-to-33v-logic-level-shifter-bo.html might be the same one used on the Parallax servo control board and the robot control board. But I'm not keen on buying something only to have it not work either.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-15 16:52
    I retested using a 6 V 1 amp AC adaptor and got the same results. So my power supply wasn't an issue.

    For another project I ordered some GWS standard servos a week and a half ago. They came in the mail today, and they work fine with 3.3 volt control signals. So right now it seems that it's 50/50 if a servo will work or not without level shifters. Those are not great odds.
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-03-15 20:25
    I have found that when I need a level shifter for similar applications (1 way from 3.3 to 5V) an 74HC244 or 74HCT244 are perfect for the job. They delay on these is fairly even so they should work with the existing code, even being a PWM controlled device as a servo.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-03-15 21:01
    If it's truly a 3.3V verses 5V signal issue with your servo, then there is no reason that this should not work...

    http://forums.parallax.com/attachment.php?attachmentid=58334



    Martin_H,

    With that level shifter you have the diode is always in forward conductance... The path is from the 5V supply through the 10k resistor, through the diode, and when the I/O is HIGH to a 3.3V supply ; when the I/O is LOW it's to GND. Either way the Anode side of the diode always has a voltage potential causing the diode to conduct. This conduction allows the 3.3V to pull down the 5V supply your intending to go to the servo to about 3.9V when the I/O is HIGH (3.3V) .... it's a little better with the version using the additional 1k resistor (..almost 4V) but still this is not a 'correct' way to design or make use of a level shifter. The transistorised version provides much better isolation between the 3.3V and 5V (or 6V) servo supply.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-16 06:55
    @davidsaunders, thanks I'll keep that in mind.

    @Beau, thanks for the level shifter schematic and the description of what's wrong with the diode one. I have enough spare parts that I can bread board the transistor version tonight.

    Thanks to all for the help as I'm a software guy with limited hardware experience. The Basic Stamp is within my comfort zone, so I knew stepping into the Propeller world might bring on difficulties.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-16 07:19
    Beau,

    That works with my finicky servo.

    Thanks
  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-16 17:20
    Well I have interesting and slightly mysterious news to report.

    I bread boarded Beau's circuit and the mini servos and several of the Power HD servo's started working. However, the base rotation servo (which bears the entire load of the arm) did not, and I noticed that the propeller chip was resetting with that servo. So I hooked up two power supplies, one for the propeller and one for the servos, and the base servo began working. On a lark I removed Beau's level shifter and that servo still worked. So I went back to the other problematic servos and they all worked in the no level shifter two power supply configuration.

    So I am happy, but slightly mystified. When I was using a single supply I was running the servos off Vbatt, not the output of the regulator. I also have beefier than normal voltage regulator (1.5 amp). I could see a Power HD servo drawing enough power under load to brown out the prop. But not the GWS mini's.

    But why would the level shifter help?

    Why would two power supplied definitively solve the problem?

    Why is the Basic Stamp 2 and my Freeduino (shudder) not effected by what ever is effecting the Propeller Platform board? I soldered together my BS 2 and my Freeduino, so it's not like the Propeller Platform kit is the first thing I put together.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-03-16 18:13
    Martin_H,

    Two power supplies for servo's doesn't surprise me, in fact I would recommend it.

    As far as the level shifter helping out, servo's produce a lot of electrical noise when in motion, the level shifter could be acting as a filter.

    The BS2 and the 'Freeduino' you mention, the higher voltage (5V) provides a 'better' signal to your particular servos that want 5V. This could also explain the level shifter helping out as well.
Sign In or Register to comment.