November 22, 2024, 04:07:00 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


fuel pump timer

Started by tj, March 16, 2010, 09:35:33 PM

Previous topic - Next topic

tj


Jon, ive thought of a new use for one of my prop 1 controllers, i thought it would be simple, but. What im trying to do is this.

I want to put a mom. push button on pin 6 (trigger 1) this will start a 5 min timer on pin0 (fuel pump). If button (trigger 1) is pushed again it will cut off,

(reset/goto main) I also want to add a second trigger (trigger 2) on pin5 or pin 7 this will only stop/reset program, (goto main). im figuring this will require state

or branch which is still rough for me, and out of my normal use. I usually modify old programs, for new uses, but couldn't find one for this.

Thanks for your help.

JonnyMac

March 18, 2010, 11:28:59 AM #1 Last Edit: March 18, 2010, 11:33:54 AM by JonnyMac
This program is not as bad as you think... with one caveat: using the same button to start AND stop can be tricky, you don't want the output oscillating.  This program uses BRANCH to handle the button states and gives the user two seconds before allowing a stop with the start button.  Also, to prevent a stop and immediate re-start, the Reset section forces both buttons to be clear.

' =========================================================================
'
'   File...... fuel_pump_v01.bs1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 18 MAR 2010
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  TrStop          = PIN7                  ' SETUP = DN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Pump            = PIN0

' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0



' -----[ Variables ]-------------------------------------------------------

SYMBOL  status          = B0                    ' trigger buttons status
SYMBOL   PStart         =  BIT6                 ' debounced start
SYMBOL   PStop          =  BIT7                 ' debounced stop

SYMBOL  idx            = B2                     ' for debounce loop

SYMBOL  timer          = W5                     ' for pump timing


' -----[ Initialization ]--------------------------------------------------

Reset:
 PINS = %00000000                              ' clear all
 DIRS = %00000001                              ' make P0 an output

Clear_Buttons:
 PAUSE 50
 status = PINS & %11000000                     ' check buttons
 IF status > %00000000 THEN Clear_Buttons      ' loop until clear

 timer = 0                                     ' reset pump timer


' -----[ Program Code ]----------------------------------------------------

Main:
 status = %11000000                            ' assume active
 FOR idx = 1 TO 20                             ' create 100ms loop
   PAUSE 5
   status = status & PINS                      ' scan button inputs
 NEXT

Check_Timer:
 IF timer = 0 THEN Check_Buttons
   timer = timer - 1                           ' update if running
   IF timer > 0 THEN Check_Buttons             ' still running?
     Pump = IsOff                              ' no, pump off

Check_Buttons:
 status = status / 64                          ' shift right by 6 bits
 BRANCH status, (Btn00, Btn01, Btn10, Btn11)   ' branch to handler

Btn00:                                          ' neither button pressed
 GOTO Main

Btn01:                                          ' start button
 IF timer = 0 THEN Start_Pump                  ' start if not on
   IF timer < 2980 THEN Reset                  ' stop after debounce period
     GOTO Main

Btn10:                                          ' stop button
 GOTO Reset

Btn11:                                          ' both buttons
 GOTO Main                                     ' invalid, ignoe

Start_Pump:
 timer = 3000                                  ' 5mins @ 0.1s per tick
 Pump = IsOn
 GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office