PDA

View Full Version : Any thoughts before I pull all my hair out?



-JR-
01-26-2007, 03:17 PM
First timmer here...· For some unknown reason to me the output alias'es work but the input ones do not.· I am asuming that I am dealing with an default setup issue, why outputs work.

If I ask it to debug in0, it does say that it =1, but my ACFAIL alias returns nothing, why?

Here is a snippit of my code... ?see anything?

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

Throttle·· VAR Word··· 'Range 500CW --> 1000CCW
Genspeed·· VAR Word··· 'ACTUAL ROTATION SPEED IN 0.5HZ
GENSETSPD· VAR Word··· 'DESIRED DISTRIBUTOR FREQ IN HZ
Cranktry·· VAR Byte··· 'NUMBER OF CRANKING TRIES
DURADJ···· VAR Word··· 'SAMPLE PERIOD FOR ENGINE SPEED IN MSEC (MUST BE GREATER THAN 1)
GENSPDD··· VAR Word··· 'THIS VALUE IS DOUBLE GENSPEED

'Constants
'Inputs / Outputs
'····· (LOW = Active state FOR inputs AND Deactive FOR outputs, unless otherwise noted)
· ACFAIL······· CON 0·· 'INPUT··· Detects AC failure
· COLDSTARTDET· CON 1·· 'INPUT··· Detects IF this is a cold start condition
· SPEEDSEN····· CON 2·· 'INPUT
· OVERTEMP····· CON 3·· 'INPUT
· OILPRESS····· CON 4·· 'INPUT
· OVERVOLT····· CON 5·· 'INPUT
· OVERAMP······ CON 6·· 'INPUT
· SHUTDOWN····· CON 7·· 'INPUT
· FAULT········ CON 8·· 'OUTPUT
· CHOKE········ CON 9·· 'OUTPUT
· IGNITION····· CON 10· 'OUTPUT
· STARTER······ CON 11· 'OUTPUT
· THROTSRVO···· CON 12· 'OUTPUT
· MAINCUT······ CON 13· 'OUTPUT
· ACPULLIN····· CON 14· 'OUTPUT

'BEING ROUTINE….
DO
DEBUG CLS
DEBUG 13, "THE CONTROLLER IS ONLINE"
PAUSE 3000

'ENVIROMENTAL SETUP
THROTTLE = 1000························ 'SETS THROTTLE FULL COUNTER CLOCKWISE, 0% THROTTLE
PULSOUT 13, THROTTLE··················· 'SETS PIN 13 FOR SERVO PWM CONTROL
DURADJ = 500··························· 'SETS POLLING PERIOD IN MSEC FOR COUNTING
GENSETSPD = 1050······················· 'SETS DESIRED DISTRIBUTOR FREQ IN HZ

INPUT·· 0············· 'ACFAIL
INPUT·· 1············· 'COLDSTARTDET
INPUT·· 2············· 'SPEEDSEN
INPUT·· 3············· 'OVERTEMP
INPUT·· 4············· 'OILPRESS
INPUT·· 5············· 'OVERVOLT
INPUT·· 6············· 'OVERAMP
INPUT·· 7············· 'SHUTDOWN
OUTPUT· 8············· 'FAULT
OUTPUT· 9············· 'CHOKE
OUTPUT· 10············ 'IGNITION
OUTPUT· 11············ 'STARTER
OUTPUT· 12············ 'THROTSRVO
OUTPUT· 13············ 'MAINCUT
OUTPUT· 14············ 'ACPULLIN
DEBUG 13, ? IN0····· '<-- DEBUGS IN0=1
DEBUG 13, ? ACFAIL·· '<-- DOESN'T DEBUG ANY INFO

'INITIALIZATION FAULT CHECKS
· IF OVERTEMP = 0 THEN HIGH FAULT
· IF OVERTEMP = 0 THEN DEBUG 13, "OVER TEMP ALARM"
· IF SHUTDOWN = 0 THEN HIGH FAULT
· IF SHUTDOWN = 0 THEN DEBUG 13, "SHUTDOWN OVERRIDE ENABLED"
· IF FAULT = 1 THEN GOTO FAULTDET
· GOTO DETECTION

FAULTDET:
· DEBUG CRSRXY, 0, 14, "GENERATOR OFFLINE DUE TO FAULT"
· DEBUG CRSRXY, 0, 15, "SYSTEM HALTED UNTIL CONDITION CORRECTED"
· PAUSE 1000
· DEBUG CLREOL, CRSRXY, 0, 14
· DEBUG CLREOL, CRSRXY, 0, 15
· PAUSE 1000
· GOTO FAULTDET

DETECTION:
· DEBUG CRSRXY, 0, 4, "NOW WATCHING FOR AC POWER FAIL"
· PAUSE 2000
· IF ACFAIL = 1 THEN DEBUG CLREOL, CRSRXY, 0, 5, "AC POWER IS NOW ON·································· "
· IF ACFAIL = 0 THEN DEBUG CLREOL, CRSRXY, 0, 5, "AC FAIL! WAITING 30SEC FOR HYDRO TO RESTORE"
· IF ACFAIL = 0 THEN PAUSE 20000·········· 'SETS DEBOUNCE WAIT TIME
· IF ACFAIL = 0 THEN DEBUG CLREOL, CRSRXY, 0, 5, "RECHECKING IN 10SEC··························· "
· IF ACFAIL = 0 THEN PAUSE 10000
· IF ACFAIL = 0 THEN GOTO CONTINUE··········· 'DECIDES IF AC FAIL IS LEGIT
· GOTO DETECTION·························· 'LOOPS THE DETECTION

