PDA

View Full Version : programming question for the BS2



firealarmfreak
08-27-2008, 02:57 AM
Hey I am making a fire alarm panel that pulses alarms. It also has a continuous option. Basicly Its programmed so i can use a button to set it to different signal codes so when I pull it, it either goes on and off or goes continuously.

But for some reason when I use continuous it automatyicy goes to silence. and the silence led is lit like it should be when it goes to silence, but it is not supposed to go to silence unless a button is pressed, but it automaticly goes to silence. I find that if i pulse the alarm led, and dont pulse the alarms, it works for longer before automaticly going to silence, but it still does. Sometimes It even goes to normal and the stamp resets. Is there a reson for this? I already tried puting them in a list instead of using high 8 : high 9, but that didnt help any. Any ideas?

Here is my Alarm routine (the source code for the alarm part)

When I remove the "IF (IN4 = 1) THEN GOTO Silence" and the "IF (IN5 = 1) THEN GOTO Normal", it worked perfectly but obviusly i couldnt turn off the alarm. By the way, all the other codes: March Time, Code 3 and Pulse, all work perfectly, its only continuous that is messed.

AlarmA: 'Continuous
DO
HIGH 8 : HIGH 9 : HIGH 0 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 225
LOW 0
PAUSE 225
LOOP

AlarmB: 'March Time
'HIGH 8 : HIGH 9 : HIGH 0 : PAUSE 100 : LOW 8 : LOW 9 : LOW 0 : PAUSE 2500 'Pre Alarm
DO
HIGH 8 : HIGH 9 : HIGH 0 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 225 : LOW 8 : LOW 0 : PAUSE 225
LOOP

AlarmC: 'Code 3
'HIGH 8 : HIGH 9 : HIGH 0 : PAUSE 100 : LOW 8 : LOW 9 : LOW 0 : PAUSE 2500 'Pre Alarm
DO
HIGH 8 : HIGH 90 : HIGH 0 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 500 : LOW 8 : LOW 0
PAUSE 500 : HIGH 8 : HIGH 0
PAUSE 500 : LOW 8 : LOW 0
PAUSE 500 : HIGH 8 : HIGH 0
PAUSE 500 : LOW 8 : LOW 0 : PAUSE 1400
LOOP

AlarmD: 'Pulse
'HIGH 0 : HIGH 8 : HIGH 9 : PAUSE 100 : LOW 8 : LOW 9 : LOW 0 : PAUSE 2500 'Pre Alarm
DO
HIGH 0 : HIGH 8 : HIGH 9 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 500 : LOW 0 : LOW 8 : LOW 9 : LOW 13 : PAUSE 500
LOOP

Thanks.

Chris.

Unsoundcode
08-27-2008, 03:42 AM
Hi Chris, do you have pull down resistors on·IN4 and IN5. If you dont have a resistor pulling the pin low the voltage could float either high or low giving you a false trigger.

Jeff T.

firealarmfreak
08-27-2008, 04:39 AM
Yes I do have a pull down resister, and it does not givefalse triggers on any other signal codes except for continuous..
Any other ideas?

Chris.

Franklin
08-27-2008, 07:35 AM
Try putting the pre alarm in your continous code like the others.

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

firealarmfreak
08-27-2008, 07:49 AM
Actually i took out pre alarm in the others as i had a ' beside it.

I will try puting pre alarm in to see if that helps, thanks.

Someone on youtube that also made a panel (i got the idea to make a panel with basic stamp cause of him). He said he had the same issue as me and all he did was erased the continuous one and retyped it in, but that did not work for me. He said its a basic stamp bug. Is that a possibility? that the problem is a bug in the basic stamp?

Chris.

stamptrol
08-27-2008, 08:09 AM
Chris,

The chance that its a Stamp bug are somewhere between slim and none.

Assuming your pull-downs are there (check with a meter when the button is not pressed), it has to be something thats happening in your program. Also, is the stamp being powered by the same source as the alarm?

Like somewhere pin 4 is getting set high by mistake, for instance.

Post the whole code and the schematic and I bet someone will see it.

Cheers,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk

http://www.siskconsult.com
·

firealarmfreak
08-27-2008, 08:21 AM
Here is the entire code for my panel.

