May 02, 2024, 11:07:56 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.


EZ-3 Standard Program for Prop-1

Started by JonnyMac, April 14, 2009, 07:09:20 PM

Previous topic - Next topic

JonnyMac

April 14, 2009, 07:09:20 PM Last Edit: October 28, 2010, 08:03:54 PM by JonnyMac
This is my standard program for the EZ-3; it uses some math tricks with the ** operator that you may not be familiar with.

' =========================================================================
'
'   File...... EZ-3_Standard.BS1
'   Purpose...
'   Author.... EFX-TEK
'              Copyright (c) 2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... teamefx@efx-tek.com
'   Started...
'   Updated... 01 MAR 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Standard 3-stage timer application.
'
' Trigger Delay... 0 TO 10 seconds
' On Time......... 1 TO 60 seconds
' Off Timer....... 1 TO 20 seconds
'
' For best accuracy of each stage you should run the POT Scaling program
' from the Run menu for each stage.  Set the scale value into the POT
' instruction for each stage.
'
' Trigger Delay... Pin 5
' On Time......... Pin 4
' Off Timer....... Pin 3
'
' Turn each pot fully clockwise and use the scale value provided.  The
' scale value will be around 100 but will vary from pot-to-pot based on
' minor component differences.


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  AdjTrDelay      = 5                     ' on delay  (no ULN)
SYMBOL  AdjOnTime       = 4                     ' run time  (no ULN)
SYMBOL  AdjOffTime      = 3                     ' off delay (no ULN)
SYMBOL  TrDelay         = PIN2                  ' triger delay output
SYMBOL  OnTime          = PIN1                  ' on time output
SYMBOL  OffTime         = PIN0                  ' off off output


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  timer           = W0
SYMBOL   negFlag        =  BIT15

SYMBOL  tix             = W1


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

Reset:
 PINS = %00000000                              ' clear all
 DIRS = %00000111                              ' set outputs


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

Main:
 timer = 0                                     ' reset timer

Check_Trigger:                                  ' debounce input
 PAUSE 5                                       ' loop pad
 timer = timer + 5 * Trigger                   ' update timer
 IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input


' Trigger delay is 0 to 10 seconds
' -- convert pot span (0 to 250) to 0 to 100 "tix"
' -- tix = timer x 0.4

Trigger_Delay:
 POT AdjTrDelay, 100, timer                    ' raw input, 5 to 255
 timer = timer - 5                             ' correct low end offset
 IF negFlag = No THEN Run_TD
   timer = 0                                   ' fix roll-under

Run_TD:
 IF timer = 0 THEN On_Time                     ' skip if zero
 tix = timer ** $6666                          ' tix = timer x 0.4
 TrDelay = IsOn
 GOSUB Delay_Tix
 TrDelay = IsOff


' On time is 1 to 60 seconds
' -- convert pot span (0 to 250) to 10 to 600 "tix"
' -- tix = (timer x 2.36) + 10

On_Time:
 timer = 0
 POT AdjOnTime, 100, timer
 timer = timer - 5
 IF negFlag = No THEN Run_OT
   timer = 0

Run_OT:
 tix = timer * 2                               ' tix = timer x 2
 timer = timer ** $5C28                        ' x 0.36
 tix = tix + timer                             ' tix = timer x 2.36
 tix = tix + 10                                ' set low end
 OnTime = IsOn
 GOSUB Delay_Tix
 OnTime = IsOff


' Off time is 1 to 20 seconds
' -- convert pot span (0 to 250) to 10 to 200 "tix"
' -- tix = (timer x 0.76) + 10

Off_Time:
 timer = 0
 POT AdjOffTime, 100, timer
 timer = timer - 5
 IF negFlag = No THEN Run_XT
   timer = 0

Run_XT:
 tix = timer ** $C28F                          ' tix = timer x 0.75
 tix = tix + 10                                ' set low end
 OffTime = IsOn
 GOSUB Delay_Tix
 OffTime = IsOff

 GOTO Main


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

' Delay in 0.1-second units
' -- put delay in "tix" before calling

Delay_Tix:
 IF tix = 0 THEN DT_Exit
   PAUSE 100
   tix = tix - 1
   GOTO Delay_Tix

DT_Exit:
 RETURN


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