Perplexing issue with Basic Stamp Homework Board
I have·a basic·design & operation requirement, which I thought a BS2 would solve. Presently I am using a Basic Stamp Homework Board for testing. I needed to activate a solenoid for ~35 mS in a 1 shot mode, 1 pulse per switch depression.
I used the (Button) command to debounce and provide this function for the control switch. I do not use the (Button) command for the other switches. The timing adjustment was done originally with the RCTIME command and a series RC circuit as in the Parallax book,·but was changed to a simpler NON RC design.
·I have run into some issues that do not seem to work as they should considering how simple the code is. I will only go over my NON RC version as this·has eliminated the need for a POT & Cap.
The circuit consist of 3 switches (2 pushbutton & 1 footswitch), all normally open, tied to Vdd through a 10K resistor and the opposite side to Vss. The output is a Opto22 Solid State Relay, which a LED has been substituted for now.
My·first problem is that·I MUST have ( time VAR Word ) declared even though I am no longer using this variable, if I remove or comment it out, the output will remain on for a long duration, and may show (·35315 ) after the output drops,·rather than cycle on for ~35mS and then drop. There is no other use of this variable as you can see below.
Below is the code presently in use:
'{$STAMP BS2}
'{$PBASIC 2.5}
·'RC Free Version, Pushbutton Time Control
·time VAR Word
·shot VAR Word
· shot = 35
DO
IF (IN0 = 0) AND shot < 65535 THEN Shot = Shot + 1
'IF shot = 65535 THEN shot = 65535
IF (IN4 = 0) AND shot > 1 THEN Shot = Shot - 1
'IF shot = 1 THEN shot = 1
DEBUG HOME,CR, "Pulse Width Time = ", ? shot
·· PAUSE 100
··· 'ENDIF
·Flow:
·BUTTON 5,0,255,0,B1,0,Again
·HIGH 7
·PAUSE shot
·LOW 7
·PAUSE 100
·Again:
·'DEBUG HOME, "done " , CR, "Total Count = ", Total
·LOOP:
·END
I used the (Button) command to debounce and provide this function for the control switch. I do not use the (Button) command for the other switches. The timing adjustment was done originally with the RCTIME command and a series RC circuit as in the Parallax book,·but was changed to a simpler NON RC design.
·I have run into some issues that do not seem to work as they should considering how simple the code is. I will only go over my NON RC version as this·has eliminated the need for a POT & Cap.
The circuit consist of 3 switches (2 pushbutton & 1 footswitch), all normally open, tied to Vdd through a 10K resistor and the opposite side to Vss. The output is a Opto22 Solid State Relay, which a LED has been substituted for now.
My·first problem is that·I MUST have ( time VAR Word ) declared even though I am no longer using this variable, if I remove or comment it out, the output will remain on for a long duration, and may show (·35315 ) after the output drops,·rather than cycle on for ~35mS and then drop. There is no other use of this variable as you can see below.
Below is the code presently in use:
'{$STAMP BS2}
'{$PBASIC 2.5}
·'RC Free Version, Pushbutton Time Control
·time VAR Word
·shot VAR Word
· shot = 35
DO
IF (IN0 = 0) AND shot < 65535 THEN Shot = Shot + 1
'IF shot = 65535 THEN shot = 65535
IF (IN4 = 0) AND shot > 1 THEN Shot = Shot - 1
'IF shot = 1 THEN shot = 1
DEBUG HOME,CR, "Pulse Width Time = ", ? shot
·· PAUSE 100
··· 'ENDIF
·Flow:
·BUTTON 5,0,255,0,B1,0,Again
·HIGH 7
·PAUSE shot
·LOW 7
·PAUSE 100
·Again:
·'DEBUG HOME, "done " , CR, "Total Count = ", Total
·LOOP:
·END
Comments
2) The problem you are running into with "time VAR Word" is that you're using the byte variable "B1" in your BUTTON statement. If you'll look in the PBasic manual in the section on memory allocation, you'll see that "B1 is the second byte of variable space. Normally, the compiler allocates variables starting at location zero and "time VAR Word" will be allocated to the same space that contains B0 and B1 or W0. If you leave that out, then "shot VAR Word" will be allocated there and the BUTTON statement will overwrite whatever you have there. Best practice is to never use both compiler allocated variables and explicitly named locations in the same program. Use a "work VAR Byte" declaration at the beginning and replace the reference to "B1" with "work".