November 21, 2024, 06:43:37 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Programming

Started by bgarth, March 16, 2010, 07:16:22 PM

Previous topic - Next topic

bgarth

Need help with programming Prop II.

We have a Prop-II controller, one Parallax 2x16 Serial LCD (Backlit), two momentary push button switch's, and two 12-volt LED's

When idle the LCD will display on Line-1 "Water is OFF" Line-2 "Push ON to Start", and Red LED will be illuminated.

Momentary Start button will activate the operational cycle.
Momentary Start button when pushed will...
1. Start timer countdown from 90:00 minutes (default)
2. Display Line-1 "Water is ON"  Line-2 "90:00 Min Remain" (unit time has expired)
3. Turn on valve 1, then after 2 seconds turn on valve 2 (until time has expired) Note: This will reduce the initial inrush current
4. Turn off red LED
4. Turn on green LED (until time has expired)

When time has expired the operational cycle is over and will...
5. Turn off valves 
6. Display Line-1 "Water is OFF" Line-2 "Push ON to Start"
7. Turn off green LED
8. Turn on red LED

Momentary Stop button when pushed during operational cycle will...
9. Turn off valves 
10. Display Line-1 "Water is OFF" Line-2 "Push ON to Start"
11. Turn off green LED
12. Turn on red LED





JonnyMac

I haven't forgotten about you, Barry.  I have a Prop-2 and Serial LCD in my bags so I can work on your program when I get to the hotel.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Barry,

Got your message -- was hoping to work on your code last night but we got called to the haunted house ("The Darkness") to help them install some AP-16s (they are our beta testers).  Will skip post show activities tonight to get some work in on your code.  Sorry... it's been a crazy month for us.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here you go, Barry -- I think this does what you want.  Be sure to set your serial LCD to 19.2K baud.

' =========================================================================
'
'   File...... BG_Water_Timer.BS2
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 30 MAR 2010
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

TX              PIN     15              ' No ULN, SETUP = UP
StartBtn        PIN     14              ' SETUP = DN
StopBtn         PIN     13              ' SETUP = DN

RedLed          PIN     3
GrnLed          PIN     2
Valve2          PIN     1               ' use OUT1
Valve1          PIN     0               ' use OUT0


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

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

Yes             CON     1
No              CON     0

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T9600       CON     84
    T19K2       CON     32
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T9600       CON     240
    T19K2       CON     110
#ENDSELECT

Baud            CON     T19K2                   ' for serial LCD

LcdBkSpc        CON     $08                     ' move cursor left
LcdRt           CON     $09                     ' move cursor right
LcdLF           CON     $0A                     ' move cursor down 1 line
LcdCls          CON     $0C                     ' clear LCD
LcdCR           CON     $0D                     ' move pos 0 of next line
LcdBLon         CON     $11                     ' backlight on
LcdBLoff        CON     $12                     ' backlight off
LcdOff          CON     $15                     ' LCD off
LcdOn1          CON     $16                     ' LCD on; no crsr, no blink
LcdOn2          CON     $17                     ' LCD on; no crsr, blink
LcdOn3          CON     $18                     ' LCD on; crsr, no blink
LcdOn4          CON     $19                     ' LCD on; crsr, blink
LcdLine1        CON     $80                     ' go to line 1, column 0
LcdLine2        CON     $94                     ' go to line 2, column 0

LcdCC0          CON     $F8                     ' define custom char 0
LcdCC1          CON     $F9                     ' define custom char 1
LcdCC2          CON     $FA                     ' define custom char 2
LcdCC3          CON     $FB                     ' define custom char 3
LcdCC4          CON     $FC                     ' define custom char 4
LcdCC5          CON     $FD                     ' define custom char 5
LcdCC6          CON     $FE                     ' define custom char 6
LcdCC7          CON     $FF                     ' define custom char 7


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

state           VAR     Byte                    ' program state

triggers        VAR     Byte
trStart        VAR     triggers.BIT6           ' for P14
trStop         VAR     triggers.BIT5           ' for P13

idx             VAR     Byte
tix             VAR     Byte
holdoff         VAR     Byte
mins            VAR     Byte
secs            VAR     Byte

runTimer        VAR     Word                    ' water run Timer


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

Power_Up:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00001111           ' set outputs

  HIGH TX                                       ' setup serial output pin
  PAUSE 100                                     ' allow LCD to initialize

  GOSUB Splash_Screen

Reset:
  GOSUB Water_Off


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

Main:
  triggers = %01100000                          ' assume active
  FOR idx = 1 TO 24                             ' ~100ms loop
    PAUSE 4
    triggers = triggers & INH                   ' scan inputs
  NEXT


Update_HoldOff:
  IF (state = 0) & (holdoff < 250) THEN         ' if not at max
    holdoff = holdoff + 1                       '  update hold-off timer
  ENDIF


