November 22, 2024, 03:53:10 PM

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.


Need help with program.

Started by Vasago, October 12, 2008, 01:53:17 PM

Previous topic - Next topic

Vasago

October 12, 2008, 01:53:17 PM Last Edit: October 13, 2008, 02:11:34 PM by JonnyMac
Hi Jon,

In the following code, the problem only appears after some use.  Basically it will trigger "n" number of times and then will get stuck on   Beacon = IsOn in the main routine.  The only way to make it work again is to power down and restart again.  Thanks for looking into this. Here is the code:


'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  AllOff          = %00000000

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL   relays         = B0
SYMBOL    BlueLight     =  BIT0
SYMBOL    Beacon        =  BIT1
SYMBOL    Mister        =  BIT2
SYMBOL    UnusedK4      =  BIT3

SYMBOL  status          = B1
SYMBOL   playing        =  BIT15

SYMBOL  timer           = B2                    ' for PIR debouncing
SYMBOL  sfx             = B3                    ' audio segment
SYMBOL  last            = B4                    ' last played
SYMBOL  mask            = B5                    ' bit mask for selection
SYMBOL  check           = B6                    ' for testing play list
SYMBOL  playList        = B7                    ' sounds played

SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = AllOff
  DIRS = %00000000

  SEROUT Sio, OT2400, ("!!!!!!!AP8", %00, "X")  ' kill audio

  relays = AllOff
  BlueLight = IsOn
  GOSUB Update_RC4

  PAUSE 30000                                   ' quiet time
  timer = 0                                     ' clear PIR timer


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

Main:
  RANDOM lottery                                ' stir random value
  PAUSE 10
  timer = timer + 10 * PIR                      ' update timer
  IF timer < 250 THEN Main                      ' wait for valid signal

  BlueLight = IsOff
  GOSUB Update_RC4
  PAUSE 3000

  Beacon = IsOn
  GOSUB Update_RC4
  PAUSE 2000

Select_Sound:
  RANDOM lottery                                ' re-stir
  sfx = lottery // 8                            ' make 0..7
  IF sfx = last THEN Select_Sound               ' no repeats allowed
  READ sfx, mask                                ' get bit mask
  check = playList & mask                       ' check agains play list
  IF check > 0 THEN Select_Sound                ' if played, try again
    playList = playList | mask                  ' mark play list
    last = sfx

  SEROUT Sio, OT2400, ("!AP8", %00, "P", sfx)   ' start audio

Let_Sound_Finish:
  PAUSE 100
  SEROUT Sio, OT2400, ("!AP8", %00, "G")        ' get status
  SERIN  Sio, OT2400, status
  IF playing = Yes THEN Let_Sound_Finish

  Mister =  IsOn
  GOSUB Update_RC4
  PAUSE 5000

  Mister =  IsOff
  GOSUB Update_RC4
  PAUSE 3000

  Beacon = IsOff
  GOSUB Update_RC4
  PAUSE 2000

  relays = AllOff
  GOSUB Update_RC4
  PAUSE 2000

  IF playList <> %11111111 THEN Reset           ' all played?
    playList = %00000000                        ' reset play list
    GOTO Reset


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

Update_RC4:
  SEROUT Sio, OT2400, ("!RC4", %00, "S", relays)
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

Bit_Mask:
  EEPROM (%00000001, %00000010, %00000100, %00001000)
  EEPROM (%00010000, %00100000, %01000000, %10000000)

JonnyMac

I think the problem was your status variable: you were using B8 and BIT15 is not a part of B8, it is part of B1 -- see the fix above.
Jon McPhalen
EFX-TEK Hollywood Office

Vasago

Jon,

That was fast response.  Thanks so much.  I'll stress it out and let you know if all is well.

Thanks Again!


Vasago

Jon,

I get about 6 or seven clean triggers of the prop before I need to restart it again.  Almost feels like once all the music is cycled through the reset doesn't take place.  Any thoughts?

Thanks.








JonnyMac

Okay, fournd the problem -- it seems that "last" was not getting set to "sfx" at the end of the Select_Sound section the way it should.  I corrected the listing above.
Jon McPhalen
EFX-TEK Hollywood Office

Vasago



Works perfectly!!! 

Thanks for your support Jon!!!