November 27, 2024, 07:31:44 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


BS2 AP-8 programing

Started by mzitterk, March 31, 2008, 10:28:55 PM

Previous topic - Next topic

mzitterk

March 31, 2008, 10:28:55 PM Last Edit: March 31, 2008, 10:33:05 PM by mzitterk
I am requesting assistance to help write and understand a program to control audio outputs from an AP-8. I am new to basic and microcontrollers but not to electronics.  "old guy"  here's what I would like to do;

I am working on a BOE with a BS2 Rev J and am able to control a AP-8 with the demo program output on pin #15. 

What I need help with is programing the different BS2 I/O (inputs) to address different voice sections of the AP-8, ex: pin #_ to control segments # _ of the AP-8.  and so on. this way I hope to use 8 inputs to control the AP-8 at audio outputs using only output pin #15.  Not all sounds would be used in every case, and some sounds would take priority over other sounds,  I would also like to string sounds together if more than one input is triggered.  Where do I start

Any help would be great!

JonnyMac

April 01, 2008, 09:55:20 AM #1 Last Edit: April 01, 2008, 09:57:21 AM by JonnyMac
Are you comfortable controlling the AP-8?  If yes, the process is actually pretty simple. 

* Scan/Debounce button inputs
* Compare scan to known combinations
* Control the AP-8

I've written a starter program for you that assumes you've got eight, active-high buttons on P0..P7 (remember, you need to pull these pins to ground through 10K resistors -- one resistor per pin).  The program has subroutines to play a segment and wait for the AP-8 to finish.  You have to wait on the AP-8 to finish before sending another command as the AP-8 does not queue commands.

' =========================================================================
'
'   File...... AP-8_Control_Center.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' AP-8 serail control
Keyboard        VAR     INL                     ' buttons on P0..P7


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

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper installed


Yes             CON     1
No              CON     0

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


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

keys            VAR     Byte                    ' debounced inputs
idx             VAR     Byte                    ' loop controller
sfx             VAR     Byte                    ' segment to play

status          VAR     Byte
Playing        VAR     status.BIT7             ' 0 = idle, 1 = playing
SoftLoop       VAR     status.BIT6             ' 0 = normal, 1 = soft loop
HardLoop       VAR     status.BIT5             ' 0 = hard loop, 1 = regular
PlayRec        VAR     status.BIT4             ' 0 = Play, 1 = Rec


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

Reset:
  SEROUT Sio, Baud, ["!!!!!!AP8", $FF, "X"]     ' reset AP-8 (any address)


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

Main:
  GOSUB Read_Keys                               ' get user input

  IF (keys = %00000001) THEN
    sfx = 0
    GOSUB Play_AP8
    GOSUB Wait_AP8
    GOTO Main
  ENDIF

  IF (keys = %00000010) THEN
    sfx = 1
    GOSUB Play_AP8
    GOSUB Wait_AP8
    GOTO Main
  ENDIF

  IF (keys = %00000011) THEN
    sfx = 0
    GOSUB Play_AP8
    GOSUB Wait_AP8
    sfx = 1
    GOSUB Play_AP8
    GOSUB Wait_AP8
    GOTO Main
  ENDIF

  GOTO Main


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

' Scans/debounces active-high inputs on P0..P7
' -- debounced inputs in "keys"

Read_Keys:
  keys = %11111111                              ' assume pressed
  FOR idx = 1 TO 10
    keys = keys & Keyboard
    PAUSE 5
  NEXT
  RETURN

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

' Plays segment specified in "sfx"
' -- assumes AP-8 is set to address %00 (both jumpers out)

Play_AP8:
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
  RETURN

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

' Polls AP-8 for playing status
' -- holds until AP-8 is finished

Wait_AP8:
  DO
    PAUSE 50
    SEROUT Sio, Baud, ["!AP8", %00, "G"]        ' get status
    SERIN  Sio, Baud, [status]
  LOOP UNTIL (Playing = No)
  RETURN

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


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


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


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




Jon McPhalen
EFX-TEK Hollywood Office

mzitterk

Thanks, with copy, paste, change of key #'s & sfx # This is a good start for my project.  You sure make this look easy!!! I'm tring to understand the subroutines and working on a way to sort or queue batched commands. 


JonnyMac

April 01, 2008, 03:55:23 PM #3 Last Edit: April 01, 2008, 03:57:46 PM by JonnyMac
This version compiles but you'll need to test it to make sure I didn't miss anything.

' =========================================================================
'
'   File...... AP-8_Control_Center-v2.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' AP-8 serail control
Keyboard        VAR     INL                     ' buttons on P0..P7


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

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper installed


Yes             CON     1
No              CON     0

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


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

hasKey          VAR     Bit

keys            VAR     Byte                    ' debounced inputs
idx             VAR     Byte                    ' loop controller
sfx             VAR     Byte                    ' segment to play

