OEM BS2SX My program crashes and stops abruptly.
beazleybub
Posts: 102
Hello everybody,
I am having trouble with a project I am working on using the BS2SX and hope someone will please check over my code and let me know if I am doing anything wrong. When I run the following code I get erratic results.
What is happening is my program stops in progress and dosent complete or dosent work all together and sometimes it does seem to work. Have I used the wrong commands? Thank you!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Post Edited (beazleybub) : 4/6/2008 2:34:34 AM GMT
I am having trouble with a project I am working on using the BS2SX and hope someone will please check over my code and let me know if I am doing anything wrong. When I run the following code I get erratic results.
'{$STAMP BS2sx} '{$PBASIC 2.5} relay3 VAR Byte 'Varables relay5 VAR Byte relay10 VAR Byte main: IF (IN15 = 1) AND (IN7 = 1) THEN FOR relay3 = 1 TO 3 HIGH 1 PAUSE 25 HIGH 2 PAUSE 25 LOW 1 PAUSE 25 LOW 2 PAUSE 25 HIGH 5 PAUSE 25 LOW 5 PAUSE 25 NEXT ELSEIF (IN14 = 1) AND (IN7 = 1) THEN FOR relay5 = 1 TO 5 HIGH 1 PAUSE 25 HIGH 2 PAUSE 25 LOW 1 PAUSE 25 LOW 2 PAUSE 25 HIGH 5 PAUSE 25 LOW 5 PAUSE 25 NEXT ELSEIF (IN13 = 1) AND (IN7 = 1) THEN FOR relay10 = 1 TO 10 HIGH 1 PAUSE 25 HIGH 2 PAUSE 25 LOW 1 PAUSE 25 LOW 2 PAUSE 25 HIGH 5 PAUSE 25 LOW 5 PAUSE 25 NEXT ENDIF GOTO main
What is happening is my program stops in progress and dosent complete or dosent work all together and sometimes it does seem to work. Have I used the wrong commands? Thank you!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Post Edited (beazleybub) : 4/6/2008 2:34:34 AM GMT
Comments
First of all, if IN7 isn't held high, nothing happens.
Second of all, driving three relays takes quite a bit of current (depending on the relays) which tends to lead to 'brown-out' resets if your battery/supply isn't up to it.
Oh, and you DO have "protection diodes" installed across your relays, right?· Because when you 'release' a relay, the collapsing magnetic field generates a current pulse.· And that current pulse needs somewhere·to go (like through a protection diode) so it doesn't go through your I/O pins.
Thank you for your quick reply!
Yes I am driving "two" relays but I am using NPN trasnsistors to do the heavywork and I do have protection diodes in place. I fully understand that a spike will eventually kill any stamp. [noparse]:)[/noparse]
I do not think a brownout condition exists because if I use this code the relays run perfectly.
When you say "First of all, if IN7 isn't held high, nothing happens." Do you mean that it has to be held down?
IN7 is a momentary pushbutton and the rest of the inputs are connected to a 8 position dip switch. I am using 220 Ohm and 4.7K Ohm resistors for the pullup pulldown. IN7 also uses them.
From what I gather your saying my code is right? (Though I should use a DO LOOP)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Thank you for your time. [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
DO
value=IND
LOOP UNTIL IN12>0··· 'IN12 assigned to PB
Now you only need one sub routine for the relays passing it a counter value. Using SELECT-CASE you can look at the variable "value" , if value=3 then you have dip switch set to P13 and the pushbutton has been pressed so set the counter to 10 counts, if value=5 then you have dip switch set to P14 and the pushbutton has been pressed so set the counter to·5 counts and finally if value=9 then you have dip switch set to P15 and the pushbutton has been pressed so set the counter to·2 counts.
the sub routine would be something like .......FOR relay_count=1·TO counter
Jeff T.
That sounds great but I have already manufactured my PCBs and there is no way for me to relocate P7
Is there anyway to do this still using P7?
P8 through P15 Are dedicated to the 8 position dip switch and P7 is dedicated to the push button.
Can you explain to me why my code does not work? Is it because P7 is not held down?
I'm in a bit of a pickle here arent I ?!
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
DO
value=IND
value=value & 14
LOOP UNTIL IN7>0
the bitwise and (&) will mask out the lowest bit reading only the three higher bits which will give values of 2=dip P13, 4=dip P14 and 8=dip P15.
when the PB is pressed the do loop will exit with one of those three values (of course if the dip switch is not set the value will be zero)
BTW do you have pull down resistors on your switches.
Jeff T
Yes I do have pull down resistors on my switches.
I used 220 and 4.7K Ohm resistors and have them set like the example in the "what's a microcontroller book on page 77"
Thanks, Robert
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Post Edited (beazleybub) : 4/6/2008 2:36:33 AM GMT
What IS the purpose of In7? Do you press the button once, then the program loops forever? Is the program supposed to loop once, then wait until somebody presses the button again?
The point is, there's a coding solution for both situations, but I can't tell from your current code what behavior you want from pressing the button.
The dip switch configuration would determine which part of the code would be executed.
Then the program would be ready to run again whenever PB in7 is pressed again.
Thanks guys!
I have to go to work now, I will check back with you later.
Thank you VAR WORD
FOR Thank you = 1 TO 1000
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Post Edited (beazleybub) : 4/4/2008 7:21:40 PM GMT
' {$PBASIC 2.5}
ButtonState VAR Bit
ButtonState = 0
MAIN:
' The next piece waits for the IN7 button to be
' pressed -- forever if necessary...
DO WHILE ButtonState = 0
· ButtonState = IN7
· PAUSE 100
LOOP
' When here, we KNOW the In7 button has been pressed...
IF ButtonState = 1 THEN
'...
ENDIF
'...
'...
'...
' This is at the end -- where we want to make sure
' the button has been released.
DO WHILE ButtonState = 1
· ButtonState = In7
· PAUSE 100
LOOP
GOTO MAIN
I will take what both of you have shown me and learn from it.
Possibly one day I too will lend a helping hand to those who need it.
Robert
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Thank you again for your guideance.
Here is what I did with your example..
It works except when I add this for a status LED..
HIGH 5
Pause 250
LOW 5
Pause 250
The relays slow down. Is it because of overhead?
Second I am kinda unsure how to approach adding ELSIF statements to this so I can add other dip switch configurations. Ultimately I am looking to have this program count 3, 5, 10, 25, 50 relay counts depending on what the dip switch is set to.
Thanks again!
Robert
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Post Edited (beazleybub) : 4/5/2008 3:33:13 PM GMT
HIGH 1
PAUSE 250
LOW 1
PAUSE 250
HIGH 2
PAUSE 250
LOW 2
PAUSE 250
HIGH 5
PAUSE 250 (here)
LOW 5
PAUSE 250 (and here)
NEXT
ENDIF
Try this...
HIGH 1
HIGH 5
PAUSE 250
LOW 1
LOW 5
PAUSE 250
HIGH 2
HIGH 5
PAUSE 250
LOW 2
LOW 5
PAUSE 250
NEXT
ENDIF
To match the number of counts to the dip switch I would try a variable in the for-next loop.· In the last code you posted,· for example,· use
LastRelay· var byte
If IN15=1 then LastRelay=10
For RelayCount=1 to LastRelay
· (insert counting routine)
Next
My board runs great and exactly the way I envisioned it!
Thank you so much for your time... Robert
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!