May 18, 2024, 09:11:44 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.


RC-4

Started by T, June 13, 2007, 01:24:27 PM

Previous topic - Next topic

T

Does anyone have documentation that explains how to connect the RC-4, AP-8 and a Prop-1 with the serial connections? I have all three connected (I Think it is right) as serial in accordance with the docs found online at efx-tek.com. However, the docs are not very clear on the correct way to connect these and address them. I have the AP-8 working with the Prop-1. As soon as I add the RC-4 on the bus, the sound no longer plays. Both boards are different addresses and connected via serial daisy chained together. Any thoughts?

See program below:

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

SYMBOL  Sio             = 7                     ' serial I/O
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Ctrl6           = PIN5                  ' relay or valve control
SYMBOL  Ctrl5           = PIN4
SYMBOL  Ctrl4           = PIN3
SYMBOL  Ctrl3           = PIN2
SYMBOL  Ctrl2           = PIN1
SYMBOL  Ctrl1           = PIN0


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

SYMBOL  IsOn            = 1                     ' active-high
SYMBOL  IsOff           = 0


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

SYMBOL  pirTimer        = B2                    ' for PIR debouncing
SYMBOL  mnTimer         = B2                    ' minimum timer value
SYMBOL  mxTimer         = B3                    ' maximum timer value
SYMBOL  span            = B4                    ' random timer range
SYMBOL  sfx             = B5                    ' sound file
SYMBOL  tix             = W4                    ' timer value
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = %00000000                              ' outputs off (low)
  DIRS = %00111111                              ' make outputs

  lottery = 1031                                ' seed random number
  tix = 300                                     ' 30 seconds
  GOSUB Timer                                   ' let PIR stabilize


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

Main:
  pirTimer = 0                                  ' reset the PIR timer

  DEBUG "Waiting...", CR

Wait_For_Victim:
  RANDOM lottery
  pirTimer = pirTimer + 25 * PIR                ' update timer
  IF pirTimer  < 250 THEN Wait_For_Victim       ' wait for 0.25 sec input

  DEBUG "Triggered", CR

Randomized_Delay:
  mnTimer = 5                                    ' delay 0.5 to 2.0 secs
  mxTimer = 20
  GOSUB Random_Timer

Activate_Prop:
Ctrl1 = IsOn
' Ctrl2 = IsOn                                  ' turn on light

'RC-4 ON
  DEBUG "Activate RC-4", CR
  SEROUT Sio, OT2400, ("!RC4", %11, "R",1,1)   ' Lights on

Play_Randomized_Sound:
  GOSUB Random_Sound
  tix = 40                                      ' delay for 2.0 seconds
  GOSUB Timer

Fixed_Delay:
  tix = 20                                      ' delay for 2.0 seconds
  GOSUB Timer

Deactivate_Prop:
  Ctrl1 = IsOff

'RC-4 OFF
  SEROUT Sio, OT2400, ("!RC4", %11, "R",1,0)   ' Lights off


Force_Release_Of_Trigger:
  IF pir = IsOn THEN Force_Release_Of_Trigger

  tix = 50                                      ' 5 second delay RESET
  GOSUB Timer                                   ' between "guests"

  GOTO Main

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

' Put minimum timer value in "mnTimer" and maximum timer value in "mxTimer"
' -- "mxTimer" must be larger than  "mnTimer"
' -- tix will be calculated from those two values
' -- tix value drops through to Timer subroutine

Random_Timer:
  tix = mxTimer - mnTimer + 1                   ' get span
  tix = lottery // tix + mnTimer                ' get random tix in range

  ' no RETURN; drops through to  "Timer"

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

' Put number of 0.1 second units in  "tix" before calling
' --  "tix" is destroyed by this subroutine
' -- maximum delay is 6553.6 seconds

Timer:
IF tix = 0 THEN Timer_Done                    ' expired?
   PAUSE 100                                   ' no, delay 0.1 second
   tix = tix - 1                               ' decrement timer
   RANDOM lottery                              ' restir random value
   GOTO Timer                                  ' check again

Timer_Done:
  RETURN

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

' Plays randomized sound
' -- does not monitor for repeats

Random_Sound:
  RANDOM lottery                                ' stir random value
  sfx = lottery // 8                            ' make 0..7
  SEROUT Sio, OT2400, ("!AP8", %00, "P", sfx)   ' play sound

  DEBUG "Playing sound #", #sfx, CR

  RETURN

JonnyMac

