November 22, 2024, 08:49:03 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Using the Prop-1 POT Function

Started by JonnyMac, May 21, 2007, 07:43:07 PM

Previous topic - Next topic

JonnyMac

May 21, 2007, 07:43:07 PM Last Edit: May 22, 2007, 08:21:05 AM by JonnyMac
From time-to-time we need to develop a program that allows for variable timing without recompiling/downloading our program -- with a simple circuit and the POT function we can do that.  The circuit in question, as used in the Prop-Pot (Prop-1 side) and the Prop-1 Trainer Board looks like this:



First things first:
1. Connect the pot circuit to P7
2. Remove the P7 SETUP jumper
3. (Important!) Change the Prop-1's ULN2803 to a ULN2003
    -- if you don't have a ULN2003 then remove the top two pins of the ULN2803 as shown below:



The BASIC Stamp Editor has a special function for deriving the Scale value required by the POT function.  For the components used in the schematic above, the scale value should be about 100, so you can use that if you don't have time to run the process below.

1. From the Run menu, select POT Scaling
2. Select pin 7 from the drop-down, then click Start
    -- this will download a new program, so you'll need to put yours back later



3. Turn the pot to both extremes noting the smallest value in the Scale Factor box (remember this!)



4. Select the POT Value checkbox then rotate the pot through its range; the value should go from near zero to 255



5. Click the close button
6. Incorporate the POT function in your program like this (which uses the Scale Factor from above):

  POT 7, 106, rawValue

... where the variable, rawValue, is a byte or word.  Note that if a word is used the maximum value will still be 255.

Q: Why doesn't the pot value go all the way down to zero?
A: Because each Prop-1 I/O pin has a 220-ohm protection resistor which will cause a low value from POT on the minimum end.

The next step is taking the raw value, ~0 to 255, and converting it to something useful in your program.  Let's say, for example, you'd like the pot range to be converted to a value from 1000 to 10000 to be used by PAUSE for a program delay.  Assuming that we have a raw output from 5 to 255 from our pot circuit, the equation works out to this:

  POT 7, 106, delay
  delay = delay - 5
  delay = delay * 36 + 1000


Here's what's going on: The first step eliminates the low end and zero-adjusts the value, effectively creating a POT range of 0 to 250.  Since the span of the value is 250, we divide this into the desired output span of 9000 (10000 - 1000) to get the multiplier of 36.  The final step is to add in the minimum output value, changing the final output from 1000 to 10000 to be used by PAUSE.

You math types will recognize this as the standard line equation of mx + b -- for those that aren't math wizards, no worries, just post your questions in our forums and we'll show you how to get to where you want to go!

Here's another example that uses a different strategy: Perhaps you just want a small delay of 25 ms to one second (1000 ms); on easy way is like this:

  delay = delay * 4 MIN 25 MAX 1000

Since the desired upper end is 1000, and 1000 / 255 is almost four we use 4 as the multiplier.  The output range is now something on the order of 0 to 1020 -- which we could just leave alone.  But... if we want to be persnickety using the MIN and MAX operators allow use to fix (sometimes truncate) the ends of the ranges.  Be a little careful with MIN and MAX as they do truncate values; in extreme cases you'll notice that at the ends of the pot range you still have movement of the pot with not output value change due to MIN and MAX truncating.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

If I remove 3 sets of pins on the uln2803 can I use 3 pots to create 3 different timing values in a program? I am going to try but before I do I just figured I would ask real quick and save myself the wasted time if it can't be done.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Yes, you can; I have a Prop-1 with four of the ULN pins removed so that the ULN doesn't interfere with what I've got connected.  Remember, when using P6 or P7 for a POT input you must also remove the the SETUP jumper.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

I am having some trouble with my pot function coding.

I am trying to cycle between 4 outputs, reading a pot on pin 7 for the on time of each output, and a pot on pin 6 for the off time. The outputs are cycling, but seems to be still under 1/2 second. I have to be missing something simple.

' =========================================================================
'
'   File...... Evilusions_cycling_relays.BS1
'   Purpose...
'   Author.... Brian Warner
'   E-mail.... gadget@evilusions.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  OnTime          = 7                     ' SETUP = out; no ULN
SYMBOL  OffTime         = 6                     ' SETUP = out; no ULN
SYMBOL  Leds            = PINS


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

SYMBOL  AllOn           = %00111111
SYMBOL  AllOff          = %00000000
SYMBOL  relay1on        = %00000001
SYMBOL  relay2on        = %00000010
SYMBOL  relay3on        = %00000100
SYMBOL  relay4on        = %00001000



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

SYMBOL  delay           = W4
SYMBOL  delay2          = W5

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

