Shop OBEX P1 Docs P2 Docs Learn Events
assistance needed!!!! — Parallax Forums

assistance needed!!!!

TrezitorulTrezitorul Posts: 68
edited 2007-07-02 01:33 in Propeller 1
I bought a servo to play around with and I wired it up and ran it using the demo program and various programs off of this forum but my servo only heads to the neutral position no matter what pulse length I put in. Can some one enlighten me on whether or not servos only spin in one direction and how can the direction be reversed. jumpin.gif. Also can anyone give me a schematic for attaching a photocell to the prop.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-29 14:30
    Servos go clockwise and servos go counterclockwise. It all depends on the pulse width. A control pulse of 1.5ms width is the neutral position. Pulses shorter than that cause movement in one direction. Pulses longer than that cause movement in the other direction. If that's not what's going on, something must be wrong with your setup. If you'll post a schematic and a listing of your program, maybe we can give you some specific advice.

    What kind of photocell are you talking about? A CdS resistive photosensor? Typically, those are connected as part of either a voltage divider or an RC circuit. The "Basic Analog and Digital" tutorial that's downloadable from the Stamps in Class webpage has a chapter on this for use with a Stamp, but the same thing applies to the Propeller. You can even use the BS2 compatibility library from the Object Exchange to provide an equivalent to the RCTIME statement in Stamp Basic.
  • RinksCustomsRinksCustoms Posts: 531
    edited 2007-06-29 17:22
    The WAM (Whats A Microcontroller) text also has good coursework on these subjects

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Definetly a E3 (Electronics Engineer Extrodinare!)
    "I laugh in the face of imposible,... not because i know it all, ... but because I don't know well enough!"
  • TrezitorulTrezitorul Posts: 68
    edited 2007-06-29 20:03
    Not included in the schematic is the fact that the my prop is powered by the transformer that came with it. I am using 20 gauge wire and it acts strangely by not supplying power to the servo sometimes, could this be a factor. I tested the connection out with my multimeter and it reads connected. I did notice that if I move the wires apart they behave better in supplying the the servo power. Is it possible that the power line is interfering with the signal line because they are very close together because I used the wire to directly connect my servo. I'm sorry Mike for not mentioning it but I am using Cds cells. Finally Could someone give me a program that makes the servo pan to make sure it is not a programming error on my part.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-29 20:40
    I believe part of your problem is the power demands of your servo vs. the capability of your power supply. Servos can draw over 1A of current and generate a bit of noise as would any motor. Servos should be powered by a supply capable of supplying 1-1.5A peak with a voltage in the range 4.5-6.5V, sometimes as much as 7.2V (although that shortens the life of the servo a little bit). This servo supply should have a common ground with the supply to the logic (the Propeller), but should be isolated otherwise from the logic. If you look at the circuit for the Protoboard with the Accessory Kit, you'll see that you can power servos either from the unregulated input to the Protoboard or from the output of the 5V regulator, but the servo power is isolated from the logic using an inductor and a large electrolytic capacitor. The regulator on the Protoboard can supply about 1A which is adequate for one servo if nothing much else of significance has to be powered from it.

    I use a 6V power supply (either a 5 cell NiMH battery pack or a 6V 2A "wall wart") to power my BoeBot which has 3 servos of which only 2 are in use at a time, a PING, a couple of IR LEDs, and some other low power sensors, all connected to a Propeller Protoboard with the Accessory Kit. The servos are powered directly from the 6V source. The 5V regulator only powers the logic and sensors.

    Download BoeBotBasic from the Propeller Object Exchange and use the servo control statements to set a couple of different servo positions. There's enough documentation and one example included that should help you.
  • TrezitorulTrezitorul Posts: 68
    edited 2007-06-29 21:22
    Here is the program I used to test the servo. I pulled it off of the thread named servo problems.
    con
    _clkmode = RCFAST

    Pub start
    repeat
    dira[noparse][[/noparse]0]~~
    outa[noparse][[/noparse]0]~~
    waitcnt(clkfreq/572 + cnt) 'servo at 180 with pulse of 1.75
    outa[noparse][[/noparse]0]~
    waitcnt(clkfreq/50 + cnt) '20ms pause between pulses

    Thanks for mentioning the power supply because now that I tested my batteries I found out that they were only producing 4.6 volts the minimum so the servo was still turning but the power was really low. How many amps do 4AA batteries produce and is the servo suposed to get really hot after only a few minutes of use. How do you ground the servo if it is already grounded to the battery. The funny thing is that the servo will always spin counter clockwise till it hits the mechanical stop no matter what pulse.(this might explain the heat).

    Thanks so much everyone for answering my many questions! tongue.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-29 21:38
    When you use RCFAST, you don't really know what the clock frequency is. It could be anything from 8MHz to 20MHz. You could try 12MHz (_clkfreq = 12_000_000), but your servo timing could be way off. Better is to use a crystal. If you have a Demo Board, you can use _CLKMODE = XTAL1 + PLL16X and _CLKFREQ = 80_000_000 with the built-in 5MHz crystal.

    Your servo should not get really hot. If you only connect the power leads to the servo and leave the control lead unconnected, the servo should just sit there. You should be able to turn the output shaft slowly against mechanical resistance, but the servo motor should not attempt to keep it from moving. The servo should not get hot at all this way since the control circuitry should be idle (with no control pulses coming in).

    The ground lead (-) of the servo should be connected to the battery ground. The ground lead of the Propeller circuitry should also be connected to the battery ground.
  • TrezitorulTrezitorul Posts: 68
    edited 2007-06-29 22:46
    Now I am curious on a standard servo where is neutral? On my servo neutral is at the front (short end). Is that correct. Because that is were 0 is!

    I am wondering is there any possibility that I got a faulty servo or that I unknowingly broke it? freaked.gif When I was testing it I would spin the shaft manually all the way from the front 0 degree position to the max position. Would a picture of it and my setup be useful.

    Post Edited (Trezitorul) : 6/29/2007 11:07:02 PM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-29 23:34
    The servo horn is removable and re-positionable so does not indicate neutral. Neutral should be roughly in the centre of the available travel.

    Graham
  • TrezitorulTrezitorul Posts: 68
    edited 2007-06-29 23:37
    If neutral is not at the center of the available area is it possible that I have a bad servo? Could you please send me some reliable code that will got to the neutral position. When I said it was at zero I was not using the servo horn as the indicator but I used the location where it stopped due to the mechanical stop.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-30 00:13
    Are you using one of the Propeller development boards or what?· (Demo Board, Protoboard, PropStick, ???)· Pretty much everything has a crystal for a system clock.· Assuming you have a 5MHz crystal:
    con
       _xtalfreq = 5_000_000
       _clkmode = xtal1 + pll16x
     
    pub start
       repeat
          dira[noparse][[/noparse]0]~~ 'servo should be connected to I/O pin 0
          outa[noparse][[/noparse]0]~~
          waitcnt(15*clkfreq/10000 + cnt) 'neutral is 1.5ms = 15 x 100us
          outa[noparse][[/noparse]0]~
          waitcnt(clkfreq/50 + cnt) '20ms pause between pulses
    
    



    Post Edited (Mike Green) : 6/30/2007 12:18:34 AM GMT
  • TrezitorulTrezitorul Posts: 68
    edited 2007-06-30 04:38
    I am using a demo board.Did you mean _xinfreq instead of _xtalfreq because if I run it with _xtalfreq it gives me an error message that reads _clkfreq or _xinfreq must be specified. While I was looking over the code I was wondering what does 15 *100us mean?
    One more thing how many clock cycles are in a megahertz and how many megahertz are in a ms. This is confusing me a great deal especially when I look over other peoples programs. The results from your program Mike were the same the manually positioned servo spun from the 180 position the back ( long end of the servo) or where the mechanical block is to the mechanical block at the front(short end) with no stop in between.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-30 05:03
    Sorry. I didn't have my Propeller Manual. It is _xinfreq.

    The neutral position of a servo is (by definition) at 1.5ms control pulse width and should occur roughly half way between the two mechanical stops. This is the same as 1500us (which is 15 * 100us). 1 second = 1000 milliseconds (ms). 1 millisecond = 1000 microseconds (us). 1 microsecond = 1000 nanoseconds (ns).

    The Demo Board has a 5MHz crystal. The phase locked loop (PLL) in the system clock circuitry can multiply this by up to 16 times to give an 80MHz system clock (5MHz x 16 = 80MHz). If you take the inverse of this, you get a clock pulse width of 12.5ns. The Propeller executes native instructions in 4 clock cycles or 50ns. That gives an execution rate of 20 million instructions per second (MIPS). With 8 cogs executing simultaneously, that gives an aggregate rate of 160 MIPS. Spin is an interpreted language and it takes about 80 or so native instructions to perform an operation in Spin (like A++). That's approximately 2 million Spin operations per second total.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-30 09:15
    Trezitorul said...
    how many clock cycles are in a megahertz and how many megahertz are in a ms.

    Further to Mike's description of ms, us etc.

    Frequency is the number of cycles (repetitions of the waves pattern) per second so 1Mhz for example is one million cycles per second. That means that the length of one cycle (the time period T) is 1/1000000, in seconds. If you then wanted it in ms multiply by 1000 or in us by 1000000. (note as there are a million cycles per second at 1Mhz and a million us in a second the period must be 1us).

    This gives you the useful formula:

    T = 1/f (think one second divided into f parts where f is the number of parts per second)

    And

    f = 1/T (think one second divided into the length of one cycle giving the number of cycles that fit in a second)

    So you can convert from one to the other easily and the equations is easy to remember (especially if you understand it).

    The knowledge of units is important and you should try to understand them, some are easy because we are used to them mm (1000 in a M) some are less so, like micro, nano, pico, femto but all represent a small fraction of the full unit. You should read up on this in a text book aimed at what you feel it your level as it will really help all your programming and experimentation.

    Graham
  • rjo_rjo_ Posts: 1,825
    edited 2007-06-30 16:06
    Trezitorul

    About the photocell... you can use "Test RC Decay Circuit (testrcdecay.spin) from the PEK Counters and Circuits Lab... and simply substitute the photoresister for the resistor. remember... light decreases the resistance of the photoresistor... not the other way around... so low light takes longer to detect than bright light. The Lab is great fun and very instructive.

    About the servo ... I got exactly the same behavior and it had nothing to do with the software or hardware... my setup was constantly causing a reset.
    The problem is... until it works... it doesn't work... and if you are new to both the hardware and the software... it seems like nothing works... That's where the Labs come in... unless you make a mistake... they work exactly correctly.

    Once you get the lab working... you can experiment from there.


    Rich
  • TrezitorulTrezitorul Posts: 68
    edited 2007-07-01 20:20
    I was wondering one other thing I have a JR servo and I opened it up and number 1 the circuitry was very poorly made and number two when I pulled off the top I programmed the servo 32 demo program into my propeller and the servo spun continuously even though I turned the pot it never stopped. Is this normal? confused.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-01 21:29
    If it has a pot, it's probably what is called a continuous rotation servo where the servo mechanism and mechanical stops are disabled and the control pulse is used to set the direction and speed of the motor rather than the position. The pot is used to set the neutral position where the motor should stop at a pulse width of 1.5ms.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-07-01 23:53
    I think he took a normal servo to pieces, the pot being the feedback one.

    If you did you should definately be able to get the servo so stop and change direction with the pot as long as the pulse width sent to the servo is correct.

    Graham
  • RinksCustomsRinksCustoms Posts: 531
    edited 2007-07-02 01:33
    http://www.parallax.com/dl/docs/books/edu/Wamv2_2.pdf

    This doesn't display or select properly for me to just drop the image into this reply. Pages 123-126 will answer all your questions about servo's.

    If you can't download a 5.15MB file easy, i'll scan it from my WAM book and post for you. Hope this helpssmilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Definetly a E3 (Electronics Engineer Extrodinare!)
    "I laugh in the face of imposible,... not because i know it all, ... but because I don't know well enough!"
Sign In or Register to comment.