Sorry about some of the messy text Example, the I/O DEFFINTIONS on my code are actually formated like: AlarmLED PIN 1 'Alarm LED on pin 1 (it didn't format correctly after i took it off the basic stamp windows editor). But it is formated correctly on the basic stamp editor.

Any ideas on my problem?

' {$STAMP BS2}
' {$PBASIC 2.5}

'--------------------------------------'
'FIRE-PRO 3002 FIRE ALARM CONTROL PANEL'
'--------------------------------------'

'Most of this code was written by Chris
'All other parts were written by Parallax Inc.
'The idea of using Basic Stamp for a panel was from "NewAgeServer" on youtube

'This is a 2 zone control panel
'It includes supervisory for each zone
'It also includes 4 selectable signal codes: Continuous, March Time, Code 3 and Pulse

'This control panel is incompatible with BS1
'I have only tested this code on BS2
'This code was written using PBASIC 2.5
'------------------------------------------

'-----------------------------------------------------I/O DEFINITIONS---------------------------------------------------------------------'
AlarmLED PIN 0 'Indicates panel is in alarm or WalkTest
Zones1 PIN 2 'Zone 1 Pull Stations
Zones2 PIN 3 'Zone 2 Pull Stations
Btn1 PIN 4 'Silence/StrobeMode, Sig=Cont
Btn2 PIN 5 'Reset, Walk, Sig=March
Btn3 PIN 6 'Walk, Coding, Re-Alarm, Sig=Code3
AudSigs PIN 8 'Audible Signals
Strobes PIN 9 'Strobes (visual-signal)
Btn4 PIN 10 'Test, Sig=Pulse
SilenceLED PIN 11 'Indicates the audibles are silenced
TroubleLED PIN 12 'Indicates the panel is in trouble
Buzzer PIN 13 'Indicates an alarm or trouble condition
LCD PIN 14 'LCD Display
'-----------------------------------------------------VARIABLES---------------------------------------------------------------------------'
signalcode VAR Word 'Indicates which signal code to use
zone1 VAR Word 'Indicates zone 1
zone2 VAR Word 'Indicates zone 2
'-----------------------------------------------------[[PROGRAM CODE BEGINS HERE]]--------------------------------------------------------'
'--SIGNALCODE DEFINITIONS--'
'signalcode = 1: Continuous
'signalcode = 2: MarchTime
'signalcode = 3: Code 3
'signalcode = 4: Pulse
'signalcode = 5: two-stage
'--------------------------'

'--ZONES-------------------'
'Zone 1: Main Floor (lower)
'Zone 2: Upper Floor
'--------------------------'

'----------[NORMAL]
Normal:
LOW 8 : LOW 9 : LOW 0 : LOW 1 : LOW 10 : LOW 11 : LOW 12 : LOW 13
PAUSE 300
HIGH 0 : HIGH 1 : HIGH 10 : HIGH 11 : HIGH 12 : HIGH 13
PAUSE 1000
LOW 0 : LOW 1 : LOW 10 : LOW 11 : LOW 12 : LOW 13
signalcode = 2 'Default Signal Code

'----------[BUTTONS]
Begin:
PAUSE 500
HIGH 13 : PAUSE 200 : LOW 13
DO
IF (IN4 = 1) THEN GOTO StrobeTest
IF (IN5 = 1) THEN GOTO WalkMode
IF (IN6 = 1) THEN GOTO SignalCodes

'----------[ZONES]
HIGH 2 'Zone 1
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO AlarmVerify
IF zone1 = 0 THEN GOTO Trouble1

HIGH 3 'Zone 2
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO AlarmVerify
IF zone2 = 0 THEN GOTO Trouble2
IF (IN10 = 0) THEN GOTO AlarmVerify 'Test Button
LOOP

'----------[SIGNAL CODES]
SignalCodes:
HIGH 13 : PAUSE 100 : LOW 13
HIGH 0 : HIGH 11 : HIGH 12
PAUSE 500
DO
IF (IN4 = 1) THEN signalcode = 1 : GOTO AlarmVerify
IF (IN5 = 1) THEN signalcode = 2 : GOTO AlarmVerify
IF (IN6 = 1) THEN signalcode = 3 : GOTO AlarmVerify
IF (IN10 = 0) THEN signalcode = 4 : GOTO AlarmVerify
LOOP

