November 01, 2024, 12:33:13 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.


AP-16 program

Started by gadget-evilusions, March 29, 2011, 06:24:32 PM

Previous topic - Next topic

gadget-evilusions

March 29, 2011, 06:24:32 PM Last Edit: March 29, 2011, 07:19:58 PM by gadget-evilusions
Hi,

I took an existing program that I have used on a bunch of props and added what I believe should be necessary to operate the ap-16 also.

I am having a little difficulty though. I can't seem to get it to play the file "burn" when it should be.

I know my set up between the prop-1 and ap-16 is working correctly because a known good program works with a known good card. Because I was having difficulty I renamed a known good file (one of Jon's sfx trial wavs) to "burn.wav" . Still won't trigger.

I must be missing something in the program and I can't see it.


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

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

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

' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL  Sio             = PIN7                  ' SETUP = DN ULN OUT
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

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

SYMBOL  Baud            = OT2400
SYMBOL  ThrashTime      = 8000                 ' thrash for eight seconds
SYMBOL  Addr            = %00                  ' BR OFF, A1 OFF, A2 OFF, EN OFF, ? OFF, AMBIENT ON

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

SYMBOL  delay           = B2                    ' valve on/off delay
SYMBOL  idx             = B3                    ' loop controller
SYMBOL  timer           = W4                    ' for event timing
SYMBOL  lottery         = W5                    ' random #

' -----[ Initialization ]--------------------------------------------------
Reset:
 PINS = %00000000                              ' clear all outputs
 DIRS = %00001111                              ' make P0-P2 outputs
 SEROUT Sio, Baud, ("!AP16", Addr, "X")        ' stop if playing now
 PAUSE 5000                                    ' inter-show delay
 timer = 0                                     ' reset timer

' -----[ Program Code ]----------------------------------------------------
Main:
 RANDOM lottery                                ' stir random #
 PAUSE 5                                       ' loop pad
 timer = timer + 5 * Trigger                   ' update timer
 IF timer < 100 THEN Main                      ' wait for 0.1 sec input
Start_Audio:
 SEROUT Sio, Baud, ("!AP16", Addr, "PW", "burn", 13, 1)
Thrash:
 timer = 0
Keep_Thrashing:
 FOR idx = 1 TO 3                              ' big stir
   RANDOM lottery
 NEXT
 PINS = lottery & %00001111                    ' update 3 valves
 RANDOM lottery                                ' new random #
 delay = lottery // 151 + 100                  ' delay = 100 to 250
 PAUSE delay                                   ' hold
 timer = timer + delay                         ' update timer
 IF timer < ThrashTime THEN Keep_Thrashing     '  and check
   GOTO Reset                                  ' reset everything

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

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

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

JonnyMac

Hint for everyone: Whitespace (blank lines) is your friend.

I always have one blank line before sections and after minor sections, and two blank lines after major sections.  These lines do not affect the size of the program downloaded to the Prop-1/2/SX, so don't be afraid to use them.  

QuoteI must be missing something in the program and I can't see it.

Make your programs easy to read and you'll spot errors more quickly.  ;D

What I missed looking at the code in the forums I found while adding blank lines to the code: the definition for Sio uses PIN7 instead of 7 as it should (see line marked in red).  What's happening, then, is that the SEROUT line is actually looking at the state of P7 (via the PIN7 register) and finding it "1" due to the pull-up; the SEROUT is now happening but on P1 instead of P7 as you intend.

Here's my reformatted version of the program.  Note the insertion of blank lines to break the code into logical chunks, even in the same major section.  Note, too, that I added a power-up delay before the reset section.  The AP-16+ has to scan for files on power up and this takes a little time.  This delay only happens at power up as the program routes back to the Reset label when finished.

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

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

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

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


SYMBOL  Sio             = 7                     ' SETUP = DN ULN OUT
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


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

SYMBOL  Baud            = OT2400
SYMBOL  Addr            = %00                  ' AP-16+ Config = 000XXX

SYMBOL  ThrashTime      = 8000                 ' thrash for eight seconds


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

SYMBOL  delay           = B2                    ' valve on/off delay
SYMBOL  idx             = B3                    ' loop controller

SYMBOL  timer           = W4                    ' for event timing
SYMBOL  lottery         = W5                    ' random #


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

Power_Up:
 PAUSE 3000                                    ' let AP-16+ power up

Reset:
 PINS = %00000000                              ' clear all outputs
 DIRS = %00001111                              ' make P0-P3 outputs

 SEROUT Sio, Baud, ("!AP16", Addr, "X")        ' stop if playing now
 PAUSE 5000                                    ' inter-show delay

 timer = 0                                     ' reset timer


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

Main:
 RANDOM lottery                                ' stir random #
 PAUSE 5                                       ' loop pad
 timer = timer + 5 * Trigger                   ' update timer
 IF timer < 100 THEN Main                      ' wait for 0.1 sec input

Start_Audio:
 SEROUT Sio, Baud, ("!AP16", Addr, "PW", "burn", 13, 1)

Thrash:
 timer = 0

Keep_Thrashing:
 FOR idx = 1 TO 3                              ' big stir
   RANDOM lottery
 NEXT
 PINS = lottery & %00001111                    ' update 4 valves

 RANDOM lottery                                ' new random #
 delay = lottery // 151 + 100                  ' delay = 100 to 250
 PAUSE delay                                   ' hold

 timer = timer + delay                         ' update timer
 IF timer < ThrashTime THEN Keep_Thrashing     '  and check
   GOTO Reset                                  ' reset everything


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

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

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




Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

On your prop: You could replace the "1" at the end of the SEROUT command with "0" (zero) to force the file to loop while your valves are operating.  At Reset: the file would be stopped.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Jon,

Sorry I missed your call.

Thank you so much. It's always that one tiny thing I seem to miss when I have a problem. That's why the forums (and Jon and John) are so great.

Thank you for the tip on repeating the audio, how to properly format my program for display on the forums, and also reminding me that blank lines are my friend. Without you guys my props would not be nearly as cool.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

gadget-evilusions

I have one more question on this program.

I have a set of REV E Prop-1's with the solder pads on the bottom. I have put solder on the solder pads that connect P6 to Out6. John told me that I needed to connect my N. O. switch between Out 6 and GND and to put the set up jumper on "UP". My program then requires a 0 instead of a 1 to start? How do I make that work with the "standard" debounce loop?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

March 31, 2011, 08:48:59 AM #5 Last Edit: March 31, 2011, 09:06:57 AM by JonnyMac
Here's how I do active-low. Start with these definitions:

SYMBOL  NotPressed      = 1                     ' for active-low
SYMBOL  Pressed         = 0


And now the debounce loop looks like this:

Main:
 timer = 0                                     ' reset timer

Check_Trigger:
 PAUSE 5                                       ' loop pad
 timer = timer + 5
 IF Trigger = NotPressed THEN Main
 IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input


You need to make sure that you've clipped the upper to pins on both sides of the ULN before using OUT7 and OUT6 as input connections, and definitely never connect those terminals to anything higher than 5v without protection.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

It worked perfectly. Thank you.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components