Howdy and noob question from a new propeller user
kennabau
Posts: 2
I picked up my 1st prop a few weeks ago to try and introduce myself to microcontroller programming...so far I've had good luck doing many of the tutorials i've found.
So, I got brave and started trying to build my own circuits and spin code to help run the christmas village train set...
I got the crossing signal to work - it starts when a train crosses a point in the tunnel, then stays with the two alternating leds until the last car clears the crossing.· So far so good.
Then I attempted to build some logic to throw the switches - I need about· a 1/4 second pulse to a relay to feed the 16vAC through·a relay (with a 5v coil) and depending on which way I want the switch to throw, I feed the AC from the 1st relay through either the NO or NC branch of a second relay.· It works good with a quick press of my test button.·
But here's my problem:· I want a 1/4 second·output on pin 3 when ever pin 24·is pulled down (·I have a pull up resistor on the input pin, and I do have the coil·diodes on my relays·)· My problem is that pin 3 stays high as long as pin 24 is pulled down.· To see this more clearly, I changed my output to 5 seconds, and here's what I got:
1 second press, 5 second output
6 second press, 6 second output
I'm guessing I'm missing some fundamental part of this, but I'm pulling my hair out trying to figure it out...· Any pointers would be greatly appreciated!
Here is my current spincode (I tried several variations, but this is what I currently have...)
Pub LoopTunnelSwitch
· dira[noparse][[/noparse]Loop_Switch_Pin] ~~····························· 'set the pin to output
· dira[noparse][[/noparse]3] ~~·················································· '3 is the source voltage relay control pin
· repeat
··· waitpeq (|<24,|<24,0)································ 'wait until pin 24 goes low
···· outa[noparse][[/noparse]Loop_Switch_Pin]~~···························· 'pull coil on source ac relay
····· outa[noparse][[/noparse]3]~~················································'pull coil on switch relay
····· waitcnt (clkfreq / 1000 *DelayMS + cnt)··········· ' hold coil for DelayMS
····· outa[noparse][[/noparse]3]~
····· outa[noparse][[/noparse]Loop_Switch_Pin]~····························· 'release coil
Kennabau.
So, I got brave and started trying to build my own circuits and spin code to help run the christmas village train set...
I got the crossing signal to work - it starts when a train crosses a point in the tunnel, then stays with the two alternating leds until the last car clears the crossing.· So far so good.
Then I attempted to build some logic to throw the switches - I need about· a 1/4 second pulse to a relay to feed the 16vAC through·a relay (with a 5v coil) and depending on which way I want the switch to throw, I feed the AC from the 1st relay through either the NO or NC branch of a second relay.· It works good with a quick press of my test button.·
But here's my problem:· I want a 1/4 second·output on pin 3 when ever pin 24·is pulled down (·I have a pull up resistor on the input pin, and I do have the coil·diodes on my relays·)· My problem is that pin 3 stays high as long as pin 24 is pulled down.· To see this more clearly, I changed my output to 5 seconds, and here's what I got:
1 second press, 5 second output
6 second press, 6 second output
I'm guessing I'm missing some fundamental part of this, but I'm pulling my hair out trying to figure it out...· Any pointers would be greatly appreciated!
Here is my current spincode (I tried several variations, but this is what I currently have...)
Pub LoopTunnelSwitch
· dira[noparse][[/noparse]Loop_Switch_Pin] ~~····························· 'set the pin to output
· dira[noparse][[/noparse]3] ~~·················································· '3 is the source voltage relay control pin
· repeat
··· waitpeq (|<24,|<24,0)································ 'wait until pin 24 goes low
···· outa[noparse][[/noparse]Loop_Switch_Pin]~~···························· 'pull coil on source ac relay
····· outa[noparse][[/noparse]3]~~················································'pull coil on switch relay
····· waitcnt (clkfreq / 1000 *DelayMS + cnt)··········· ' hold coil for DelayMS
····· outa[noparse][[/noparse]3]~
····· outa[noparse][[/noparse]Loop_Switch_Pin]~····························· 'release coil
Kennabau.
Comments
An example:
Also, it isn't clear that you have set p24 as input.
Post Edited (TChapman) : 12/11/2008 6:57:50 AM GMT
you need to detect the low-high-TRANSITION of the switch
and store this event in a variable
best regards
Stefan
I tried both solutions (I actually had Stefan's, I was just missing checking that the bit was still set in the last if statement.· )
They both almost do what I want, but sometimes I get a second activation of the relay when I release the button, and sometimes I don't.· I'm using a 10k pull-up resistor to keep pin 24 high until the switch press pulls it to ground...
I'm gonna keep playing with it - especially since I'm going to try to bounce an IR led off the bottom of the train for a sensor and I haven't even started that part yet...· now that I have an idea about which way I should go with the code, I'm gonna tackle the IR and come back to the switch.
So, I changed the last if (the re-arm-if) to this:
(I took out the two if statements at the end completely)
Since the train won't be in a position to trip the switch in the tunnel for well more than the 10 seconds, it works.· And it's much more stable - no flipping on the release of the switch.
Thanks again!
Kennabau.
Post Edited (kennabau) : 12/12/2008 4:17:52 AM GMT
It is great to hear that you are making progress and having fun. You are making me miss my train layout.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com
I too am a neophyte when it comes to the Propeller, though I've had more than a few years (and no, I'm not sharing that number) under my belt with uControllers and before that lots of linear stuff in the Navy. As Timothy replied above you need switch debouncing. You can go about this in one of two ways. You can use a software method for switch debouncing which requires you poll the switch at a specific interval and save the last switch state - not too complex but not something you want to have to sprinkle around either. Another alternative is to use a debouncing circuit. It just takes an IC *7414 or equivalent*, a resistor and a cap. You basically make an RC filter with a schmitt trigger (if you are going pure analog you can lose the schmitt trigger unless you need a nice crisp transition).
Here is a circuit diagram to get you started:
From one noob to another, HTH.