June 13, 2007, 02:50:34 PM #1 Last Edit: June 13, 2007, 02:56:31 PM by JonnyMac
1) Make sure you RC-4 is first in the chain -- it gets power from the Prop-1
2) Check the WRB connector orientation; the marking on the RC-4 is near X1-X4 connectors
3) Test the RC-4 by itself, then plug back into your program
    -- make sure the Prop-1 P7 SETUP jumper is removed
    -- make sure that you've replaced the ULN2803 with a ULN2003 or clipped pin 1 of the ULN2803
4) Replace your jumper wire; they're thin and you may have a broken connection

Notes on your program:

1) Since you're only using on AP-8 and one RC-4 you can set them both to address %00 (A0 and A1 jumpers removed)
    -- the address is per device type, no units in the serial chain
2) You should reset the AP-8 and RC-4 (use the "X" command) at the top of your program in the event the Prop-1 reset button gets pressed
3) You don't need the seed the value of "lottery" as it gets updated in your trigger waiting loop
4) I use the "S" command to change RC-4 relay status as this lets me change all at once (use "X" if you want them all off)
5) You have a 4-second delay after each sound; you could use LOOKUP to get an appropriate delay for each of your sound segments
6) Remove DEBUG statements when everything is working; this just consume code space and time.

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

SYMBOL  Sio             = 7                     ' serial I/O
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Ctrl6           = PIN5                  ' relay or valve control
SYMBOL  Ctrl5           = PIN4
SYMBOL  Ctrl4           = PIN3
SYMBOL  Ctrl3           = PIN2
SYMBOL  Ctrl2           = PIN1
SYMBOL  Ctrl1           = PIN0


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

SYMBOL  IsOn            = 1                     ' active-high
SYMBOL  IsOff           = 0


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

SYMBOL  pirTimer        = B2                    ' for PIR debouncing
SYMBOL  mnTimer         = B2                    ' minimum timer value
SYMBOL  mxTimer         = B3                    ' maximum timer value
SYMBOL  span            = B4                    ' random timer range
SYMBOL  sfx             = B5                    ' sound file
SYMBOL  tix             = W4                    ' timer value
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = %00000000                              ' outputs off (low)
  DIRS = %00111111                              ' make outputs

Reset_Accessories:
  SEROUT Sio, OT2400, ("!!!!!!!AP8", %00, "X","!RC4", %00, "X")

  tix = 300                                     ' 30 seconds
  GOSUB Timer                                   ' let PIR stabilize


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

Main:
  pirTimer = 0                                  ' reset the PIR timer

Wait_For_Victim:
  RANDOM lottery
  pirTimer = pirTimer + 25 * PIR                ' update timer
  IF pirTimer  < 250 THEN Wait_For_Victim       ' wait for 0.25 sec input

Randomized_Delay:
  mnTimer = 5                                    ' delay 0.5 to 2.0 secs
  mxTimer = 20
  GOSUB Random_Timer

Activate_Prop:
Ctrl1 = IsOn

Light_On:
  SEROUT Sio, OT2400, ("!RC4", %00, "S", %0001)

Play_Randomized_Sound:
  GOSUB Random_Sound
  tix = 40                                      ' delay for 2.0 seconds
  GOSUB Timer

Fixed_Delay:
  tix = 20                                      ' delay for 2.0 seconds
  GOSUB Timer

Deactivate_Prop:
  Ctrl1 = IsOff

Light_Off:
  SEROUT Sio, OT2400, ("!RC4", %00, "X")

Force_Release_Of_Trigger:
  IF PIR = IsOn THEN Force_Release_Of_Trigger

  tix = 50                                      ' 5 second delay
  GOSUB Timer                                   ' between "guests"

  GOTO Main

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

' Put minimum timer value in "mnTimer" and maximum timer value in "mxTimer"
' -- "mxTimer" must be larger than  "mnTimer"
' -- tix will be calculated from those two values
' -- tix value drops through to Timer subroutine

Random_Timer:
  tix = mxTimer - mnTimer + 1                   ' get span
  tix = lottery // tix + mnTimer                ' get random tix in range

  ' no RETURN; drops through to  "Timer"

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

' Put number of 0.1 second units in  "tix" before calling
' --  "tix" is destroyed by this subroutine
' -- maximum delay is 6553.6 seconds