Update_Run_Timer:
  IF (state > 0) THEN                           ' running?
    tix = tix + 1 // 10                         ' update seconds timer
    IF (tix = 0) THEN                           ' new second?
      runTimer = runTimer - 1                   ' yes, decrement run timer
      IF (runTimer = 0) THEN                    ' expired?
        GOSUB Water_Off                         ' yes, kill valves
      ELSE
        GOSUB Show_Run_Time
      ENDIF
    ENDIF
  ENDIF

  BRANCH state, [W_Off, W_Start, W_On]
  state = 0


W_Off:
  IF (holdoff > 50) THEN                        ' past hold-off (5s)?
    IF (trStart = Yes) THEN                     '  yes, start pressed?
      GOSUB Water_On                            '   yes, let's go
    ENDIF
  ENDIF
  GOTO Main


W_Start:
  IF (runTimer <= 5398) THEN                    ' time for valve 2?
    Valve2 = IsOn                               '  yes, activate
    state = 2
  ENDIF
  GOTO Main


W_On:
  IF (runTimer <= 5395) THEN                    ' past min run time (5s)?
    IF (trStop = Yes) THEN                      ' if stop pressed
      GOSUB Water_Off                           '  kill it
    ELSEIF (trStart = Yes) THEN                 ' if start pressed
      GOSUB Water_On                            '  reload timer
    ENDIF
  ENDIF
  GOTO main


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

Splash_Screen:
  SEROUT TX, Baud, [LcdBLoff, LcdOn1, LcdCls]
  PAUSE 5
  SEROUT TX, Baud, [" BG Water Timer", CR, "  Version 0.1"]
  PAUSE 2000
  RETURN

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

Water_Off:
  SEROUT TX, Baud, [LcdCls]
  PAUSE 5
  SEROUT TX, Baud, ["Water is OFF", CR, "Push ON to Start"]

  Valve1 = IsOff
  Valve2 = IsOff
  GrnLed = IsOff
  RedLed = IsOn
  holdoff = 0                                   ' reset hold-off timer
  state = 0

  RETURN

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

Water_On:
  SEROUT TX, Baud, [LcdCls]
  PAUSE 5
  SEROUT TX, Baud, ["Water is ON"]

  tix = 0
  runTimer = 90 * 60                            ' seconds in 90 minutes
  Valve1 = IsOn
  GrnLed = IsOn
  RedLed = IsOff
  state = 1

  ' falls through to Show_Run_Time

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

Show_Run_Time:
  mins = runTimer / 60
  secs = runTimer // 60
  SEROUT TX, Baud, [LcdLine2, DEC2 mins, ":", DEC2 secs]
  RETURN

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

bgarth

JonnyMac,

Thanks for the programming, but due to space limitations in my enclosure, could we move PIN group 15, 14, & 13 to 7, 6, & 5.


JonnyMac

April 02, 2010, 09:57:58 AM #5 Last Edit: April 02, 2010, 10:00:15 AM by JonnyMac
Easy-peezy -- just update the TX, StartBtn, and StopBtn definitions as shown in the listing below, and redirect the scan routine to the low group.  While looking at the program I also made a couple very small refinements; no changes to operation, though.

You'll need to remove pin 1 of the ULN used for the lower group (P0..P7) -- we don't want the ULN loading the line (P7) used for serial comms to the LCD.  See this link: http://www.efx-tek.com/php/smf/index.php?topic=130.0

' =========================================================================
'
'   File...... BG_Water_Timer_v2.BS2
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 02 APR 2010
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

TX              PIN     7                       ' No ULN
StartBtn        PIN     6                       ' ULN acts as pull-down
StopBtn         PIN     5                       ' ULN acts as pull-down

RedLed          PIN     3                       ' use P3.W/GND or OUT3/V+
GrnLed          PIN     2                       ' use P2.W/GND or OUT2/V+
Valve2          PIN     1                       ' use OUT1
Valve1          PIN     0                       ' use OUT0


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

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

Yes             CON     1
No              CON     0

#SELECT $STAMP
 #CASE BS2, BS2E, BS2PE
   T2400       CON     396
   T9600       CON     84
   T19K2       CON     32
 #CASE BS2SX, BS2P
   T2400       CON     1021
   T9600       CON     240
   T19K2       CON     110
#ENDSELECT

Baud            CON     T19K2                   ' for serial LCD

