November 23, 2024, 11:57:33 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.


Scaling the Prop-Pot

Started by JonnyMac, September 14, 2011, 01:10:33 PM

Previous topic - Next topic

JonnyMac

September 14, 2011, 01:10:33 PM Last Edit: September 14, 2011, 02:33:04 PM by JonnyMac
I just wrote a bit of code for one of our OEM customers that I think is worth sharing.  What he needed to do is convert the input from the Prop-Pot (0 to 255) to a variable delay for the end of the program.  In his case, he wanted 30 to 90 minutes, but for the code below I will change that to 30 to 180 seconds (30s to 3m).

The key to understanding how this program works on the delay calculation is that we're going to use the general formula for a line which is mx+b.  The m element is the slope of the line (change in output per change in input), the b element is the intercept point at X = 0.  In our case, the intercept (b) is the minimum delay.

So how do we get the slope (m)?  That's easy: it's the ratio of output span to input span.  The input span is easy: 0 to 255 is what we will get from a properly scaled POT circuit, so the input span is 255.  The output span is 150 (180 - 30).  The BS1 uses 16 bit variables inside so we can put the math on one line.  The only caveat is that we don't want the internal value to go above 65535 (W size) otherwise we will get a bad result.  Since the BS1 does math strictly left-to-right we can check; in our case the worst-case internal value is 38250 (255 * 150) -- we're okay.

Here's the program that adds a pot-controlled, variable delay after the prop runs.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'
'   E-mail....
'   Started...
'   Updated... 14 SEP 2011
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Pin 7 must have SETUP jumper and ULN pin removed for proper operation of
' the Prop-Pot circuitry.  This program is compatible with the Prop-1
' Trainer.
'
' Use "Run\Pot Scaling..." from the Editor menu to determine the correct
' value for the Scale constant.


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


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

SYMBOL  Adjust          = 7                     ' SETUP = Out, No ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  PopUp           = PIN0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Scale           = 113                   ' for RC ciruit on Prop-Pot


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

SYMBOL  timer           = B2                    ' for input debouncing

SYMBOL  lottery         = W5                    ' random #


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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000001                              ' P0 is output

  lottery = 1031                                ' seed random #


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 150 THEN Check_Trigger             ' debounce for 150ms

Start_Show:
  PopUp = IsOn
  PAUSE 1000
  PopUp = IsOff

Read_Delay:
  POT Adjust, Scale, timer                      ' 0 to 255
  timer = timer * 150 / 255 + 30                ' convert to 30 to 180s

  DEBUG CLS, "Delay = ", #timer, CR             ' show delay in seconds

Run_Delay:
  IF timer = 0 THEN Reset                       ' expired?
    PAUSE 998                                   ' 1 sec, minus overhead
    timer = timer - 1
    GOTO Run_Delay

  GOTO Reset


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


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


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


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


' -----[ User Data ]-------------------------------------------------------



Jon McPhalen
EFX-TEK Hollywood Office