Shop OBEX P1 Docs P2 Docs Learn Events
First Project — Parallax Forums

First Project

velogirlvelogirl Posts: 5
edited 2006-06-09 15:45 in BASIC Stamp
Hello all,

*disclaimer* newbie here

after receiving my basic stamp kit i proceded to make an led blink. yippie.

i am a feeling confident and a bit adventurous now and decided on my first non-tutorial project...and generally·i get it to work but·i don't have the precision I'd like.

here is the overall idea:

i·want to get a·motor to shoot (its the innards of a electric trigger BB gun, don't ask) and I'd like it to shoot Morse Code through keyboard input.·so in essence, i type in a letter and the software sends the pulses in order to "shoot" the letter as it would be in morse code in the bb gun.

the motor needs 7 volts to trigger

Since the board regulates·the pins to 5 volts and the i/o are only 20 ma,·i decided to replace the switch with a relay, and control it via 2 adjustable resistors. the battery pack is still connected to the motor.

see picture for details

my issue is this:

for some reason i am not getting a precise pulse. sometimes the motor has one revolution, sometimes two or three or seven...never a pattern. I want to be able to control it to one revolution per pulse in order to define the letters in the code.

any suggestions??? maybe there is a simpler solution and i am just overthinking the problem???

attached are a picture of the circuit and the code i have at this point...i appreciate any help or suggestions.

thanks a million!!!!
1152 x 768 - 99K

Comments

  • HarborHarbor Posts: 73
    edited 2006-06-08 02:51
    Well, I assume that's a 12V reed relay in the picture, Velogirl, and that you're providing 7.2 volts or something like that to the firing circuit. You could fiddle with the pulse width and see if that works, but I'm guessing the problem is inherent in the trigger device. I've never seen an electric BB gun so I can't be sure.

    Basically, we'd like it to be one-shot-and-done until a recovery time passes, and it certainly sounds like the opposite is happening. That it fires, recovers, fires, recovers, for as long as the pulse is seen.

    Let me suggest you try a very short pulse first. Very short as mechanical things go. Say, 1 millisecond. I'm pretty sure that reed relay will respond that fast. If you still get multiple shots on some pulses, we'll see if the reed relay needs debouncing. Actually I should have mentioned that first, though mechanical devices rarely respond fast enough for that to be an issue.

    Do you have any material that tells you how to debounce a switch signal? I'll look up a reference if you don't.
  • velogirlvelogirl Posts: 5
    edited 2006-06-08 03:15
    thanks for the quick response Harbor!!!

    Actually its a 5v relay, the problem is its rather erratic in its throughput.
    for ex:·I hit the letter and the motor turns once, as it is supposed to.
    so i·hit it again (and pray)·and maybe it shoots twice.
    again: 3 times

    i could adjust it in the code if it·were always shooting 1, 2, 3, but then sometime it just goes crazy and shoots 7 times or 5 or 1/2 a revoluotion. I am really not getting any consistency.

    I have tweaked milliseconds on the·HIGH/LOW·and tweaked the resistors to get the most accurate 1 shot possible but even then it is a Smile shoot...i do not feel i am getting enough control or predictablity
    I am thinking maybe the relay is not fast enough, precise enough...

    debounce a switch signal...um...no clue what that is...i just started working with electronics a few weeks ago so this is all new to me...if you think it might help i would greatly appreciate it.

    thanks!!!
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-08 03:57
  • velogirlvelogirl Posts: 5
    edited 2006-06-08 04:14
    doesn't really solve the problem of the erratic pulsing...

    even though it seems a bit more precise

    thx many appreciations
  • HarborHarbor Posts: 73
    edited 2006-06-08 04:59
    Actually, my mind went foggy for a minute there. I did not mean a 12V relay because that refers to the voltage you must apply to cause the coil to close the relay. A 5V relay is the right choice. What I was confirming is that you are applying at least 7 volts to the trigger circuit using this reed relay to turn that current on and off.

    Looking at your picture, we don't see how the few milliseconds of bounce in a reed relay can affect what looks like an electric motor. (By 'we' I don't mean Parallax. I mean my brother-in-law and I talking about your project on the phone.) We think the first thing is to figure out what that device needs. What it takes to make it happy. We need to 'characterize' the device we're trying to control.

    Put it another way: Don't try to program something until you can do it yourself. Or since we don't personally make good sources of electrons, don't wire it until we can describe very well what is supposed to happen. And until we can 'pull the trigger' by hand and get the result we expect.

    Let me suggest a way to figure out just what this widget is doing. Personally, I've never seen an electric BB gun, so you may already know more than I do. If you have a desktop power supply (which most people do not), set it for 7.5 V. Failing that, put together four D-cells or even C-cells to have a generous source of 6V. You can buy plastic battery cases at Radio Shack that let you put together groups of cells like that. (Get a "normally open" push button switch while you're there unless you already have one.) If it looks like 6V isn't working, we can always add an extra cell in series to reach 7.5V. It looks like you're using variable resistors to step down the power from the 9V cell in that picture, but a simple 9V battery can't source much current and might be doing all sorts of strange things. Well, just one really. We call it 'sag'.·So let's get a big sturdy pile of akaline batteries driving this thing and that removes one source of confusion. Or an adjustable·power supply if you·have one.

    Now put a pushbutton switch in the circuit. Hmmm. One more question. Are those just two wires connecting your reed relay to the BB motor? I'll assume so for now. If so, instead of a Stamp with all that rest of the stuff, let's try to "fire the gun" with a direct push of a switch. And see how many times it 'fires.' If you still have a BB reservoir, be sure this experiment is set up carefully so as not to hurt any innocent pets in the area. (Or even yourself. We geeks have use for both eyes.<g>)

    It seems to us that the impulse motor for a BB gun should fire exactly once every time the trigger is pulled. And unless they had a circuit board in the gun, closing a push button switch, even with mechanical bounce issues, should only cause it to fire once until you release the switch, let it recover briefly and close the circuit again. Let's try that and see.

    Once you get a feel for what happens when you manually depress a switch, we can put together a circuit to do it under the stamp's control. Then we'll have to deal with the keyboard input issues you mentioned but we haven't discussed. But that's a discussion for another day. First let's figure out what the guts of an electric BB gun want to do when left to themselves. Will it only fire once? Or several times when you push a simple switch by hand?

    Good luck and get back to us.

  • RinksCustomsRinksCustoms Posts: 531
    edited 2006-06-08 05:41
    Looking at your source code I noticed that your using the "HIGH, PAUSE, LOW" routine, this may be a simple to understand solution to your project, but there is a more precice way of controlling the output. Assuming you have a copy of "What's a Microcontroller" book, look in it for a comand called PULSOUT.

    Demo Program (PULSOUT.bs2)
    ' PULSOUT.bs2
    ' This program blinks an LED on for 25 ms at 1-second intervals. Connect an
    ' LED (active-low) to I/O pin 0.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    #SELECT $STAMP
    #CASE BS2, BS2E, BS2PE
    Scale CON 500 ' to ms for 2 us per unit
    #CASE BS2SX, BS2P, BS2PX
    Scale CON 1250 ' to ms for 0.8 us per unit
    #ENDSELECT
    Flash CON 25 * Scale ' 25 milliseconds
    Setup:
    HIGH 0 ' make P0 high (LED off)
    Main:
    PULSOUT 0, Flash ' flash LED
    PAUSE 1000 ' one second delay
    GOTO Main
    END
    NOTE: This example program can be
    used with all BS2 models. This program
    uses conditional compilation techniques;
    see Chapter 3 for more information.


    hope this helps, it's from the syntax and language reference manual available for free download: http://www.parallax.com/html_pages/downloads/basicstamps/documentation_basic_stamp.asp

    I am very expierienced with electronics and am avg @ coding with a BS2. I'll have to agree with HARBOR, I believe your problem lies with that trigger mechanism. I'm not sure exactly how your mechanism works, but I would recomend a solenoid. I would also suggest replacing the reed relay you have there with a MOSFET transistor. The Electronics Engineer mini handbook or a searh on "MOSFET project circuits" at http://www.discovercircuits.com/index.htm. I believe www.mouser.com, or www.digikey.com can provide you with a solenoid and 1000 times more electronis parts than Radio Shack can. If you really like doing DIY, I can guide you on making your own solenoid. It's a basic electronic device that has been around since the turn of the century. I'ts uses a coil of wire wraped round a tube that pulls or pushes a steel inner shaft with magnetism when you apply voltage to the coil.

    In any case, hope this was helpful to you and anyone else that comes across this.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-06-08 05:45
    Folks -

    PRESUMPTION ALERT!

    It's probably not a valid idea to presume that this automatic electric gun (AEG) is only single-shot, or that the default mode is single-shot, when single-shot, semi-automatic, and automatic fire are all possible. Here is a brief description from an AEG provider, which may be of some marginal interest:

    "Basically, an AEG is powered by an on-board battery (similar to hobby R/C Cars), which operates a motor that turns gears inside the gun to compress and release a piston, which in turn creates the blast of air needed to propel the 6mm BB through the barrel of the gun. This system allows the gun to efficiently generate the power needed to support the fully-automatic features of most AEGs and the result is a realistic Rate-Of-Fire (ROF) of anywhere from 600 - 900 Rounds-Per-Minute (RPM), once again mimicking the capabilities of real steel firearms."

    So, the "trigger pull" duration may be highly important, and also examining the weapon for any sort of mode switch which might provide different rates of fire: "man", "semi", "auto" or something like that.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->

    Post Edited (Bruce Bates) : 6/8/2006 5:54:41 AM GMT
  • stamptrolstamptrol Posts: 1,731
    edited 2006-06-08 11:49
    Velogirl,

    Two quick thoughts:

    1. looking at your pic, I only see the motor leads going into the firing mechanism. That leads me to believe there is no way of knowing the postion of the motor and geartrain to ensure you are always starting in the same position. Its usual in things like this to have a limit switch which tells the controller when it is "home"......sort of like the windshield wipers on a car....they always park in the same position regardless of where in the cycle you turn the switch off.
    All of that to say you might have better repeatability if the system could always know that the motor was starting in the same place each time.

    2. do you have a diode on the coil of the reed relay to control the inductive kick when the reed relay switches off? Any spurious spikes could be getting into the stamp and causing unwanted resets.

    Cheers
  • velogirlvelogirl Posts: 5
    edited 2006-06-08 12:46
    Thanks all for your wonderful input,

    lots of food for thought.

    Just a few more clarifications:
    The battery pack, powering the gun is 7.2 volt and gets charged with a 250 ma adapter.

    The switch it replaced was a regular on/off toggle switch which allowed for automatic firing.
    pulling·the·trigger once = one shot.
    keeping the trigger squeezed = automatic firing.

    I had tried pulsout,·& it was·even more erratic...but will try it again.

    Transistors:
    I rigged up a working circuit based on a PNP transistor, but since all i/o pins are regulated to 20 ma and I couldn't use the powerpack in conjunction, I·had not enough current to move the motor.
    (I used VIN instead of VDD to get an increase in voltage)·maybe there is some more possibilities·in that way of thinking...

    I'll work on getting it to shoot with a pushbutton...

    Thanks again!!!

    v
  • bennettdanbennettdan Posts: 614
    edited 2006-06-09 00:48
    velogirl,
    Can you tell us if the bb gun had any other electronics to make it work other than·just a switch. Also you might try to use a mosfet like a IR510 from radioshack and the PWM comand to slow the motor down and make it more prdictable unless it wont fire the bb at a lower speed atleast the mosfet will trigger quicker than the relay.

    Post Edited (bennettdan) : 6/9/2006 1:05:37 AM GMT
  • velogirlvelogirl Posts: 5
    edited 2006-06-09 14:02
    thanks bennettdan,

    this specific bb gun had no other electronic parts except a toggle switch.


    good to know that the mosfet will tigger faster than the relay...will give it a try as well as the PWM command.

    thanks again!
  • bennettdanbennettdan Posts: 614
    edited 2006-06-09 15:45
    If the gun only had a switch then the relay should be fast enough to set only one trigger pull but could not be unlaching at the same rate the mosfet might be a better switch for you.
Sign In or Register to comment.