November 01, 2024, 12:31:28 AM

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.


converting prop 1 to prop 2

Started by fish68, September 10, 2007, 10:18:07 AM

Previous topic - Next topic

fish68

Hi John

This is Todd from the Bates motel.
I talked with you on sunday about converting programs from prop 1 to prop 2
Here is the program I was looking to convert
' =========================================================================
'
'   File...... SP_Template.BS1
'   Purpose... Scare Parts Moby Deluxe
'   Author.... Dale Underwood
'   E-mail.... dunderwood@scareparts.com
'   Started...
'   Updated... 17 AUG 2006
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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

'   Out 0 is the Body Extend Valve
'   Out 1 is the Neck Up and Down Valve
'   Out 2 is the Jaw Valve
'   Out 3 is the Head Left Valve
'   Out 4 is the Head Right Valve
'   Out 5 is the strobe

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


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

SYMBOL  AP8     = 7                             ' serial I/O for AP-8
SYMBOL  Trigger = PIN6                          ' trigger input button
SYMBOL  Valves  = PINS                          ' uses P0..P5 only


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

SYMBOL  Yes     = 1                             ' for active high input
SYMBOL  No      = 0


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

SYMBOL  temp    = B0                            ' value for pins
SYMBOL  fini    = BIT7                          ' sequenced finished
SYMBOL  pntr    = B2                            ' table pointer
SYMBOL  delay   = B3                            ' delay in 1/10 seconds


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

Move_Table:
  EEPROM (%00100001,  18)
  EEPROM (%00110001,   6)
  EEPROM (%00110101,   6)
  EEPROM (%00101001,   7)
  EEPROM (%00101101,   7)
  EEPROM (%00110001,   8)
  EEPROM (%00110101,   7)
  EEPROM (%00101011,   7)
  EEPROM (%00110110,   7)
  EEPROM (%00111011,   7)
  EEPROM (%00110111,   6)
  EEPROM (%00101011,   5)
  EEPROM (%00110101,   5)
  EEPROM (%00110001,   5)
  EEPROM (%00110101,   5)
  EEPROM (%00101011,   5)
  EEPROM (%00101011,   6)
  EEPROM (%00100101,   6)
  EEPROM (%00110111,   6)
  EEPROM (%00100111,   6)
  EEPROM (%00100100,   9)
  EEPROM (%00101000,   3)
  EEPROM (%00100100,  15)
  EEPROM (%00100000,  15)
  EEPROM (%10000000, 100)                       ' 10 sec re-trigger delay


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

Setup:
  DIRS = %00111111                              ' P0..P5 are outputs


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

Main:
  IF Trigger = No THEN Main                     ' wait for trigger
  pntr = 0                                      ' reset to start of table

Start_SFX:                                      ' activate sound
  SEROUT AP8, OT2400, ("!AP8", %00, "P", 0)

Engine:
  READ pntr, temp                               ' read valves from table
  pntr = pntr + 1                               ' point to delay
  READ pntr, delay                              ' read delay from table
  pntr = pntr + 1                               ' point to next record

  Valves = temp                                 ' update the valves outputs
  GOSUB Timer                                   ' hold for timing

  IF fini = Yes THEN Main                       ' sequence done?
    GOTO Engine                                 ' no, continue


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

Timer:
  IF delay = 0 THEN Timer_Exit                  ' delay finished?
    PAUSE 100                                   ' no, hold 1/10 second
    delay = delay - 1                           ' update delay counter
    GOTO Timer                                  ' keep going

Timer_Exit:
  RETURN                                        ' return to caller


Thank you
Fish68

JonnyMac

September 10, 2007, 11:22:20 AM #1 Last Edit: September 10, 2007, 11:25:46 AM by JonnyMac
I see that my pal, Dale, put his name on a program that I wrote for him!  ;D

There are many ways to skin this cat -- the code below is how I'd do it for the Prop-2, and this version will let you sequence up to 12 outputs.  That said, you still have to "paint" the bits into the table manually.  You don't have to do that anymore for this kind of [sequencer] program; that's why we developed the Vixen interface with KC Oaks.  If you're just doing on-off sequencing and need to start an AP-8 at the beginning of the cycle, you can create your program visually with Vixen.

See this thread: http://www.efx-tek.com/php/smf/index.php?topic=140.0

And here's the program translation:

' =========================================================================
'
'   File...... Bates_Seq.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' SETUP = out; no ULN
Trigger         PIN     14                      ' SETUP = DN
Valves          VAR     OUTS                    ' use OUT0 - OUT11


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

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

Yes             CON     1
No              CON     0


#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            ' use fast baud


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

