Shop OBEX P1 Docs P2 Docs Learn Events
trying to flip relay but servos move? — Parallax Forums

trying to flip relay but servos move?

thebucketmousethebucketmouse Posts: 20
edited 2009-05-26 07:09 in BASIC Stamp
So I have 2 servos, one on P7 and one on P13 with a BS2 board of education. Also, I have a reed relay with the coil·tied on one end to P1 and on the other end to VSS. I'm trying to get the stamp to flip the relay using HIGH 1, PAUSE 200, LOW 1 but whenever it does this the relay does not switch, but my two servos both move clockwise??? How is this even possible? The only way they are attached is where they come together at VSS.. other than that the servos have no contact with the reed relay. Please help me understand what I'm doing wrong.
«1

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-05-17 19:21
    Could you attach a drawing of your circuit? Do you have a resistor inline on P1 and a diode reverse biased across the coil? where are you getting the power for your servos? Attach your actual code using the attachment manager so we can load your code and test it. Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-17 19:25
    I didn't use a resistor or diode with the relay coil, no. Should I have? Also, I havn't written any other code besides what I posted earlier, as simply running that program causes the servos to move unintentionally. Also, each servo is connected to VSS, VIN and one of the I/O pins (7 or 13)
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-17 20:20
    What's probably happening is that trying to "flip" the relay causes a power surge that resets the Stamp and your program starts over from the beginning. This is why a circuit diagram and a copy of your code (as attachments) are necessary to help you. Otherwise, you're just giving us a little bit of the puzzle and we have to guess the next piece.
  • FranklinFranklin Posts: 4,747
    edited 2009-05-17 20:26
    Servos will sometimes move when they are powered up and since you are not telling them to do anything they think you don't care what they do.

    ·Also if you don't refresh them every 20ms they loose interest and motivation in keeping still.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen

    Post Edited (Franklin) : 5/17/2009 8:35:14 PM GMT
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-17 21:13
    Unfortunately I don't really know how to draw out a circuit, but there isnt anything in my circuit that I havnt detailed the wiring of already..
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-17 23:34
    thebucketmouse said...
    Unfortunately I don't really know how to draw out a circuit, but there isnt anything in my circuit that I havnt detailed the wiring of already..

    You could post a picture...

    Add some code to the beginning of your program that makes a sound or lights up a LED, that way if the Stamp is resetting you will get an audio or visual indication. The BoeBot manual , page 105, describes how to do this - they call it a brownout detector.

    Rich H

    Post Edited (W9GFO) : 5/17/2009 11:40:00 PM GMT
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-18 03:01
    Alright, here's a crude circuit diagram if you can't see what I'm trying to describe. http://s57.photobucket.com/albums/g236/thebucketmouse/?action=view&current=diagram.jpg
    and at W9GFO, could you expound on that a little bit about the brownout detector? I would put the buzzer in my code before attempting to flip the relay, and then what?
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-05-18 03:09
    thebucketmouse,

    A reverse biased diode across the relay coil is a must to prevent back EMF entering into the Stamp. Connect the Anode of the diode to Vss, and the Cathode of the diode to the I/O pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-18 03:14
    thebucketmouse said...

    I would put the buzzer in my code before attempting to flip the relay, and then what?

    Then if you hear the buzzer go off, you know the stamp reset itself and began running the code from the beginning again.

    You can post your picture inline if you do the following;

    (img)http://i57.photobucket.com/albums/g236/thebucketmouse/diagram.jpg(/img)
    



    Use square brackets"[noparse][[/noparse]" instead of the "(" though.

    Rich H

    diagram.jpg

    Post Edited (W9GFO) : 5/18/2009 2:38:31 PM GMT
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-18 19:17
    Beau Schwabe (Parallax) said...
    thebucketmouse,

    A reverse biased diode across the relay coil is a must to prevent back EMF entering into the Stamp. Connect the Anode of the diode to Vss, and the Cathode of the diode to the I/O pin.

    So the diode would be in parallel with the coil? How would that stop the EMF from traveling through the coil??
  • skylightskylight Posts: 1,915
    edited 2009-05-18 20:20
    The coil of the relay is what produces the Back EMF pulse, when the relay is de-energised rapidly the coil can then produce a high voltage that can affect the stamp or even damage it, the diode if connected properly ie the right way round will in effect short out the coil and the pulse.

    The principle of Back EMF is used to advantage in a car where the coil is energised and de energised rapidly by the points, the high voltage pulse is output from the coil to produce a spark at the sparkplugs, now imagine this energy being discharged into your stamp, get the picture? freaked.gif
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-18 23:07
    I put the diode in but it still does the same thing... [noparse]:([/noparse]
    this time I made a video if that helps outline the problem any better
    www.youtube.com/watch?v=Un1PWeY5GXs

    Post Edited (thebucketmouse) : 5/18/2009 11:15:34 PM GMT
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-18 23:49
    How are the servos getting their power? Are the servos getting power by way of the external battery pack? And if so, do they get powered on when the relay activates? It is normal for servos to jump a bit when first powered on.

    Rich H
  • Clive WakehamClive Wakeham Posts: 152
    edited 2009-05-19 00:04
    Have you tried to connect the coil of the relay to +V instead of VSS and use the opposite commands (ie Low 1, pause 200, high 1)?

    Usually servos only move when they get a certain pulse signal, and since both servos move to the exact same position they are getting the same signal at the same time.
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-19 00:12
    Clive Wakeham said...
    Have you tried to connect the coil of the relay to +V instead of VSS and use the opposite commands (ie Low 1, pause 200, high 1)?

    Usually servos only move when they get a certain pulse signal, and since both servos move to the exact same position they are getting the same signal at the same time.

    I've tried this, and I'm pretty sure it did the same thing.
    W9GFO said...
    How are the servos getting their power? Are the servos getting power by way of the external battery pack? And if so, do they get powered on when the relay activates? It is normal for servos to jump a bit when first powered on.

    As I drew in the diagram, the servos are only connected to an I/O pin, VSS and VIN.



    I think it could be something to do with this back-EMF pulse they were talking about a couple posts back, because the relay circuit and servo circuits are totally separated. There's no way the relay would affect the servos unless the basic stamp itself freaked out because of the back-EMF. Unfortunately, the parallel diode didn't help stop it...

    Another thing confusing me is that the servos don't go crazy when the external battery pack is switched off (this is shown in the video), but I can't see how the battery pack would affect me sending the HIGH signal through the relay coils.

    Post Edited (thebucketmouse) : 5/19/2009 12:17:46 AM GMT
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-19 00:45
    My understanding of back EMF and it's effects on the stamp are weak at best. If the diode is supposed to correct that problem but your servos still twitch as they do, then I would look back into the brownout issue. Have you eliminated that as a possible cause?

    You will want to have the servos drawing power separately from the stamp. That could be a source of trouble now but certainly will be once you get the gun and ping servos moving.

    As an experiment, create a repeat loop that keeps the servos centered. Pull the jumper out of P1. Then with that running touch the jumper to vdd to simulate the pin going hi and see what the servos do.

    Wait a minute, VIN for the servos? That is unregulated - 9 volts! Servos don't like more than 6.

    Rich H
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-19 01:33
    I'll try what you said and see what happens. Also, the Parallax book tells me to wire the servo to VIN for the "homework board", which mine is.
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-19 01:44
    thebucketmouse said...
    I'll try what you said and see what happens. Also, the Parallax book tells me to wire the servo to VIN for the "homework board", which mine is.

    From page 1 of the Homework board manual...

    attachment.php?attachmentid=61035

    Wiring the servos to VIN would be fine if you were using a battery pack of 4 or 5 cells instead of the 9 volt battery to power the stamp.

    Rich H

    Post Edited (W9GFO) : 5/19/2009 1:50:33 AM GMT
    1175 x 111 - 79K
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-19 02:02
    That doesn't make any sense... on page 111 of "What's a Microcontroller?" which is the book I use, it shows a diagram of a servo plugged in to the homework board breadboard and the 3 servo wires going to Vss, Vin and P14 and the caption is "Connecting servo to servo header on a homework board"
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-19 02:29
    Well I suspect that using VIN on the HomeWork Board works alright when the servo is not under load - just to experience how to control a servo. When it comes to actually using a servo in a project it really should have a separate power source. The servo you have the gun mounted to will draw a lot of current (compared to a bare servo) due to it having to accelerate the mass of the gun. Since you have that battery pack already it should be a simple matter of wiring it up to the servos. That would eliminate any problem with the servos drawing too much current and causing a brownout - besides, you'll have to do it anyway eventually.

    Rich H
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-19 02:51
    I just don't think that is the problem, I can control the servos just fine with everything mounted on them the way it is right now, the only malfunction I have is trying to use this relay.
  • FranklinFranklin Posts: 4,747
    edited 2009-05-19 03:04
    Try writing code that sets the position of the servos and refreshes that position every 20ms before firing the relay.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-19 03:29
    Something else to consider, each IO pin is rated to source up to 20 ma. I looked up some reed relays and found a 5 v one which has a 150 ohm coil. I take that to mean it uses 33 ma to drive the coil.

    Rich H
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-05-19 05:19
    The next line of attack, and it goes along with what I believe W9GFO is getting at, is that you might try driving the relay with a transistor to offload some of the current on the I/O. A typical 2n3904 transistor can easily drive up to 300mA. You still need a diode across the relay coil, and a 1K resistor in addition to a 2n3904 transistor.


    The schematic below lowers the I/O current requirement down to about 4.4mA
                                   Diode
                       o------------>|---------o
                       |                       |
                       o------>[noparse][[/noparse]Relay Coil]<---o--->+5V
                       |
                       | 
             1k        C
    I/O >---/\/\-----B    2n3904
                       E 
                       |
                       |
                      GND
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-20 01:20
    I built the circuit you made and the results changed a bit... this time the servos still turned to the right but the gun started firing this time, while turning [noparse]:([/noparse] I just can't keep these stupid servos still! And like I said earlier, it's no problem to control the servos if I want to, I only run into a problem with this relay. Any other suggestions?? Please???
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-20 04:44
    It's not clear to me which suggestions you have tried and which ones you haven't.

    Have you ruled out brownout 100%? If so how?

    Have you tried Franklin's suggestion?

    I have been there - suggestions come in that I don't think will help. Much of the time they don't correct the problem but I do them anyway so that I can check them off the list and move on. Way back when I first started with the BoeBot I had a problem that I was sure wasn't brownout related. I spent a great deal of time trying to track down the cause. I skipped over the boring suggestion of checking the battery because I was sure that something mysterious and interesting was going on. Nope, I finally got to the point where I would try anything and checked the battery which was new just a short time ago...

    It's a hollow victory solving such a basic problem after so many hours of work.

    Rich H
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-20 18:09
    Haha, I understand. I put in the diode and I built the transistor circuit, but no, I havn't yet made the buzzer circuit that someone was talking about earlier. I'll do that in a bit and get back with the results.
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-20 22:08
    Alright I added the brownout detector, if I understood it correctly. I added an LED and included HIGH 16, PAUSE 200, LOW 15, PAUSE 200 to the beginning of my program. This makes the LED blink on and off before doing the program. But after the blinking, the gun fires and spins as usual. The LED only blinks once, so the stamp isnt resetting. I called tech support and he said that my whole circuit, even the external battery pack should be on a common ground, so he told me to connect the external battery pack to VSS. I did this but still the same results. [noparse]:([/noparse]
  • W9GFOW9GFO Posts: 4,010
    edited 2009-05-22 05:42
    What happens when you send a signal to the servos immediately before activating the relay - like Franklin suggested?

    Rich H
  • thebucketmousethebucketmouse Posts: 20
    edited 2009-05-22 22:57
    I had totally overlooked that comment, but... I just tried it and I think it worked [noparse]:)[/noparse]))
    I made a script to first light the LED to check against brownout, then it moves the servo to a certain position, flashes the LED again to indicate thats done then fires the gun. And the servos don't move anywhere. That's great... I'm gonna program it some more tonight and include the script for the PING rangefinder and such, but it looks like we've solved the problem. Thank you so much everyone, especially you W9GFO
Sign In or Register to comment.