November 21, 2024, 04:13:34 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.


Stumped with Sequence

Started by aquawilly54, October 22, 2016, 03:02:03 PM

Previous topic - Next topic

aquawilly54

Hi folks,
  I'm back with another question.
I'm posting my program for help. 

What I'm trying to get is:

T00
    Main body, Strobe light, LED light to come on, then 4 seconds later:

T04
    Audio and arms on.

Then all will shut off at the end of audio.

Right now everything comes on, then at 4 seconds the audio does it's thing, then all is off

Why are the arms coming on immediately? 

Admittedly I copied and pasted a lot of stuff, but I don't see the error.  Please help.
Thank you.


'   File......   Skeleton 2016
'   Purpose...    Strobe light and LED lights in head on at same time Main body goes up.  Audio plays with arms up, then all ends.
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


SYMBOL  Arms            = PIN4                  ' Use OUT4/V+
SYMBOL  LED             = PIN2                  ' use OUT2/V+
SYMBOL  Strobe          = PIN1                  ' use OUT1/V+ to relay for 120V AC strobe and spot light
SYMBOL  MainBody        = PIN0                  ' use OUT0/V+


' -----[ 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  Baud            = OT2400


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

SYMBOL  status         =  B0                    ' AP-16+ status byte
SYMBOL  playing        =  BIT7                 ' 1 when playing

SYMBOL  timer          =  B2                    ' for debounce loop


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

Power_Up:
  PAUSE 3000                                    ' let AP-16+ initialize

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  PAUSE 20000                                   ' PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

T00:                                            ' start of sequence
  Arms           = IsOff                        ' Arms stay down 'til sound comes on
  MainBody       = IsOn
  Strobe         = IsOn
  LED            = IsOn

  PAUSE 3958                                    ' 4s - Body up, strobe on, LEDs on

  ' play audio file, SFX00.WAV
  ' -- allows testing via AP-16+ start button

T04:
  SEROUT Sio, Baud, ("!AP16", %00, "P?", 5, 1)  ' play SFX00.WAV thru SFX05.WAV one time
  Arms           = IsOn



     Audio_Wait:
  PAUSE 100
  SEROUT Sio, Baud, ("!AP16", %00, "G")
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Wait



  GOTO Reset



aquawilly54

Problem fixed, but drives another question.

I omitted Output 0 and moved everything up one notch, so now it's outputs 1,2,3, &4.  It works as advertised, so now I have to ask why. 

Was Output 0 acting as a ground for everything, thereby completing the circuit even though it wasn't supposed to be for Output 4?  If that's the case...why?

Thanks for listening.
Steve

JonnyMac

It's a little difficult to help because your code doesn't seem to match your comments.

You should be able to download a blank program to the Prop-1 and have everything be off. Give that a try -- it may detect a problem.
Jon McPhalen
EFX-TEK Hollywood Office

aquawilly54

Ok, let me try this without the code.

- I started out with connections at OUT0, OUT1, OUT2, and OUT3.
- OUT0, OUT1, and OUT2 were timed to come on immediately with trigger.
- OUT4 was to come on 4s later with the audio.

- All OUTPUTS came on immediately.  Not what I programed. 

- I then swapped the connection from OUT3 to OUT4, but no change.

I moved connections to OUT1, OUT2, OUT,3, and OUT4 and the program worked correctly, so the question is "Is it possible that OUT0 was causing a grounding issue?  If so - why? 

I don't need a fix, I'm just trying to understand why it happened.
Thanks much.

Steve








Why didn't it work before the move? 

JonnyMac

October 22, 2016, 09:32:19 PM #4 Last Edit: October 22, 2016, 09:37:30 PM by JonnyMac
I can't find anything obviously wrong with your program, and I can say that one bad output will not cause others to operate.

Okay... tough love: messy listings drive me bonkers. As you get more into coding, your program will become longer and more sophisticated, and messy formatting will bite you on the backside. Trust me, I know. It doesn't really take any extra time to keep listings very tidy. I promise you, the few extra seconds you spend keeping your listings very neat and orderly will save you hours of debugging time. Yes, I am speaking from experience.

Here's a clean-up that I ran on my Prop-1 without any troubles (outputs tested with Prop-1 Trainer)

' =========================================================================
'
'   File...... Skeleton_2016.bs1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Arms            = PIN3                  ' Use OUT3/V+
SYMBOL  LED             = PIN2                  ' use OUT2/V+
SYMBOL  Strobe          = PIN1                  ' use OUT1/V+
SYMBOL  Body            = PIN0                  ' use OUT0/V+


' -----[ 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  Baud            = OT2400


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

SYMBOL  status          =  B0                   ' AP-16+ status byte
SYMBOL   playing        =   BIT7                ' 1 when playing

SYMBOL  timer           =  B2                   ' for debounce loop


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

Power_Up:
  PAUSE 3000                                    ' let AP-16+ initialize

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00001111                              ' P3..P0 are outputs

  PAUSE 20000                                   ' PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

T00:                                            ' start of sequence
  Body   = IsOn
  Strobe = IsOn
  LED    = IsOn

  PAUSE 4000

T04:
  SEROUT Sio, Baud, ("!AP16", %00, "P?", 5, 1)  ' randomize SFX00..SFX05
  Arms = IsOn

Audio_Wait:
  PAUSE 100
  SEROUT Sio, Baud, ("!AP16", %00, "G")
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Wait

  GOTO Reset


BTW... here's another way you can tackle the outputs.

T00:                                            ' start of sequence
  PINS = %00000111
  PAUSE 4000

T04:
  SEROUT Sio, Baud, ("!AP16", %00, "P?", 5, 1)  ' randomize SFX00..SFX05
  PINS = %00001111


This style is not self-documenting, but does use less code and refreshes all IO pins with the PINS command.

Jon McPhalen
EFX-TEK Hollywood Office

aquawilly54

"Okay... tough love: messy listings drive me bonkers. As you get more into coding, your program will become longer and more sophisticated, and messy formatting will bite you on the backside."

Understood.  I'm trying to get better.  I like that last example.  Thanks much.

Steve