November 23, 2024, 05:15:02 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.


Advice for a newbie

Started by chuck, July 19, 2008, 05:42:19 AM

Previous topic - Next topic

JonnyMac

Okay, give this a look.  I've moved the program states into a data table and have a run-time engine that processes them.  This is a fairly-sophisticated program for a Prop-1, and demonstrates that it can do neat things when you push it.

' =========================================================================
'
'   File...... Bike_Starter_v2.BS1
'   Purpose... Automate BMX starting gate
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 17 AUG 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Start           = PIN6                  ' SETUP = DN
SYMBOL  Reset           = PIN5
SYMBOL  Gate            = PIN4
SYMBOL  GreenLight      = PIN3
SYMBOL  AmberLight2     = PIN2
SYMBOL  AmberLight1     = PIN1
SYMBOL  RedLight        = PIN0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

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

SYMBOL  IsDown          = 1
SYMBOL  IsUp            = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  btns            = B0
SYMBOL   startBtn       =  BIT0
SYMBOL   resetBtn       =  BIT1

SYMBOL  status          = B1
SYMBOL   playing        =  BIT15

SYMBOL  idx             = B2                    ' loop controller
SYMBOL  pntr            = B3                    ' EEPROM pointer
SYMBOL  tPins           = B4                    ' temporary pins
SYMBOL  sfx             = B5                    ' sound file
SYMBOL  tmrSpan         = B6                    ' timer span
SYMBOL  tmrMin          = B7                    ' timer minimum
SYMBOL  check           = B8                    ' for testing sfx bit7

SYMBOL  lottery         = W5                    ' random value


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

Setup:
  PINS = %00000000                              ' clear all pins
  DIRS = %00011111                              ' make P0-P4 outputs

  IF Reset = Yes THEN Setup                     ' force reset release


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

Main:
  RANDOM lottery                                ' stir random value
  GOSUB Scan_Buttons                            ' check start and reset btns
  IF resetBtn = Yes THEN Reset_Warning
  IF startBtn = No THEN Main

  pntr = 0                                      ' reset data pointer

Get_Record:
  READ pntr, tPins
  pntr = pntr + 1
  READ pntr, sfx
  pntr = pntr + 1
  READ pntr, tmrSpan
  pntr = pntr + 1
  READ pntr, tmrMin
  pntr = pntr + 1

Set_Outputs:
  IF tPins > 127 THEN Hold_For_Reset
    PINS = tPins & %00011111                    ' set outputs

Check_Audio:
  IF sfx = $FF THEN Set_Timing                  ' $FF = no audio
  check = sfx                                   ' make copy
  sfx = sfx & %111                              ' make sfx legal
  GOSUB Play_Audio
  check = check & %10000000                     ' hold bit set?
  IF check = 0 THEN Set_Timing                  ' skip if no

Audio_Hold:
  GOSUB Scan_Buttons
  IF resetBtn = Yes THEN Reset_Warning
  SEROUT Sio, Baud, ("!AP8", %11, "G")          ' get status
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Hold

Set_Timing:
  IF tmrSpan = tmrMin THEN Run_Timer            ' if same, just run
    tmrSpan = lottery // tmrSpan + tmrMin       '  else randomize

Run_Timer:
  IF tmrSpan = 0 THEN Get_Record                ' timer expired?
    GOSUB Scan_Buttons                          ' no, check buttons
    IF resetBtn = Yes THEN Reset_Warning        ' abort on Reset
    tmrSpan = tmrSpan - 1                       ' update timer
    GOTO Run_Timer

Hold_For_Reset:
  GOSUB Scan_Buttons
  IF resetBtn = No THEN Hold_For_Reset

Reset_Warning:
  sfx = 3
  GOSUB Play_Audio
  GOTO Setup


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

' Scans and debounces start and reset buttons
' -- creates 33 ms delay for base timing

Scan_Buttons:
  RANDOM lottery                                ' stir random value
  btns = %11                                    ' assume pressed
  FOR idx = 1 TO 11
    btns = PINS / 32 & btns
    PAUSE 3
  NEXT

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

Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %11, "P", sfx)
  RETURN


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

