November 23, 2024, 12:00:40 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.


FC-4 sample program

Started by David, September 01, 2008, 11:12:35 AM

Previous topic - Next topic

David

Is there a sample program (test code) for a FC-4 Lamp Fader Control Board? The website only has samples for the Prop-1 and Prop-2.

JonnyMac

September 01, 2008, 12:30:06 PM #1 Last Edit: September 03, 2008, 09:05:43 AM by JonnyMac
Give this a try.  My hardware is presently tied up so I'm not able to fully test, but having written hundreds of SX/B programs I feel pretty confident this will work for you (remember, you have to remove the ULN influence from P15).  Note, too, that the SX doesn't have DEBUG like the BS1 or BS2, so this program runs without telling you what it's doing.

Some of you are looking at this and thinking, "Man, that's a lot of work!"  Yes, it is in a way, but it's like going from an automatic transmission to a manual transmission: you get a lot more performance when you need it, and the SX is like a Formula 1 car where the BS1 and BS2 are like nice Volkswagons (great cars, just not that fast).

[Edit] Listing updated 03 SEP 2008


' =========================================================================
'
'   File...... FC-4_Demo.SXB
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 03 SEP 2008
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            20_000_000
ID              "FC-4"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

Sio      PIN   RC.7         ' P15; no ULN, no SETUP


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

Baud      CON   "OT38400"

IsOn      CON   1
IsOff      CON   0


' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

level      VAR   Byte
idx      VAR   Byte




tmpW1      VAR   Word         ' for subs/funcs
tmpB1      VAR   Byte
tmpB2      VAR   Byte
tmpB3      VAR   Byte
tmpB4      VAR   Byte


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS   SUB   1, 2         ' shell for PAUSE

TX_BYTE      SUB   1         ' shell for SEROUT
TX_STR      SUB   2         ' transmit a string

FC4_RESET   SUB   0         ' kill FC-4 outputs
FC4_LEVEL   SUB   2         ' set channel to level
FC4_SET      SUB   4         ' set all channels
FC4_PRESET   SUB   1         ' preset to level
FC4_ALLON   SUB   0         ' all on
FC4_DIGITAL   SUB   1         ' digital control
FC4_FADE   SUB   4         ' fade one channel
FC4_CROSSFADE   SUB   3         ' full cross-fade


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  PLP_A = %0000_0000            ' pull-ups on unused pins
  PLP_B = %0000_0000
  PLP_C = %1000_0000


Main:
  FC4_ALLON
  DELAY_MS 500

  FOR level = 255 TO 0 STEP -1         ' manal fade down (all)
    FC4_PRESET level
    DELAY_MS 20
  NEXT

  FOR idx = %0000 TO %1111         ' digital control
    FC4_DIGITAL idx
    DELAY_MS 150
  NEXT

  FC4_RESET

  FC4_FADE 1, 0, 255, 8            ' fade up ch1, 2048 ms
  DELAY_MS 2_500

  FC4_CROSSFADE 1, 4, 8            ' cross-fade, ch1 to ch4
  DELAY_MS 3_000

  FC4_FADE 4, 255, 0, 2            ' fade down ch4, 512 ms
  DELAY_MS 2_000

  GOTO Main



' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

' Use: DELAY_MS duration
' -- duration in milliseconds
' -- shell for PAUSE

SUB DELAY_MS
  ASM
    SB   __PARAMCNT.1            ' skip if word value
    CLR  __WPARAM12_MSB            ' clear MSB if byte value
  ENDASM

  PAUSE __WPARAM12
  ENDSUB

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

' Use: TX_BYTE value
' -- transmit one byte at Baud on Sio
' -- shell for SEROUT

SUB TX_BYTE
  SEROUT Sio, Baud, __PARAM1
  PAUSEUS 25               ' insert extra stop bit
  ENDSUB

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

' Use: TX_STR value [string | Label]
' -- transmit a string (inline or z-string at Label)

SUB TX_STR
  tmpW1 = __WPARAM12            ' capture address of string

  DO
    READINC tmpW1, __PARAM1         ' get a character
    IF __PARAM1 = 0 THEN EXIT         ' if 0, we're done
    TX_BYTE __PARAM1            ' otherwise, send it
  LOOP
  ENDSUB

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