Reset:
  Leds = AllOff                                 ' clear LEDs
  DIRS = %001111111                             ' set outputs


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

Main :
  POT OnTime, 105, delay                        ' read speed pot
  delay = delay * 38 + 300                      ' make ~500 to ~10000 ms
  POT OffTime, 105, delay2                      ' read speed pot2
  delay2 = delay2 * 38 MIN 500 MAX 10000        ' make ~500 to ~10000 ms
  Leds = relay1on
  PAUSE OnTime
  Leds = AllOff
  PAUSE OffTime
  Leds = relay2on
  PAUSE OnTime
  Leds = AllOff
  PAUSE OffTime
  Leds = relay3on
  PAUSE OnTime
  Leds = AllOff
  PAUSE OffTime
  Leds = relay4on
  PAUSE OnTime
  Leds = AllOff
  PAUSE OffTime
  GOTO Main


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


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


' -----[ EEPROM Data ]-----------------------------------------------------
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Nothing looks askew; check it with DEBUG -- like this; that way you can see what your pot circuits are actually returning.


Main :
  POT OnTime, 105, delay                        ' read speed pot
  delay = delay * 38 + 300                      ' make ~500 to ~10000 ms
  POT OffTime, 105, delay2                      ' read speed pot2
  delay2 = delay2 * 38 MIN 500 MAX 10000        ' make ~500 to ~10000 ms
  DEBUG delay, delay2   
  GOTO Main


Have you actually run the pot scaling program in the IDE, or is the value of 105 that you're using for the scale value just an estimate?
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Debugs came back perfect, i did find the problem. Here is the corrected code. I had OnTime and OffTime where I should have had delay and delay2

Main:
  POT OnTime, 105, delay                        ' read speed pot
  delay = delay * 38 + 300                  ' make ~500 to ~10000 ms
  POT OffTime, 105, delay2                      ' read speed pot
  delay2 = delay2 * 38 MIN 500 MAX 10000        ' make ~500 to ~10000 ms
  Leds = relay1on
  PAUSE  delay
  Leds = AllOff
  PAUSE  delay2
  Leds = relay2on
  PAUSE  delay
  Leds = AllOff
  PAUSE  delay2
  Leds = relay3on
  PAUSE  delay
  Leds = AllOff
  PAUSE  delay2
  Leds = relay4on
  PAUSE  delay
  Leds = AllOff
  PAUSE  delay2
  GOTO Main
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Boy, call me eagle-eye, huh?  I need more rest!  ;D
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

We are just making you look at way too many programs. Thanks Jon.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

imagineerdan

Hey Team, I am trying to get a pot to make an led blink faster fand faster the more it is turned. Flashing at like 10 to 100 miliseconds. what kind of pot whould I use, and what would the code look look. This is my first use of the pot command so I am excited to give it a try!  Thanks!

JonnyMac

October 24, 2007, 04:37:14 PM #9 Last Edit: October 24, 2007, 04:42:30 PM by JonnyMac
There are times when being pretty good with math is helpful -- this is one of those occasions.  When you've run the POT Scaling function (it's in the Run menu -- and do read about it in the Help file) so that your raw pot value comes back at 255 at the pot's max position you want to find a constant that will convert the max value to 90; you'll add the result of that expression to 10 (your minimum value) to get the full desired range, 10 to 100 (well, pretty close).  Turns out it's about 0.35, so here's how I did it (DEBUG shows 11 to 99 after the math):

' =========================================================================
'
'   File...... Led_Flasher.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Speed           = 7                     ' SETUP = out; no ULN
SYMBOL  Led             = 0


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

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


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

SYMBOL  delay           = B2


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

Reset:


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

Main:
  POT Speed, 110, delay                         ' read trainer pot

  delay = delay * 35 / 100 + 10                 ' delay = delay x 0.35 + 10

  PAUSE delay                                   ' hold
  TOGGLE Led                                    ' flip LED state

  GOTO Main


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


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


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

imagineerdan

How would I wire a pot into the Rev Dx module with the above code?

JonnyMac

Connect the cap side of the circuit to P7 and the resistor to Vss (ground).  Pretty easy -- though you'll have to do some soldering.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

What would the schematic for using the pot with the Rev Dx look like? Thanks :)

JonnyMac

February 12, 2008, 05:30:54 PM #13 Last Edit: February 12, 2008, 05:34:05 PM by JonnyMac
No matter what form your BS1 assumes (Prop-1, or Rev Dx board) the POT circuit is the same.  Be sure to read the online help file for details on using the POT function.

Jon McPhalen
EFX-TEK Hollywood Office