' Audio
' -- $FF = no audio
' -- 0 to 7 = audio file
' -- 0 to 7 plus 127 = audio, hold until finished
'
' Timing
' -- 33 millisecond units
' -- if times same, use that timing
'     otherwise randomize
'
'                 +---------------------------- pins
'                 |    +----------------------- audio
'                 |    |    +------------------ timing (span)
'                 |    |    |    +------------- timing (minimum)
'                 |    |    |    |
Sequence:
  EEPROM (%00000000, $FF, 091, 091)             ' wait 3 secs
  EEPROM (%00000000, 127, 000, 000)             ' sfx 0, hold
  EEPROM (%00000000, $FF, 082, 003)             ' randomized time
  EEPROM (%00000000, 001, 023, 023)             ' sfx 1, 750 ms delay
  EEPROM (%00000001, $FF, 002, 002)             ' red
  EEPROM (%00000010, $FF, 002, 002)             ' amber 1
  EEPROM (%00000100, $FF, 002, 002)             ' amber 2
  EEPROM (%00011000, $FF, 076, 076)             ' green + gate, 2500 ms
  EEPROM (%00010000, $FF, 000, 000)             ' green off
  EEPROM (%10010000, $FF, 000, 000)             ' end of sequence
Jon McPhalen
EFX-TEK Hollywood Office

chuck

Hi Jon,

I'm sure they will canonise you one day for all the help you give to people, though not just yet as you keep giving me a headache  ;D I can just about grasp the data table and the run-time engine, though I don't understand some of the numbers and the EEPROM coding, maybe some directed reading. Unfortunately, I don't understand your code sufficiently to hazard a guess as to why it appears not to work. When I load the program and try to run it I only receive a series of clicks through the speakers, both when I power up and when I press the start button. Pressing the reset button produces silence for several seconds then it returns to the clicking sound. I hope this makes some kind of sense to you. I will keep looking at it.

JonnyMac

I'm at a very serious disadvantage without your hardware setup.  Do me a favor, please: ZIP your audio files and send them to my work e-mail account; I will connect everything in the next day or so to see if I can sort it out. 
Jon McPhalen
EFX-TEK Hollywood Office

chuck

September 01, 2008, 02:50:26 PM #18 Last Edit: September 01, 2008, 02:53:49 PM by chuck
Hi Jon,

Sorry, now posted in the right place!

Sorry it’s taken so long to get back to you, I seem to be having problems with all things technical at the moment.

My set-up is like the one in the Prop-1 docs pdf showing the valve connection (though I only have 1 pneumatic ram, I/O 4). I/O 7 to AP-8, 6 to start btn, 5 to reset btn. The other I/O’s are not connected as yet as I have to build the start lights.

It has 24v DC and draws 2W + AP-8. However, I think I may have inadvertently reversed the voltage (a bit), I mistakenly reversed the power leads. That is the only thing I can think of that caused the I/O’s to blow high as everything had been working fine for over a week previously.

JonnyMac

Congratulations, you get to buy a shiny new Prop-1.  Okay, I'm being cheeky, sorry you had the problem.  We can only protect against so much, and 24v applied in reverse is a deal breaker (12 usually is, too).  While you may be able to reprogram the Prop-1 what has probably happened is the the IOs on the interpreter chip have blown.  I just went through this a few weeks ago with my good friend and make-up artist Ralis Kahn -- he reversed a 12v battery to his Prop-1 and did the same thing.

Sorry, Chuck.
Jon McPhalen
EFX-TEK Hollywood Office

chuck

No worries Jon, be as cheeky as you like - I would be if someone else had done it  ;D My own fault for being clumsy, just needed to make sure. Now if only the Dutch guys would get some Prop-1's in I could order a new one and then move on to my next project - Blowing a Prop-SX   :-[

JonnyMac

No more blowing up controllers for you, mate -- you've reached your lifetime quota!
Jon McPhalen
EFX-TEK Hollywood Office

chuck

Quote from: JonnyMac on August 18, 2008, 02:23:55 PM
I'm at a very serious disadvantage without your hardware setup.  Do me a favor, please: ZIP your audio files and send them to my work e-mail account; I will connect everything in the next day or so to see if I can sort it out. 

Hi Guys, Chuckies Back (sorry, couldn't resist). Finally got a new Prop-1 through. Did you ever get the email I sent to you Jon? As I sent someone else an email at the same time and they never got back to I am assuming they didn't get sent (as I was offering to send the other person a $1,000 for something I would have thought they would reply).

JonnyMac

I don't recall -- but September/October is really busy for us and my brain turns to Jello in a hurry.  Now that things have eased up a bit before the Christmas rush, maybe we can get a bike gate program going.
Jon McPhalen
EFX-TEK Hollywood Office