'----------[ALARM]
AlarmVerify:
LOW 0 : LOW 11 : LOW 12
PAUSE 1000
HIGH 2
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO Alarm
HIGH 3
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO Alarm
IF (IN10 = 0) THEN GOTO Alarm
GOTO Begin 'If no zones are in alarm, go back to normal

Alarm:
LOW 11
DO
IF signalcode = 1 THEN GOTO AlarmA
IF signalcode = 2 THEN GOTO AlarmB
IF signalcode = 3 THEN GOTO AlarmC
IF signalcode = 4 THEN GOTO AlarmD
LOOP

AlarmA:
DO
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
HIGH 8
HIGH 9
LOOP

AlarmB: 'March Time
'HIGH 8 : HIGH 9 : HIGH 0 : PAUSE 100 : LOW 8 : LOW 9 : LOW 0 : PAUSE 2500 'Pre Alarm
DO
HIGH 8 : HIGH 9 : HIGH 0 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 225 : LOW 8 : LOW 0 : PAUSE 225
LOOP

AlarmC: 'Code 3
'HIGH 8 : HIGH 9 : HIGH 0 : PAUSE 100 : LOW 8 : LOW 9 : LOW 0 : PAUSE 2500 'Pre Alarm
DO
HIGH 8 : HIGH 9 : HIGH 0 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 500 : LOW 8 : LOW 0
PAUSE 500 : HIGH 8 : HIGH 0
PAUSE 500 : LOW 8 : LOW 0
PAUSE 500 : HIGH 8 : HIGH 0
PAUSE 500 : LOW 8 : LOW 0 : PAUSE 1400
LOOP

AlarmD: 'Pulse
'HIGH 0 : HIGH 8 : HIGH 9 : PAUSE 100 : LOW 8 : LOW 9 : LOW 0 : PAUSE 2500 'Pre Alarm
DO
HIGH 0 : HIGH 8 : HIGH 9 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 500 : LOW 0 : LOW 8 : LOW 9 : LOW 13 : PAUSE 500
LOOP

ReAlarm:
LOW 11
DO
IF (IN4 = 1) THEN GOTO SilenceA
IF (IN5 = 1) THEN GOTO Normal
HIGH 0 : HIGH 8 : HIGH 9
PAUSE 225
LOW 0 : LOW 8
PAUSE 225
LOOP

'----------[SILENCE]
Silence:
LOW 8 : HIGH 11
DO
HIGH 2
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO Zone_1

HIGH 3
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO Zone_2
IF (IN5 = 1) THEN GOTO Normal
IF (IN6 = 1) THEN GOTO ReAlarm
LOOP

Zone_1:
DO
IF (IN5 = 1) THEN GOTO Normal
IF (IN6 = 1) THEN GOTO ReAlarm
HIGH 3 'Zone 1 was activated, Waits to see if zone 2 is activated, if so, goes back to the alarm routine
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO ReAlarm
LOOP

Zone_2:
DO
IF (IN5 = 1) THEN GOTO Normal
IF (IN6 = 1) THEN GOTO ReAlarm
HIGH 2 'Zone 2 was activated, Waits to see if zone 1 is activated, if so, goes back to the alarm routine
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO ReAlarm
LOOP

SilenceA:
LOW 8 : HIGH 0 : HIGH 11
DO
IF (IN5 = 1) THEN GOTO Normal
IF (IN6 = 1) THEN GOTO ReAlarm
LOOP

'----------[WALK TEST]
WalkMode:
HIGH 0
HIGH 13 : PAUSE 100 : LOW 13
PAUSE 500
DO
IF (IN5 = 1) THEN GOTO Normal
HIGH 2 'Zone 1
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO WalkTest1
HIGH 3 'Zone 2
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO WalkTest2
LOOP


WalkTest1: 'Zone 1 Walk Test
DO
LOW 0 : HIGH 8 : HIGH 9 : HIGH 13
PAUSE 225
LOW 8 : LOW 9 : LOW 13
PAUSE 1500
GOTO WalkMode

WalkTest2: 'Zone 2 Walk Test
LOW 0 : HIGH 8 : HIGH 9
PAUSE 225
LOW 8 : LOW 9
PAUSE 225
HIGH 8 : HIGH 9
PAUSE 225
LOW 8 : LOW 9
PAUSE 1500
GOTO WalkMode
LOOP