Timer:
IF tix = 0 THEN Timer_Done                    ' expired?
   PAUSE 100                                   ' no, delay 0.1 second
   tix = tix - 1                               ' decrement timer
   RANDOM lottery                              ' restir random value
   GOTO Timer                                  ' check again

Timer_Done:
  RETURN

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

' Plays randomized sound
' -- does not monitor for repeats

Random_Sound:
  RANDOM lottery                                ' stir random value
  sfx = lottery // 8                            ' make 0..7
  SEROUT Sio, OT2400, ("!AP8", %00, "P", sfx)   ' play sound
  RETURN
Jon McPhalen
EFX-TEK Hollywood Office

davisgraveyard

Thanks for the info Jon I have a very similar setup.  It has been working for me but I added your suggestions for reseting at the beginning and using the "S" command to turn on and the "X" to turn off the RC4 relay instead of the "R" command.  Also didn't know about the address per device type. 

Couple of questions.

What is with all the "!"'s in this line
SEROUT Sio, OT2400, ("!!!!!!!AP8", %00, "X","!RC4", %00, "X")

Also does this have to be done?
   -- make sure that you've replaced the ULN2803 with a ULN2003 or clipped pin 1 of the ULN2803

I didn't do it on my setup and my RC4 and AP8 are working fine?  The AP8 is first in the chain and then the RC4. 

Jeff







JonnyMac

The use of

  SEROUT Sio, OT2400, ("!!!!!!!AP8", %00, "X","!RC4", %00, "X")

is real conservative programming on my part.  What if the AP-8 or RC-4 was in the middle of receiving a command when you press the reset button?  The AP-8 or RC-4 would still be waiting for the rest of the command characters, but the reset action on the Prop-1 would prevent that.  So the "!!!!!!" pad at the beginning of the string clears any pending command input so that the device can get back to the beginning and accept the rest of the string as it normally would.

We have found that the input side of the ULN puts enough of a load on the serial line to swamp it, cause unreliable communications.  Don't take a chance; repalce the ULN2803 with the ULN2003 or remove pin 1 of the ULN2803

The RC-4 gets its power from the Prop-1 (or Prop-2) so it should come first in the chain.  On the boards that have their own power supplies the R pin on the serial header don't connect to anything, so power is not passed through -- this is something we're changing as we update our boards.  The safest thing, then, is to connect the RC-4(s) to the Prop-1, then any other device to the RC-4.
Jon McPhalen
EFX-TEK Hollywood Office

davisgraveyard

OK now the extra "!!!!!" make sense even if it is a bit conservative.  Beter safe than confused huh?

Well I don't have a ULN2003 laying around :) so I guess I remove pin 1.  Just to be certain I am doing this right.  This is the pin with the DOT on it right?  Can I just unseat the ULN2803 and bend pin 1 out so it doesn't get inserted in the socket?  Or should I actually cut the pin off?

Funny but I had my AP8 connected to the Prop-1 and then the RC4 chained to the AP8.  It worked fine?   I can switch it like you suggest but wonder why it worked?



JonnyMac

June 14, 2007, 12:23:29 PM #5 Last Edit: June 14, 2007, 12:25:33 PM by JonnyMac
Don't take a chance on a bent-up pin shoring against something else; cut it off.  I've just created a sticky post at the top of this forum that shows how to modify the ULN2803 or use the ULN2003 -- set it here:

http://www.efx-tek.com/php/smf/index.php?topic=130.0

We've had to fill orders so I don't have the latest version of the AP-8 -- JB may well have connected the Serial.R pins to allow power to pass through it.  I'll know for sure tomorrow when I get one for photography.  Sorry for the confusion, but we felt that customers should get them first and we had a bunch of back-orders to fill.
Jon McPhalen
EFX-TEK Hollywood Office

davisgraveyard

I saw the ULN2003 in the online store so I picked one up along with some Misc stuff I was ordering.  What the heck it is better than cutting of my pin.

So I take it based on your comments that  Prop-1 -> (new) AP8 -> RC4   is not a bad thing?   

I am using a cut-off power end to bring power from the Prop-1 to the AP8 and then it looks like the RC4 is getting power (it works?).    Can I just daisy chain off the RC4 to attach my DC16 when it arrives?




JonnyMac

If your AP-8 is Rev D (has EFX-TEK logo on it) then you can put it in the chain before the RC-4 as the serial.R pins pass power through.  And yes, you can connect your DC-16 to the RC-4 in that chain -- the DC-16 must come after the RC-4.
Jon McPhalen
EFX-TEK Hollywood Office