' Use: FC4_RESET
' -- kills all FC-4 outputs
' -- assumes FC-4 at address %00

SUB FC4_RESET
  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "X"               ' kill all outputs
  ENDSUB

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

' Use: FC4_LEVEL channel, level
' -- sets channel to specified level
' -- assumes FC-4 at address %00

SUB FC4_LEVEL
  tmpB1 = __PARAM1            ' capture channel
  tmpB2 = __PARAM2            ' capture level

  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "L"
  TX_BYTE tmpB1
  TX_BYTE tmpB2
  ENDSUB

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

' Use: FC4_SET level1, level2, level3, level4
' -- sets outputs to specified levels
' -- assumes FC-4 at address %00

SUB FC4_SET
  tmpB1 = __PARAM1            ' capture levels
  tmpB2 = __PARAM2
  tmpB3 = __PARAM3
  tmpB4 = __PARAM4

  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "S"
  TX_BYTE tmpB1
  TX_BYTE tmpB2
  TX_BYTE tmpB3
  TX_BYTE tmpB4
  ENDSUB

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

' Use: FC4_PRESET level
' -- sets all outputs to level
' -- assumes FC-4 at address %00

SUB FC4_PRESET
  tmpB1 = __PARAM1            ' capture preset level

  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "P"
  TX_BYTE tmpB1
  ENDSUB

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

' Use: FC4_ALLON
' -- sets all outputs to 100%
' -- assumes FC-4 at address %00

SUB FC4_ALLON
  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "A"
  ENDSUB

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

' Use: FC4_DIGITAL
' -- sets outputs to 0% or 100%; based on bits passed (like RC-4 "S" cmd)
' -- assumes FC-4 at address %00

SUB FC4_DIGITAL
  tmpB1 = __PARAM1 & $0F         ' capture digital bits

  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "D"
  TX_BYTE tmpB1
  ENDSUB

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

' Use: FC4_FADE channel, start, end, step_time
' -- fades channel from start to end, in step_time (ms) increments
' -- assumes FC-4 at address %00

SUB FC4_FADE
  tmpB1 = __PARAM1            ' channel
  tmpB2 = __PARAM2            ' start level
  tmpB3 = __PARAM3            ' end level
  tmpB4 = __PARAM4            ' step time (milliseconds)

  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "F"               ' cross-fade
  TX_BYTE tmpB1               ' channel
  TX_BYTE tmpB2               ' start level
  TX_BYTE tmpB3               ' end level
  TX_BYTE tmpB4               ' step time
  ENDSUB

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

' Use: FC4_CROSSFADE channel_A, channel_B, step_time
' -- does full crossfade from channel_A to channel_B
' -- assumes FC-4 at address %00

SUB FC4_CROSSFADE
  tmpB1 = __PARAM1            ' channel (100% to 0%)
  tmpB2 = __PARAM2            ' channel (0% to 100%)
  tmpB3   = __PARAM3            ' step time (milliseconds)

  TX_STR  "!FC4"
  TX_BYTE %00
  TX_BYTE "C"               ' cross-fade
  TX_BYTE 0               ' type 0 (full)
  TX_BYTE tmpB1               ' "a" channel
  TX_BYTE tmpB2               ' "b" channel
  TX_BYTE tmpB3
  ENDSUB


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

David

Thanks for the help. Definitley a bit more complicated than programming a Prop-1.

When I try to run the program I am getting an error message that says "SX Blitz does not support this function".

JonnyMac

Yes, the Prop-SX is more work (initially) to program than the Prop-1 or Prop-2; that said, it offers infinitely more horsepower and for me, is the processor of choice.

You cannot run the Prop-SX from the Blitz, you can only program it.  What this means is that you need to install a 20 MHz resonator into the Prop-SX (the three-pin socket is located between the SX programming header and the DB-9 connector) and then use the Program command from the IDE.  If all goes well the SX-Blitz will reset the controller and your program will start.  If not, you may need to press the reset button on your Prop-SX (I just ran the [updated] demo with the Blitz and it started on its own).

Note that I updated the listing; sorry, found a small typo.  Today I was able to free up my FC-4 demo board actually run the code.  It's now working as I intended.
Jon McPhalen
EFX-TEK Hollywood Office