'----------[STROBE TEST]
StrobeTest:
HIGH 11
HIGH 13 : PAUSE 100 : LOW 13
DO
IF (IN5 = 1) THEN GOTO Normal
HIGH 2
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO StrobeVerify
HIGH 3
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO StrobeVerify
IF (IN10 = 0) THEN GOTO StrobeVerify
LOOP

StrobeVerify:
PAUSE 1000
HIGH 2
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO StrobeOnly
HIGH 3
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO StrobeOnly
IF (IN10 = 0) THEN GOTO StrobeOnly
GOTO StrobeTest 'If no zones are in alarm, go back to normal

StrobeOnly:
HIGH 11
DO
IF (IN5 = 1) THEN GOTO Normal
HIGH 0 : HIGH 9
PAUSE 225
LOW 0
PAUSE 225
LOOP

'----------[TROUBLE]
Trouble1:
DO
HIGH 12 : HIGH 13 : PAUSE 500 : LOW 12 : LOW 13 : PAUSE 500
HIGH 2
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO AlarmVerify
HIGH 3
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO AlarmVerify
IF (IN4 = 1) THEN GOTO TroubleSilence
IF (IN5 = 1) THEN GOTO Normal
LOOP

Trouble2:
DO
HIGH 12 : HIGH 13 : PAUSE 500 : LOW 12 : LOW 13 : PAUSE 500
HIGH 2
RCTIME 2,1, zone1
IF zone1 = 1 THEN GOTO AlarmVerify
HIGH 3
RCTIME 3,1, zone2
IF zone2 = 1 THEN GOTO AlarmVerify
IF (IN4 = 1) THEN GOTO TroubleSilence
IF (IN5 = 1) THEN GOTO Normal
LOOP

TroubleSilence:
DO
HIGH 11
HIGH 12
LOW 13
IF (IN5 = 1) THEN GOTO Normal
LOOP

'-----------------------------------------------------[[PROGRAM CODE ENDS HERE]]--------------------------------------------------------'









'

Post Edited (firealarmfreak) : 8/27/2008 1:26:24 AM GMT

PJ Allen
08-27-2008, 08:25 AM
Please upload it as an attachment.

Post Edit -- http://forums.parallax.com/showthread.php?p=725270

·Some things that cause posts to go unanswered...
·- Posting very large programs into the message rather than attaching. This is not only clutter and difficult to follow, but often the formatting is lost. It is easier for experienced programmers to load attached code in and see what is going on.

It's what the * Attachment Manager * button is there for.

Post Edited (PJ Allen) : 8/27/2008 1:37:52 AM GMT

firealarmfreak
08-27-2008, 09:30 AM
Ok, here is my code as an attatchment. Sorry I never thought of that before.

Chris.

Chris Savage
08-27-2008, 10:29 AM
FAF,

I looked at your attached code thinking I could at least follow what was going on. Unfortunately your code jumps about so much I can’t really follow what is going on. At the beginning you define several pins and their functions but you never use these descriptive labels through the program. Instead you use the pin numbers. While you’re going down through the code, things like HIGH 0 : HIGH 8 : HIGH 9 don’t mean much unless you know what they are connected to. Same with inputs…you use IN4 and IN5. It would be easier to see what is going on by using:

HIGH AlarmLED: HIGH AudSigs : HIGH Strobes

and

IF (Btn1 = 1) THEN GOTO StrobeTest
IF (Btn2 = 1) THEN GOTO WalkMode
IF (Btn3 = 1) THEN GOTO SignalCodes

The section where you have (there are several):

LOW 8 : LOW 9 : LOW 0 : LOW 1 : LOW 10 : LOW 11 : LOW 12 : LOW 13

…could be done with a single command.

You can set the states of several pins using OUTS, or for less pins the appropriate OUTL, OUTH, etc. A quick note is you have PIN 10 defined as a button but you are forcing it LOW above. By doing this when the button is pressed it will cause a short circuit.

It may seem I am being very harsh about your code but please understand that in a situation like this there are so many things that stand out as problems up front that it is hard to see the forest for the trees. In this case you may need to use DEBUG statements to see where the code is going and what is happening…I can’t really follow the flow because the code jumps all over based on so many conditions.

When you use DEBUG try to print the section the code is in as well as the state of any relevant variables or inputs at that point so you can see why the code may be doing this. And definitely check into that button shorting issue. If you group 4 buttons on a nibble within a port it would be easy to read them all using a subroutine or at least one alias.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

