November 22, 2024, 10:06:49 PM

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.


PWM Loop while checking trigger

Started by gadget-evilusions, October 21, 2008, 09:51:37 AM

Previous topic - Next topic

gadget-evilusions

Jon,

For one my props, I was thinking if it was possible to pwm the eyes up and down (leds on out 0) while still being able to pick up the trigger input (P6) if it happened to be triggered during one of the pwm loops and then jump to the operational portion of my program, (solenoid valves on outs 1-4) . Just a theoretical question, if at all possible.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

This seems to work on my Prop-1 Trainer -- give it a try.  Note that the "1" at the end of the PWM instruction is one cycle of 5 milliseconds, hence the "+ 5" in the timer update line.  If you want a slower fade change the PWM cycles to 2 and the timer update value to 10.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 21 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Eyes            = 0

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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  flags           = B0
SYMBOL   direction      =  BIT0

SYMBOL  timer           = B2
SYMBOL  level           = B3


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

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


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

Main:
  level = 0
  direction = 0
  timer = 0

Check_Trigger:
  PWM Eyes, level, 1
  timer = timer + 5 * Trigger
  IF timer = 100 THEN Show_Code
  IF direction = 1 THEN Check_Dim

Check_Bright:
  level = level + 1
  IF level < 255 THEN Check_Trigger
    direction = 1
    GOTO Check_Trigger

Check_Dim:
  level = level - 1
  IF level > 0 THEN Check_Trigger
    direction = 0
    GOTO Check_Trigger


Show_Code:
  FOR timer = 1 TO 10
    HIGH Eyes
    PAUSE 100
    LOW Eyes
    PAUSE 50
  NEXT

  GOTO Main


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


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


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


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


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


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


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

gadget-evilusions

Wow, that is some fancy looping and redirect. I had the basic idea in my head but couldn't get it to work. The addition of the "direction" was genius. Thanks Jon.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

condolaw

THANK YOU !!!
I "permanently borrowed" the code and added
Cylinder = PIN1 in definitions and  DIRS = %00000011 and at the end:

Cylinder = IsOn
PAUSE 2000
Cylinder = IsOff

  GOTO Reset                        ' Changed MAIN to Reset

and worked GREAT !!!!   one more ulcer  gone!!!!

. . . in definitions I had to use PINx instead of just the # for it to run. .


EXACTLY what I was looking for THANK YOU AGAIN!!!!
Condolaw
John
St. Augustine, FL

JonnyMac

October 22, 2008, 09:44:32 AM #4 Last Edit: October 22, 2008, 09:46:42 AM by JonnyMac
Yes, if you want to write a value to a pin like this:

  Cylinder = IsOn

... then Cylinder must be defined as a pin register (PINx) not just a pin number (x).  The reason is that the compiler replaces the nice names we use with their constants (from the SYMBOL definitions).  The line above translates to:

  PIN1 = 1

... and

  Cylinder = IsOff

... translates to:

  PIN1 = 0

If we had just used the pin number the compiler would translate like this:

  1 = 0

... which creates an obvious error and causes the compilation process to fail.
Jon McPhalen
EFX-TEK Hollywood Office