Hardware works but my software doesn't - BS2
wedgehawg
Posts: 1
Hello,
I am working on a stamp based (BS2) project to provide control of a dc motor, some ac loads, etc.· The hardware· functions when·I·provide·a stand alone TTL input to the respective interface circuits.· I am not a programmer and it shows! And, I don't·understand what is happening well enough to correct my errors.·
I am trying to work with If-Then statements that sample binary inputs, then direct the code to subroutines that send out logic high states to my drive circuits. All the output drive signals need to be·cancelled upon receiving a high input on·assigned pins representing limit switches, etc.
Right now, I can only achieve success with my code through the first two loops (Up and Dn loops); I can never get acknowledment of reaching my hardware limits (Up, Dn, limit switches) and see the state changes in the outputs.
Sorry I am so confused over the simple stuff. Thanks in advance - here is the code:
' {$STAMP BS2}
btn_up VAR Byte· 'define Up button (P13), workspace for button instructions
btn_dn VAR Byte· '· "··· Dn·· "··· (P15),···· "····· "···· "······· "
btn_up_limit VAR Byte 'define Up_limit· (P12),"····· "···· "······· "
btn_dn_limit VAR Byte 'define Dn_limit· (P10),"····· "···· "······· "
btn_up=0········ 'clear the workspace variable
btn_dn=0········ 'clear the workspace variable
btn_up_limit=0·· 'clear the workspace variable
btn_dn_limit=0·· 'clear the workspace variable
start:
IF btn_up=1 THEN Up
IF btn_dn=1 THEN Dn
IF btn_up_limit=1 THEN Deenergize
IF btn_dn_limit=1 THEN Deenergize2
Up:·· 'Up relay drive subroutine
· BUTTON 13,1,255,255,btn_up,0,nopress 'button modes, branch instr.
· DEBUG "*"····· 'if pin13=1· - show asterisk in debug window on switch closure
· HIGH 7········ 'send out "Up" relay drive signal on P7
· BUTTON 12,1,255,255,btn_up_limit,0,Deenergize 'button modes, branch inst.
· nopress: GOTO Dn· 'check and see if Dn switch is pressed
· RETURN
Dn:· 'Dn relay drive subroutine
· BUTTON 15,1,255,255,btn_dn,0,nopress2 'button modes, branch instr.
· DEBUG "*"······ 'if pin15=1· - show asterisk in debug window on switch closure
· HIGH 6········· 'send out "Dn" relay drive signal on P6
· BUTTON 10,1,255,255,btn_dn_limit,0,Deenergize2· 'button modes, branch instr.
· DEBUG "*"······ 'if pin10=1 - show asterisk in debug window
· nopress2: GOTO Up· 'check and see if Up switch is pressed
· RETURN
Deenergize: 'Up limit switch activation
· BUTTON 12,1,255,255,btn_up_limit,0,nopress3 'button modes, branch instr.
· DEBUG "*"······ 'if pin12=1 - show asterisk in debug window on switch closure
· LOW 7·· 'remove Up relay drive signal
· nopress3: GOTO Deenergize2
· RETURN
Deenergize2: 'Dn limit switch activation
· BUTTON 10,1,255,255,btn_dn_limit,0,nopress4
· DEBUG "*"······ 'if pin10=1 -show asterisk in debug window on switch closure
· LOW 6··· 'remove Dn relay drive signal
· nopress4: GOTO Deenergize
· RETURN
I am working on a stamp based (BS2) project to provide control of a dc motor, some ac loads, etc.· The hardware· functions when·I·provide·a stand alone TTL input to the respective interface circuits.· I am not a programmer and it shows! And, I don't·understand what is happening well enough to correct my errors.·
I am trying to work with If-Then statements that sample binary inputs, then direct the code to subroutines that send out logic high states to my drive circuits. All the output drive signals need to be·cancelled upon receiving a high input on·assigned pins representing limit switches, etc.
Right now, I can only achieve success with my code through the first two loops (Up and Dn loops); I can never get acknowledment of reaching my hardware limits (Up, Dn, limit switches) and see the state changes in the outputs.
Sorry I am so confused over the simple stuff. Thanks in advance - here is the code:
' {$STAMP BS2}
btn_up VAR Byte· 'define Up button (P13), workspace for button instructions
btn_dn VAR Byte· '· "··· Dn·· "··· (P15),···· "····· "···· "······· "
btn_up_limit VAR Byte 'define Up_limit· (P12),"····· "···· "······· "
btn_dn_limit VAR Byte 'define Dn_limit· (P10),"····· "···· "······· "
btn_up=0········ 'clear the workspace variable
btn_dn=0········ 'clear the workspace variable
btn_up_limit=0·· 'clear the workspace variable
btn_dn_limit=0·· 'clear the workspace variable
start:
IF btn_up=1 THEN Up
IF btn_dn=1 THEN Dn
IF btn_up_limit=1 THEN Deenergize
IF btn_dn_limit=1 THEN Deenergize2
Up:·· 'Up relay drive subroutine
· BUTTON 13,1,255,255,btn_up,0,nopress 'button modes, branch instr.
· DEBUG "*"····· 'if pin13=1· - show asterisk in debug window on switch closure
· HIGH 7········ 'send out "Up" relay drive signal on P7
· BUTTON 12,1,255,255,btn_up_limit,0,Deenergize 'button modes, branch inst.
· nopress: GOTO Dn· 'check and see if Dn switch is pressed
· RETURN
Dn:· 'Dn relay drive subroutine
· BUTTON 15,1,255,255,btn_dn,0,nopress2 'button modes, branch instr.
· DEBUG "*"······ 'if pin15=1· - show asterisk in debug window on switch closure
· HIGH 6········· 'send out "Dn" relay drive signal on P6
· BUTTON 10,1,255,255,btn_dn_limit,0,Deenergize2· 'button modes, branch instr.
· DEBUG "*"······ 'if pin10=1 - show asterisk in debug window
· nopress2: GOTO Up· 'check and see if Up switch is pressed
· RETURN
Deenergize: 'Up limit switch activation
· BUTTON 12,1,255,255,btn_up_limit,0,nopress3 'button modes, branch instr.
· DEBUG "*"······ 'if pin12=1 - show asterisk in debug window on switch closure
· LOW 7·· 'remove Up relay drive signal
· nopress3: GOTO Deenergize2
· RETURN
Deenergize2: 'Dn limit switch activation
· BUTTON 10,1,255,255,btn_dn_limit,0,nopress4
· DEBUG "*"······ 'if pin10=1 -show asterisk in debug window on switch closure
· LOW 6··· 'remove Dn relay drive signal
· nopress4: GOTO Deenergize
· RETURN
Comments
An alternative technique is to read all the switches at once, with the INA, INB, INC, or IND command (see the Help file). You may want to rearrange your switches to be on 4 adjacent pins. (0,1,2,3 or 12,13,14,15 for instance).
Then use SELECT.......CASE to branch your program as required.(see the Help file)
Heres a code snippet where I make several choices depending on where two joysticks are. The variables ch1 and ch2 are obtained in the main loop of the program.
· runwin: ' operate winches when direction stick is at center-off
·SELECT ch1
·· CASE < 300
···· GOTO nolink
·· CASE > 800
···· HIGH 0
···· LOW 14
·· CASE < 600
···· HIGH 14
···· HIGH 0
·· CASE 660 TO 770
···· LOW 0
···· LOW 14
·ENDSELECT
SELECT ch2
·· CASE < 300
···· GOTO nolink
·· CASE > 800
···· HIGH 1
···· LOW 15
·· CASE < 600
···· HIGH 15
···· HIGH 1
·· CASE 660 TO 770
···· LOW 1
···· LOW 15
· ENDSELECT
· RETURN
Cheers,
·Edit Nov 16/08 - Code snippet added.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
Post Edited (stamptrol) : 11/16/2008 9:33:17 PM GMT