showBits        VAR     Word                    ' value for pins
endOfShow       VAR     showBits.BIT15          ' sequenced finished
pntr            VAR     Byte                    ' table pointer
delay           VAR     Byte                    ' delay in 1/10 seconds


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

Reset:
  OUTS = $0000                                  ' clear valves
  DIRS = $0FFF                                  ' make pins outputs


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

Main:
  IF Trigger = IsOff THEN Main                  ' wait for trigger
  pntr = 0                                      ' reset to start of table

Start_SFX:                                      ' activate sound
  SEROUT Sio, Baud, ["!AP8", %00, "P", 0]

Engine:
  READ pntr, Word showBits, delay               ' get valves + timing
  pntr = pntr + 3                               ' point to next record

  Valves = showBits & $0FFF                     ' update the valves outputs

  DO WHILE (delay > 0)                          ' delay finished?
    PAUSE 100                                   ' no, hold 1/10 second
    delay = delay - 1                           ' update delay counter
  LOOP

  IF endOfShow = IsOn THEN Main                 ' sequence done?
    GOTO Engine                                 ' no, continue


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


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

Movement:
'             *                                 ' * = end of show bit
  DATA  Word %0000000000100001,  18
  DATA  Word %0000000000110001,   6
  DATA  Word %0000000000110101,   6
  DATA  Word %0000000000101001,   7
  DATA  Word %0000000000101101,   7
  DATA  Word %0000000000110001,   8
  DATA  Word %0000000000110101,   7
  DATA  Word %0000000000101011,   7
  DATA  Word %0000000000110110,   7
  DATA  Word %0000000000111011,   7
  DATA  Word %0000000000110111,   6
  DATA  Word %0000000000101011,   5
  DATA  Word %0000000000110101,   5
  DATA  Word %0000000000110001,   5
  DATA  Word %0000000000110101,   5
  DATA  Word %0000000000101011,   5
  DATA  Word %0000000000101011,   6
  DATA  Word %0000000000100101,   6
  DATA  Word %0000000000110111,   6
  DATA  Word %0000000000100111,   6
  DATA  Word %0000000000100100,   9
  DATA  Word %0000000000101000,   3
  DATA  Word %0000000000100100,  15
  DATA  Word %0000000000100000,  15
  DATA  Word %1000000000000000, 100             ' 10 sec re-trigger delay
Jon McPhalen
EFX-TEK Hollywood Office

fish68

Hi John

Notice my name is not on the program it came with a prop.

Randy said he has the vixen program I will look at using it

Thank's

Todd

JonnyMac

Tohdd,

For programs like the one you wanted translated, Vixen will save you a ton of time.  It only takes about 15 minutes to get installed, and you can create programs in moments.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Hello Jon,

I came across this program while finding out what I can all do with the AP-8 hooked up to the Prop-2 and I can see quite a few uses for this program right off the bat.

Anyway I noticed that the front end of this program you created is a bit involved in terms of setting the baud rate in the constants section.

This is what I am referring to:

#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            ' use fast baud


Now I manged to create a template in which I add to my programs in which I want to add sound.

This is what I am using in my constants section for setting the baud.

T2400           CON     396
T38K4           CON     6
Open            CON     $8000

Baud            CON     Open | T38K4

This is working fine for me.   So why is the top one so much more eleborate if this does the same thing? 

Particularly I am curious what the section with all the number (#) signs is for.  Does it have something to do with programming with Vixen?

Thanx,
Geo

livinlowe

Geo-
Those are conditional compiler segments. When you enter your stamp type (BS2, BS2sx, ect) it will automatically use the right constants to get the serial data rates right. Its really cool, in that if you always include those statements, and then switch to a faster Stamp, the baud rate will automatically change (provided you change the ' {stamp xx} directive).

Hope this helps!

Shawn
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

To Shawn's point, my default BS2 template has the Conditional Compilation section so that I can use any BS2-family Stamp.  That fact is that we sell a lot of product to Parallax customers who are using other Stamps, so I try to keep my examples as broad-based as possible.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Ahhh, I see.

So then this basically eliminates having to do conversions by hand then.  So all you have to do is change the program designation as to per BS2-xx family micro-controller you are using and you are set, huh?  That IS cool.   

Too bad this feature couldn't extend to the BS-1, since here the Prop-1 is more popular than the Prop-2.  I have been doing a lot of conversions from the Prop-1 to the Prop2.  Not that that is a bad thing.  In a way it is good because while doing conversions I am also learning how to program the Prop-1 in the event I get an application that doesn't need the full power of the Prop-2.

Thanx for the info.

Geo

JonnyMac

There are too many syntax differences between the BS1 and BS2 for that to work out -- believe me, we talked about it when I was working at Parallax.
Jon McPhalen
EFX-TEK Hollywood Office