BS2 help with program
Hello,
I can't determine why this program doesn't work the way I'm thinking it should. I need to turn on four relays with a 15 second delay in between each turn on. I've also got it set up where you need to push a button to start the program. It appears that the BS2 "times out" or resets before all relays light. Is this something into the BS2?
'What's a Microcontroller - International Power delayed Relay Switching.bs2
'Activate circuit with reset switch, timed delay of four relays then hold them in on state
'till reset or power is switched off.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Delayed turn on of four relays after pressing start button!"
DO
DEBUG ? IN3
IF (IN3 = 1) THEN
GOTO Routine1
Routine1:
DEBUG "Wait 1 second to turn on R1"
PAUSE 1000
DEBUG "Turn on R1"
HIGH 14
DEBUG "Wait 15 Seconds to turn on R2"
PAUSE 15000
DEBUG "Turn on R2"
HIGH 13
DEBUG "Wait 15 Seconds to turn on R3"
PAUSE 15000
DEBUG "Turn on R3"
HIGH 12
DEBUG "Wait 15 Second to turn on R4"
PAUSE 15000
DEBUG "Turn on R4"
HIGH 11
ELSE
PAUSE 100
ENDIF
LOOP
STOP
Thanks!
John
I can't determine why this program doesn't work the way I'm thinking it should. I need to turn on four relays with a 15 second delay in between each turn on. I've also got it set up where you need to push a button to start the program. It appears that the BS2 "times out" or resets before all relays light. Is this something into the BS2?
'What's a Microcontroller - International Power delayed Relay Switching.bs2
'Activate circuit with reset switch, timed delay of four relays then hold them in on state
'till reset or power is switched off.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Delayed turn on of four relays after pressing start button!"
DO
DEBUG ? IN3
IF (IN3 = 1) THEN
GOTO Routine1
Routine1:
DEBUG "Wait 1 second to turn on R1"
PAUSE 1000
DEBUG "Turn on R1"
HIGH 14
DEBUG "Wait 15 Seconds to turn on R2"
PAUSE 15000
DEBUG "Turn on R2"
HIGH 13
DEBUG "Wait 15 Seconds to turn on R3"
PAUSE 15000
DEBUG "Turn on R3"
HIGH 12
DEBUG "Wait 15 Second to turn on R4"
PAUSE 15000
DEBUG "Turn on R4"
HIGH 11
ELSE
PAUSE 100
ENDIF
LOOP
STOP
Thanks!
John
Comments
A quick check with a volt meter on your supply will check this. It's possible your relay coils are pulling enough to overload the supply, or overload the Stamp bus.
You could also temporarily replace each relay with a 1k resistor in series with an LED, just to iron out your problems. Then connect the relays one by one to see what happens?
Also, make your program super simple just to lay a foundation, no buttons, no loops, just cut and dry code. I do this A LOT when I'm having problems. For example:
Relay #1 ON
pause 15000
Relay #2 ON
pause 15000
Relay #3 ON
pause 15000
Relay #4 ON
pause 15000
end program
Thanks for the feedback. I am using a diode across the relay to prevent kickback.
I've reduced the code to this and am still having problems. I've gone down to a simple 470 ohm resistor and an LED on P15 thru P12. LED P15 turns on, LED P14 turns on, LED P13 flashes but doesn't stay on, P12 never comes on. I believe this is a "time-out" or name reset problem caused by a USB communication error. I am uncertain how to get around this? Any help would be greatly appreciated.
Thanks!
' {$STAMP BS2}
' {$PBASIC 2.5}
HIGH 15
PAUSE 1500
HIGH 14
PAUSE 1500
HIGH 13
PAUSE 1500
HIGH 12
PAUSE 1500
HIGH 11
PAUSE 1500
END
I changed the END command to a STOP command...no help?
I wouldn't suspect a communications problem because once you burn the program, you can unhook the com cable and the Stamp run independently.
Ah, you know what? Put this command before the code:
DIRH %11111111
That will make all the pins outputs.... I bet that's it. DUH! [noparse]:)[/noparse]
Makes sense, once I RUN/download the program USB is out of the picture.
' {$STAMP BS2}
' {$PBASIC 2.5}
DIRH= %11111111
HIGH 15
PAUSE 1500
HIGH 14
PAUSE 1500
HIGH 13
PAUSE 1500
HIGH 12
PAUSE 1500
STOP
This probably isn't valid code but you should get the idea.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
DO
HIGH 15
PAUSE 1500
LOW 15
HIGH 14
PAUSE 1500
LOW 14
HIGH 13
PAUSE 1500
LOW 13
HIGH 12
PAUSE 1500
LOW 12
LOOP
STOP
This program does not run correctly: I get a reset after the the second/third LED lights. All I did was remove the LOW 15 command, why should this cause problems?
DO
HIGH 15
PAUSE 1500
HIGH 14
PAUSE 1500
LOW 14
HIGH 13
PAUSE 1500
LOW 13
HIGH 12
PAUSE 1500
LOW 12
LOOP
STOP
I'm not running any relays at this time. Just 470 Ohm resistors in series with each LED on outputs P15-P12. Should be no problem with current.
I plan to use a TIP transistor to drive each relay.
Something else connected to your Stamp?
Post Edited (Moskog) : 2/12/2010 5:58:33 PM GMT
This is why people use the 7805, and 4 AA cells (or a wall-wart) to get around current limitations.
Oh, and the classic check for this is to put:
SEROUT 16, 16468, [noparse][[/noparse]"Reset!",CR]
at the start of your program, then monitor the debug terminal window on the IDE for "Reset!" messages.
so what ARE you using as a power supply? I asked early on: Did you check the supply with a voltmeter while the circuit was on?
I'm guessing bad solder joints/poor connection with your protoboard or poor supply
Post Edited (Spiral_72) : 2/12/2010 7:54:10 PM GMT
I'm using a plug in 1 amp 9 volt wall transformer plugged in the 6-9 volt DC circular jack.
Can the BS2 source or sink 4 LED's at one time?
Could the BS2 be sending a "timeout" about every two seconds?
HIGH 15
'HIGH 14
'HIGH 13
'HIGH 12
STOP
When I run this program the first and second LED's start blinking:
HIGH 15
HIGH 14
'HIGH 13
'HIGH 12
STOP
When I run this program the first, second, and third LED's are blinking even faster:
HIGH 15
HIGH 14
HIGH 13
'HIGH 12
STOP
Every time I allow another LED to come on the blink rate goes up!
You could try tying the reset pin to +5V Vcc through a 10k resistor (which is a good idea anyways, for all your stamp projects)
You could try unplugging the stamp programming cable after you've sent you program. I can't imagine this helping, but it's worth a shot.
You need to tell us the supply voltage with the stamp powered up and the program running. Also if you have a scope, I'd be interested to see how close to DC the power supply is ESPECIALLY if the wall-wart is intended to be a battery charger. You might be able to check this by measuring the supply with your voltmeter on the AC setting. The closer to DC the level is, the less AC voltage there will be (closer to 0VAC). Also the power supply could be defective.
And yes the stamp should have no problems sourcing four LED's at 5mA each.
That's all I have. Good luck.
Post Edited (Spiral_72) : 2/12/2010 9:07:14 PM GMT
What have you plugged the BS2 into? Is it a BOE (Board Of Education)?
If you're using the on-BS2 regulator module, driving more than one LED is a bad idea -- unless they are "low-current" LED's.
DO
HIGH 15
'HIGH 14
'HIGH 13
'HIGH 12
LOOP
If·LEDs still blinking then you are having a current·overflow problem
Also try a 2.2k resister and see if makes any different
If you are still having this problems I·do not know what else it could be
I hope this helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Right on with the current overflow problem. I bumped up the resistor values and wala, no more blinking LED's. I did notice the Board of Education on-board regulator was running hot.
Thanks everyone! It's great to be able to find help when your in a pickle!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Use Ohm's law: V=I*R
Where V is voltage in VOLTS, I is current in AMPS, R is resistance in OHMS
I use 5ma to drive the standard sized LED's I have. Yes it's dim, but still easy to see. I bought some small 3mm green ones that are very bright at 3mA.
So if you are running them off Vcc (5V) bus voltage you use V/I=R or 5V / 0.005A = R or 1k ohm
10mA would be 5V / 0.010A = 500 ohm
Most standard 6mm size LED's have a max current of 20 or 30mA. The small ones are 10mA, 15mA maybe even 5mA so you'll need to take that into account too.
And that's it! Make sure you don't exceed the maximum bus current listed in the manual. I thought it was 80mA, but others have said only 40mA.... You'll have to look it up (and I do too)
"MY" rule of thumb is never exceed 5mA off a pin and I try to keep it under that. More than 5mA and I use a transistor or small relay.
Post Edited (Spiral_72) : 2/16/2010 3:38:38 PM GMT