LcdBkSpc        CON     $08                     ' move cursor left
LcdRt           CON     $09                     ' move cursor right
LcdLF           CON     $0A                     ' move cursor down 1 line
LcdCls          CON     $0C                     ' clear LCD
LcdCR           CON     $0D                     ' move pos 0 of next line
LcdBLon         CON     $11                     ' backlight on
LcdBLoff        CON     $12                     ' backlight off
LcdOff          CON     $15                     ' LCD off
LcdOn1          CON     $16                     ' LCD on; no crsr, no blink
LcdOn2          CON     $17                     ' LCD on; no crsr, blink
LcdOn3          CON     $18                     ' LCD on; crsr, no blink
LcdOn4          CON     $19                     ' LCD on; crsr, blink
LcdLine1        CON     $80                     ' go to line 1, column 0
LcdLine2        CON     $94                     ' go to line 2, column 0

LcdCC0          CON     $F8                     ' define custom char 0
LcdCC1          CON     $F9                     ' define custom char 1
LcdCC2          CON     $FA                     ' define custom char 2
LcdCC3          CON     $FB                     ' define custom char 3
LcdCC4          CON     $FC                     ' define custom char 4
LcdCC5          CON     $FD                     ' define custom char 5
LcdCC6          CON     $FE                     ' define custom char 6
LcdCC7          CON     $FF                     ' define custom char 7


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

state           VAR     Byte                    ' program state

triggers        VAR     Byte
trStart        VAR     triggers.BIT6           ' for P6
trStop         VAR     triggers.BIT5           ' for P5

idx             VAR     Byte
tix             VAR     Byte
holdoff         VAR     Byte
mins            VAR     Byte
secs            VAR     Byte

runTimer        VAR     Word                    ' water run Timer


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

Power_Up:
 OUTH = %00000000 : OUTL = %00000000           ' clear all
 DIRH = %00000000 : DIRL = %00001111           ' set outputs

 HIGH TX                                       ' setup serial output pin
 PAUSE 100                                     ' allow LCD to initialize

 GOSUB Splash_Screen

Reset:
 GOSUB Water_Off


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

Main:
 triggers = %01100000                          ' assume active
 FOR idx = 1 TO 24                             ' ~100ms loop
   PAUSE 4
   triggers = triggers & INL                   ' scan inputs
 NEXT


Update_HoldOff:
 IF (state = 0) & (holdoff < 250) THEN         ' if not at max
   holdoff = holdoff + 1                       '  update hold-off timer
 ENDIF


Update_Run_Timer:
 IF (state > 0) THEN                           ' running?
   tix = tix + 1 // 10                         ' update seconds timer
   IF (tix = 0) THEN                           ' new second?
     runTimer = runTimer - 1                   ' yes, decrement run timer
     IF (runTimer = 0) THEN                    ' expired?
       GOSUB Water_Off                         ' yes, kill valves
     ELSE
       GOSUB Show_Run_Time
     ENDIF
   ENDIF
 ENDIF

 BRANCH state, [W_Off, W_Start, W_On]
 state = 0


W_Off:
 IF (holdoff > 50) THEN                        ' past hold-off (5s)?
   IF (trStart = Yes) THEN                     '  yes, start pressed?
     GOSUB Water_On                            '   yes, let's go
     state = 1
   ENDIF
 ENDIF
 GOTO Main


W_Start:
 IF (runTimer <= 5398) THEN                    ' time for valve 2?
   Valve2 = IsOn                               '  yes, activate
   state = 2
 ENDIF
 GOTO Main


W_On:
 IF (runTimer <= 5395) THEN                    ' past min run time (5s)?
   IF (trStop = Yes) THEN                      ' if stop pressed
     GOSUB Water_Off                           '  kill it
   ELSEIF (trStart = Yes) THEN                 ' if start pressed
     GOSUB Water_On                            '  reload timer
   ENDIF
 ENDIF
 GOTO main


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

Splash_Screen:
 SEROUT TX, Baud, [LcdBLon, LcdOn1, LcdCls]    ' initialize LCD
 PAUSE 5
 SEROUT TX, Baud, [" BG Water Timer", CR, "  Version 0.2"]
 PAUSE 2000
 RETURN

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

Water_Off:
 SEROUT TX, Baud, [LcdCls]
 PAUSE 5
 SEROUT TX, Baud, ["Water is OFF", CR, "Push ON to Start"]

 Valve1 = IsOff
 Valve2 = IsOff
 GrnLed = IsOff
 RedLed = IsOn
 holdoff = 0                                   ' reset hold-off timer
 state = 0

 RETURN

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

Water_On:
 SEROUT TX, Baud, [LcdCls]
 PAUSE 5
 SEROUT TX, Baud, ["Water is ON"]

 tix = 0
 runTimer = 90 * 60                            ' seconds in 90 minutes
 Valve1 = IsOn
 GrnLed = IsOn
 RedLed = IsOff

 ' falls through to Show_Run_Time

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

Show_Run_Time:
 mins = runTimer / 60
 secs = runTimer // 60
 SEROUT TX, Baud, [LcdLine2, DEC2 mins, ":", DEC2 secs]
 RETURN

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