firealarmfreak
08-27-2008, 10:44 AM
I did what I could, I labeled the best i could, i was told you cant label inputs. The parts I think are causing my problem is

"IF (IN4 = 1) THEN GOTO Silence
"IF (IN5 = 1) THEN GOTO Normal

When I removed those, it worked, but i couldnt shut off the alarms..

any ideas?

Chris Savage
08-27-2008, 10:53 AM
First it occurred to me that the code you posted does not match the clips you posted first. That caused me some confusion. Also, you mentioned having to remove two lines to cause the program to work. Does just removing one work?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

firealarmfreak
08-27-2008, 11:11 AM
Well somebody told me i couldnt use IF btn1 = 1, someone said i needed IN4 etc.., i found out he made a mistake. So i changed it and im going to see if it works any better. What do you mean by my code posted does not match the clips i posted first?

When i removed:

IF (IN4 = 1) THEN GOTO Silence,

the system started automaticly resetting.

When I removed:

IF (IN5 = 1) THEN GOTO Normal,

the system started automaticly going to silence (the silence led lit)

When I have them both, its random, sometimes resets automaticly and mostly just goes to silence automaticly.

The key thing is that, i have 4 signal codes, all programmed the same except they pulse the alarm at different rates. The ONLY one not working is continuous, it works perfectlty on the rest.

Any other ideas?

Chris Savage
08-27-2008, 11:19 AM
In your original post your code for the AlarmA section looked like this…

AlarmA: 'Continuous
DO
HIGH 8 : HIGH 9 : HIGH 0 'Normal Alarm
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
PAUSE 225
LOW 0
PAUSE 225
LOOP

In the file you attached it looks like this:

AlarmA:
DO
IF (IN4 = 1) THEN GOTO Silence
IF (IN5 = 1) THEN GOTO Normal
HIGH 8
HIGH 9
LOOP

There are differences and I made initial assumptions based on the snips you first posted and now see they’re incorrect. That was what I meant. I would make all changes and attach new code once you have run the DEBUG routines.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

firealarmfreak
08-27-2008, 12:10 PM
Hey, sorry for that change. You said if i ran the debug commands you would fix my code, does this mean you know why im having a problem?

Chris Savage
08-27-2008, 10:09 PM
Actually, what I said was that if I were you I would use DEBUG to try and find out what is happening and I suggested how you could go about that. With all due respect you have what we programmers refer to as spaghetti code. In the time it would take an outsider to dissect and troubleshoot your code you could probably just use the DEBUG method to track the source of the problem or simply rewrite it in a modular format.

Once you have done this you should post your results. You could put a DEBUG line at various routine entry points and see where the flow of the program is going. At key points, such as where things are not working as they should you can also have it print the values of the affected variables·before, during and after entry into the routine.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

firealarmfreak
08-27-2008, 11:38 PM
Thats pointless because I know where the code is going,

Its jumping to silence and sometimes back to the begining.. but if i were to debug it, how would i write the debug code?

Chris Savage
08-28-2008, 12:04 AM
What do you mean going back to the beginning? That could be an indication that the BASIC Stamp is resetting…That is important information to know. If you put a line at the beginning of your program that says, “Program Running…” you should see it only once. If you’re seeing it more than once then your program is indeed, restarting.

P.S. - Suggestions are never pointless.· If we suggest something there is always a point to it, otherwise we're just wasting time.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

firealarmfreak
08-28-2008, 12:21 AM
Sorry, it just seems like its taking forever to solve something that i thought someone could solve by correcting a piece of my code, instead its made complicated. Sugesstions are not useless but i was clearly telling you where the stamp was going. When i say it goes back to the begining i mean it goes back to the top of the code and starts from the begining, in my code its Normal.

Unsoundcode
08-28-2008, 01:40 AM
Hi Chris, your code is taking an unexpected path , if you first track the route with debug instructions you can then reduce the number of debugs to concentrate on the portion of code thats directing you the wrong way. To first track the route place a debug immediately after each of the 20 plus labels

eg:

Label Name:

DEBUG "Name of Label",CR

if the program is cycling too quickly slow it down a little with a pause after each debug. This will help you close in on the problem

Jeff T.

firealarmfreak
08-28-2008, 02:47 AM
Thanks Unsoundcode, you actually made it make sense too me. I will try that.

Chris.