November 18, 2024, 11:47:41 AM

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.


Weirdness with PWM

Started by gadget-evilusions, March 08, 2008, 09:15:50 PM

Previous topic - Next topic

gadget-evilusions

Hi,

I have this program I piced together and modifed, I know it's not efficent program design, but it was convinent for programming on what I am doing. I have led lights on all 8 outputs. The issue I am having is with the fade sections at the end of the program. The first on works fine, all the leds start on and fade off in sequence. The second one however fades each led on in sequence, but does not leave it on.

' =========================================================================
'
'   File...... Evilusions_Screamline_booth_TW2008.BS1
'   Purpose...
'   Author.... Brian Warner parts "borrowed" from programs by Jon Williams, EFX-TEK
'   E-mail.... gadget@evilusions.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Leds            = PINS


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

SYMBOL  AllOn           = %11111111
SYMBOL  AllOff          = %00000000
SYMBOL  SignOn          = %11000000
SYMBOL  RedSignOn       = %10111111
SYMBOL  WhiteSignOn     = %01000000
SYMBOL  WhiteLeftOutOn  = %10100000
SYMBOL  RedLeftOn       = %10010000
SYMBOL  WhiteLeftInOn   = %10001000
SYMBOL  WhiteRightInOn  = %10000100
SYMBOL  RedRightOn      = %10000010
SYMBOL  WhiteRightOutOn = %10000001
SYMBOL  RightOn         = %10000111
SYMBOL  LeftOn          = %10111000
SYMBOL  RedOn           = %10010010
SYMBOL  WhiteOn         = %01101101
SYMBOL  Delay1 = 80
SYMBOL  Delay2 = 100
SYMBOL  Delay3 = 100
SYMBOL  Delay4 = 250
SYMBOL  Delay5 = 500

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

SYMBOL  tix            = B2
SYMBOL  pinNum         = B3
SYMBOL  level          = B4



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

Reset:
  Leds = AllOff
  DIRS = %111111111


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

Main:

Sign_Strobe:
FOR tix = 1 TO 750
  Leds = RedSignOn
  PAUSE Delay1
  Leds = AllOn
  PAUSE Delay1
  NEXT
  GOTO Sweep

Sweep:
FOR tix = 1 TO 25
  Leds = WhiteLeftOutOn
  PAUSE Delay2
  Leds = RedLeftOn
  PAUSE Delay2
  Leds = WhiteLeftInOn
  PAUSE Delay2
  Leds = WhiteRightInOn
  PAUSE Delay2
  Leds = RedRightOn
  PAUSE Delay2
  Leds = WhiteRightOutOn
  PAUSE Delay2
  Leds = RedRightOn
  PAUSE Delay2
  Leds = WhiteRightInOn
  PAUSE Delay2
  Leds = WhiteLeftInOn
  PAUSE Delay2
  Leds = RedLeftOn
  PAUSE Delay2
  Leds = WhiteLeftOutOn
  PAUSE Delay2
  NEXT
  GOTO Sign_Strobe2

Sign_Strobe2:
FOR tix = 1 TO 750
  Leds = RedSignOn
  PAUSE Delay1
  Leds = AllOn
  PAUSE Delay1
  NEXT
  GOTO Sweep2

Sweep2:
FOR tix = 1 TO 10
  Leds = LeftOn
  PAUSE Delay3
  Leds = RightOn
  PAUSE Delay3
  NEXT
  GOTO Sign_Strobe3

Sign_Strobe3:
FOR tix = 1 TO 750
  Leds = RedSignOn
  PAUSE Delay1
  Leds = AllOn
  PAUSE Delay1
  NEXT
  GOTO Blink

Blink:
FOR tix = 1 TO 25
  Leds = RedOn
  PAUSE Delay4
  Leds = WhiteOn
  PAUSE Delay4
  NEXT


Sign_Strobe4:
FOR tix = 1 TO 750
  Leds = RedSignOn
  PAUSE Delay1
  Leds = AllOn
  PAUSE Delay1
  NEXT

FadeAllDown:
  Leds = AllOn
  FOR pinNum = 0 TO 7
   FOR  level = 255 TO 0 STEP -2
      PWM pinNum, level, 2
    NEXT
  NEXT

FadeAllUp:
Leds = AllOff
  FOR pinNum = 0 TO 7
   FOR  level = 0 TO 255 STEP 2
      PWM pinNum, level, 2
    NEXT
  NEXT
  GOTO Reset







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


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


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

John B

Hi Brian,
I haven't run your code, but I think I may have an idea why it is not working the way you think it should.
I believe the PWM command, after it executes, leaves the pin low, i.e. the LED off.  So how about adding one line of code to your last routine, like this:

FadeAllUp:
Leds = AllOff
  FOR pinNum = 0 TO 7
   FOR  level = 0 TO 255 STEP 2
      PWM pinNum, level, 2
    NEXT
    HIGH pinNum
  NEXT
  GOTO Reset

I think that will fix it.  Let me know either way.

John B.

gadget-evilusions

It worked perfect, thanks John. I didn't realize that after a PWM it defaults to off, now I know.

See you in Vegas!
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components