· CONTINUE:
··· DEBUG CLS, "END OF CONDITIONS"
··· END

· LOOP


Thanks so much!
-JR-
·

Bruce Bates
01-26-2007, 03:39 PM
JR -

The firt thing to do is to clean up the program so it's more readable. You need to learn about the OTHER form of the IF statement. You are presently using the single line format: IF ... THEN and you should be using the multi-line format: IF ... THEN ... ELSE. The syntax and usage can be found in the PBASIC Reference Manual, or in the PBASIC Help File.

That will make everyone's life easier.

Additionally, take a look at the PIN declaration instead of using CON to define your input and output pins.

Regards,

Bruce Bates

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

Zoot
01-26-2007, 03:50 PM
You have defined ACFAIL as a CONSTANT not as PIN. You might want to check out the Stamp manual for the PIN definition.

If you define:

ACFAIL CON 0

Then it will ALWAYS be 0.

If you define it as

ACFAIL PIN 0

Then you could:

HIGH ACFAIL 'sets ACFAIL to be output and makes it high
INPUT ACFAIL 'make it an input
IF ACFAIL = 0 THEN DEBUG "yo, it is zero" 'if it's input and it equals 0, then do something

Does this make sense?

Also, it looks like you make MAINCUT an output before checking it's "input" state -- you can't do both, only one or the other. But wait, I just realized, I think you mean to pulsout the throttle, not main cut
To go further, from your code:




THROTSRVO PIN 12 'alias to pin, not a constant
MAINCUT PIN 13
ACPULLIN PIN 14
'...
PULSOUT THROTSRVO, THROTTLE 'was wrong PIN + use PIN alias, not number, this way if change you pins, you only have to change def. in one place
'...
INPUT MAINCUT 'use pin alias, make input
IF MAINCUT = 0 THEN
DEBUG "MAINCUT = 0"
ELSE
DEBUG "MAINCUT = 1"
ENDIF


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

Lee Harker
01-26-2007, 10:29 PM
JR,
It seems that you have ACFAIL defined as the number 0. Your debug statement sends 13 which is a carriage return and then the 0 which in ASCII code is null. So it is sending something but it's not a visible character.
Another thing you will want to check is your DO loop. It appears that you want this to loop forever but once it hits the END command near the bottom, the party's over.

LSB
01-26-2007, 10:30 PM
to expand on Bruce's comments:

IF ACFAIL = 1 THEN DEBUG CLREOL, CRSRXY, 0, 5, "AC POWER IS NOW ON "
IF ACFAIL = 0 THEN DEBUG CLREOL, CRSRXY, 0, 5, "AC FAIL! WAITING 30SEC FOR HYDRO TO RESTORE"
IF ACFAIL = 0 THEN PAUSE 20000 'SETS DEBOUNCE WAIT TIME
IF ACFAIL = 0 THEN DEBUG CLREOL, CRSRXY, 0, 5, "RECHECKING IN 10SEC "
IF ACFAIL = 0 THEN PAUSE 10000
IF ACFAIL = 0 THEN GOTO CONTINUE

May be written as:

IF ACFAIL = 1 THEN
DEBUG CLREOL, CRSRXY, 0, 5, "AC POWER IS NOW ON "
Else
DEBUG CLREOL, CRSRXY, 0, 5, "AC FAIL! WAITING 30SEC FOR HYDRO TO RESTORE"
PAUSE 20000
DEBUG CLREOL, CRSRXY, 0, 5, "RECHECKING IN 10SEC "
PAUSE 10000
GOTO CONTINUE
EndIf

Also:

Gosub and Return may be used to structure common or repeated segments of code as in:

Gosub Pause_Recheck:
.
.
.
code
code
Gosub Pause_Recheck:
code
END

Pause_Recheck: 'notice the colon
PAUSE 20000
DEBUG CLREOL, CRSRXY, 0, 5, "RECHECKING IN 10SEC "
PAUSE 10000
Return

The code between the LABEL and RETURN statements is executed each time the GOSUB is encountered
This prevents typos and makes troubleshooting easier. Also helps with readability.

TechnoRobbo
01-26-2007, 11:28 PM
- JR- said...

IF OVERTEMP = 0 THEN HIGH FAULT
IF OVERTEMP = 0 THEN DEBUG 13, "OVER TEMP ALARM"


------------------------------------------------------------------------------

This alternate syntax will also work if you use CON instead of PIN:




IF INS.LOWBIT(OVERTEMP) = 0 THEN

HIGH FAULT
DEBUG 13, "OVER TEMP ALARM"

ENDIF


---------------------------

My only other thought is: don't pull out your hair -it hurts. http://forums.parallax.com/images/smilies/freaked.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Post Edited (TechnoRobbo) : 1/26/2007 7:43:29 PM GMT