November 26, 2024, 07:29:00 PM

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.


Expanding LED Strobe Controller program

Started by uncle, March 05, 2010, 05:14:48 PM

Previous topic - Next topic

uncle

Jon-

I have finally opened up my Prop-SX after almost 2 years in the box.  I have been able to get the Strobe program to work (using LED's and not trainer which I have misplaced). 

In trying to get a feel for the programming, I have been trying to expand it to 7 or more LED's but haven't had success.  Is there a way to expand the outputs into P0-P7 as well?

JonnyMac

Without seeing your program I can only generalize...  Did you make the extra pins outputs?  Remember, the outputs on the RB port (P0..P7) are controlled by the TRISB register.  If you want to expand to P8..P15 you'll be dealing with the RC port.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Jon-

I have been trying to modify your original Strobe Controller program(below) to expand to the RB side, and have had no luck.  I have read through the Practical SX/B and found one reference to the TRISB register but could not find an example that had it embedded in a program. 

So I will admit that I am completely stumped.




' =========================================================================
'
'   File....... Strobe_Controller.SXB
'   Purpose.... Linear strobe of six outputs
'   Author..... EFX-TEK (www.efx-tek.com)
'   E-mail..... teamefx@efx-tek.com
'   Started....
'   Updated.... 01 JUL 2007
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Creates a linear strobe of six lamps/LEDs on P8..P13; much like airport
' landing lights. Strobing runs when button on P14 is pressed, and rate
' can be adjusted with pot circuit on P15.
'
' Replace the ULN2803A on P8..P15 with a ULN2003A to allow the pot circuit
' on P15 to operate correctly.


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


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

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
FREQ            4_000_000
ID              "Lights"


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

Speed           PIN     RC.7                    ' SETUP = DN; remove ULN
Trigger          PIN     RC.6                    ' SETUP = DN

Lamps           PIN     RC
Lamp6           PIN     RC.5 OUTPUT
Lamp5           PIN     RC.4 OUTPUT
Lamp4           PIN     RC.3 OUTPUT
Lamp3           PIN     RC.2 OUTPUT
Lamp2           PIN     RC.1 OUTPUT
Lamp1           PIN     RC.0 OUTPUT

UnusedRB        PIN     RB   INPUT PULLUP


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

IsOn            CON     1
IsOff            CON     0


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

idx                VAR     Byte                    ' loop index
holdTm          VAR     Word                    ' for timing

tmpW1           VAR     Word                    ' for subs & funcs


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


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

DELAY_MS         SUB     1, 2                    ' delay in milliseconds
GET_SPEED       FUNC    2, 0                    ' read speed pot


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

Start:


Main:
  Lamps = %000000                                 ' clear all
  DO WHILE Trigger = IsOn                       ' run when button pressed
    holdTm = GET_SPEED                           ' read speed setting
    FOR idx = 0 TO 5
      Lamps = 1 << idx                                ' one LED on
      DELAY_MS holdTm
      Lamps = %000000                              ' LED off
    NEXT
  LOOP
  GOTO Main

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

' Use: DELAY_MS mSecs
' -- 'mSecs' is delay in milliseconds, 1 - 65535

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1                               ' save byte value
  ELSE
    tmpW1 = __WPARAM12                          ' save word value
  ENDIF
  PAUSE tmpW1
  ENDSUB

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

' Use: result = GET_SPEED
' -- scales Prop-1 Trainer pot to 50 to 150

FUNC GET_SPEED
  HIGH Speed                                             ' charge cap
  DELAY_MS 1
  RCTIME Speed, 1, tmpW1                        ' measure RC circuit
  tmpW1 = tmpW1 ** $71C7                        ' x 0.44 (max = 100)
  tmpW1 = tmpW1 + 50                             ' set min to 50
  RETURN tmpW1
  ENDFUNC


' -------------------------------------------------------------------------
' User Data
' -------------------------------------------------------------------------

JonnyMac

What we have here is a failure to communicate....

Mea culpa. (my fault)

What -- exactly -- do you want your version to do?  There is no sense posting our code; we wrote and know it works.  Remember, programming a specific enterprise; works like "about", etc. don't count.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Sorry.  I was thinking perhaps there was another program similarly named. 

I can see how the original strobes the 6 LED's, but I have been trying to figure out how to strobe say 8 or more LED's.  I am trying to slowly see how it can be expanded into using both the RC and RB outputs.  I figured this might be a simple way to see/learn how to program both sets of outputs.

JonnyMac

Well, here's the thing: eight or fewer are easy, because they can be on the same port (RB or RC).  If you want to go past eight pins then you have to synthesize a 16-bit port with RB and RC.  In SX/B there is a [synthesized] port called RBC, but there is no equivalent for the TRISx registers (input/output direction).

So... tell me exactly what you want to do and I whip up a demo that you can play with.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Synthesized port RBC sounds like what I was thinking toward. 

It is basically a program that does the Airport Runway/Cylon/Knightrider effect with the LED starting at one end of the array and running through to the other end.  It doesn't necessarily need to reverse direction (though that would probably be interesting), but it needs to use outputs of both RB and RC, so at least 8 LED's. 

Basically I am trying to understand how to use both output sections in the same program, or to expand them into a larger output grouping.  I don't have a specific application I am working on, just trying to get a feel for this aspect of programming the SX.

JonnyMac

Well, let's start "easy" first.  This program does a Cyclon/Knightrider effect with all 16 outputs.  Note how a 16-bit port (RBC) is created in SX/B and all are set to output mode.

' =========================================================================
'
'   File...... Cylon16.SXB
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007-10 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started... 26 JUN 2007
'   Updated... 08 MAR 2010 (updated for SX/B 2.xx)
'
' =========================================================================


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


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


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

ID              "Cylon"

DEVICE          SX28, OSC4MHZ, BOR42
FREQ            4_000_000


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

Eyes            PIN     RBC OUTPUT              ' P0..P15 are outputs


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

Speed           CON     50


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

idx             VAR     Byte

tmpB1           VAR     Byte                    ' for subs/funcs
tmpW1           VAR     Word


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

DELAY_MS        SUB     2, 2,    Word, Word     ' delay in milliseconds


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

Start:
  PLP_A = %0000                                 ' RA bits are not used

Main:
  FOR idx = 0 TO 14                             ' loop P0 to P14
    Eyes = 1 << idx                             ' pin on, others off
    DELAY_MS Speed                              ' wait
  NEXT
  FOR idx = 15 TO 1 STEP -1                     ' loop P15 to P1
    Eyes = 1 << idx
    DELAY_MS Speed
  NEXT
  GOTO Main

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

' Use: DELAY_MS ms
' -- 'ms' is delay in milliseconds, 1 - 65535

SUB DELAY_MS
  PAUSE __wparam12
  ENDSUB

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


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

uncle

Thanks!  This goes a long way in answering a couple of my questions!