Any thoughts before I pull all my hair out?
-JR-
Posts: 6
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-
·
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-
·
Comments
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 -->
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:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
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.
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.
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 1/26/2007 7:43:29 PM GMT