status          VAR     Byte
Playing        VAR     status.BIT7             ' 0 = idle, 1 = playing
SoftLoop       VAR     status.BIT6             ' 0 = normal, 1 = soft loop
HardLoop       VAR     status.BIT5             ' 0 = hard loop, 1 = regular
PlayRec        VAR     status.BIT4             ' 0 = Play, 1 = Rec

queue           VAR     Byte( 8 )               ' circular buffer
qSize           VAR     Byte                    ' items in queue
head            VAR     Byte                    ' next item to play
tail            VAR     Byte                    ' last item entered


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

Reset:
  SEROUT Sio, Baud, ["!!!!!!AP8", $FF, "X"]     ' reset AP-8 (any address)


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

Main:
  GOSUB Read_Keys                               ' get user input
  IF (hasKey = No) THEN Play_Next

EnQueue:
  IF (keys = %00000001) THEN
    sfx = 0                                     ' set segment
    GOSUB Push_Queue                            ' push into queue
    hasKey = No                                 ' mark keypress as done
  ENDIF

  IF (keys = %00000010) THEN
    sfx = 1
    GOSUB Push_Queue
    hasKey = No
  ENDIF

  IF (keys = %00000011) THEN
    sfx = 0
    GOSUB Push_Queue
    sfx = 1
    GOSUB Push_Queue
    hasKey = No
  ENDIF

DeQueue:
  IF (qSize > 0) THEN
    GOSUB Check_AP8
    IF (Playing = No) THEN
      GOSUB Play_Next
    ENDIF
  ENDIF

  GOTO Main


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

' Scans/debounces active-high inputs on P0..P7
' -- debounced inputs in "keys"

Read_Keys:
  keys = %11111111                              ' assume pressed
  FOR idx = 1 TO 10
    keys = keys & Keyboard
    PAUSE 5
  NEXT
  IF (keys <> %0000000) THEN
    hasKey = Yes
  ENDIF
  RETURN

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

' Pushes new selection into queue
' -- will wait if queue is full

Push_Queue:
  DO WHILE ( qSize = 8 )                        ' is queue full?
    GOSUB Pop_Queue                             '  wait for room
  LOOP
  queue(head) = sfx                             ' put item into queue
  head = (head + 1) & %00000111                 ' advance pointer
  qSize = qSize + 1                             ' update size
  RETURN

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

' Waits for AP-8 to finish present segment and plays next

Pop_Queue:
  DO
    PAUSE 50
    GOSUB Check_AP8
  LOOP WHILE (Playing = Yes)                    ' let segment finish
  IF (qSize > 0) THEN
    GOSUB Play_Next
  ENDIF
  RETURN

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

' Gets the AP-8's present status

Check_AP8:
  SEROUT Sio, Baud, ["!AP8", %00, "G"]          ' get status
  SERIN  Sio, Baud, [status]
  RETURN

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

' Plays next segment in queue

Play_Next:
  sfx = queue(tail)                             ' pull item from queue
  tail = (tail + 1) & %00000111                 ' advance pointer
  qSize = qSize - 1                             ' update size
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]     ' play audio
  RETURN

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


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


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


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

mzitterk

Johnny M.

Made same changes as last program.  I seem to be locked in a loop,  There is an audio sound coming from AP-8 ...Just white noise..., not sure why!. I'm going to back track to see if I can locate the command causing the problem. Also am unable to que any of the audio sections.




JonnyMac

Sorry, I wrote it off the top of my head while having lunch at my desk.  You may want to break it into sections just to test the queuing and dequeuing, then worry about sending play commands to the AP-8.
Jon McPhalen
EFX-TEK Hollywood Office

mzitterk

Thanks, that's what I'm working on now. For being an old fashioned transister, tube guy, I'm sure getting a kick out of this stuff.

mzitterk

Jonny Mac,

I think i found the looping problem in the following subroutine. By changing the IF (keys <> %0000000) THEN,  toIF (keys <>%11111111) THEN, also appears to work with <=%11111111     both seem to allow  the program  to work, now trying to understand why?

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

' Scans/debounces active-high inputs on P0..P7
' -- debounced inputs in "keys"

Read_Keys:
  keys = %11111111                              ' assume pressed
  FOR idx = 1 TO 10
    keys = keys & Keyboard
    PAUSE 5
  NEXT
  IF (keys <> %0000000) THEN           
    hasKey = Yes
  ENDIF
  RETURN

JonnyMac

That routine assumes that you are using active-high inputs; this means that an input that is not pressed will read as zero -- so you have to have pull-downs on every input (P0..P7).  If you don't have pull-downs the floating input may occasionally read as a [false] one.
Jon McPhalen
EFX-TEK Hollywood Office

mzitterk