May 19, 2024, 01:16:52 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.


Connecting two RC-4s together for light chaser

Started by jukingeo, February 22, 2008, 09:14:47 PM

Previous topic - Next topic

jukingeo

Hello,

I just received my two RC-4 boards today and I am able to configure each board and turn each channel on and off with no problem.

However, when I went back to revisit one of my light chaser programs, I couldn't get it to work across from one board to the next.

I can chase one board easily, but I cannot chase into the next board.

For the record I normally set my chases up to run across 6 channels. 

In a nutshell, I would like this program that Jon wrote for me (and I heavily modified) to run across two RC-4's.

Thank You.

' =========================================================================
'
'   File...... Pattern_Chaser_v6.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'   Revised by Jukin'Geo (added auto pattern change timing loop)
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Speed           PIN     15                      ' SETUP = DN, no ULN
PatSelect       PIN     14                      ' SETUP = DN
Leds            VAR     OUTH


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

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0

timeselect      CON     300                     'set time for pattern change


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

patNum          VAR     Nib                     ' pattern, 0 - 3
pntr            VAR     Word                    ' start of pattern
offset          VAR     Byte                    ' offset into pattern
patLen          VAR     Byte                    ' length of pattern
patbuf          VAR     Word                    ' pattern time buffer

delay           VAR     Word


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

Reset:
  DIRH  = %00111111                             ' make LEDs outputs


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

Main:

FOR patbuf = 1 TO timeselect                    ' auto pattern change
  IF (PatSelect = Pressed) THEN                 ' button pressed?
    Leds = %000000                              ' clear to indicate press
    patNum = patNum + 1 // 7                    ' point to next pattern
    offset = 0                                  ' reset to start
    DO WHILE (PatSelect = Pressed)              ' force release
    LOOP
  ENDIF

  LOOKUP patNum, [Pattern1, Pattern2, Pattern3, Pattern4, Pattern5, Pattern6, Pattern7], pntr
  LOOKUP patNum, [10, 20, 6, 6, 3, 5, 40], patLen

  READ pntr + offset, Leds                      ' update LEDs
  offset = offset + 1 // patLen                 ' adjust offset

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 50                        ' set new range
  PAUSE delay                                   ' hold a bit

NEXT

patNum = patNum + 1 // 7

GOTO main


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


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

Pattern1        DATA    %000001        'Cylon Eye
                DATA    %000010
                DATA    %000100
                DATA    %001000
                DATA    %010000
                DATA    %100000
                DATA    %010000
                DATA    %001000
                DATA    %000100
                DATA    %000010

Pattern2        DATA    %000001       'KITT - Knight Rider
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111110
                DATA    %111100
                DATA    %111000
                DATA    %110000
                DATA    %100000
                DATA    %110000
                DATA    %111000
                DATA    %111100
                DATA    %111110
                DATA    %111111
                DATA    %011111
                DATA    %001111
                DATA    %000111
                DATA    %000011

Pattern3        DATA    %000001       'Standard 6 Chan Chase
                DATA    %000010
                DATA    %000100
                DATA    %001000
                DATA    %010000
                DATA    %100000

Pattern4        DATA    %001110       '3-on 3-off Chase
                DATA    %011100
                DATA    %111000
                DATA    %110001
                DATA    %100011
                DATA    %000111

Pattern5        DATA    %100001       'In to center 3 Chan Chase
                DATA    %010010
                DATA    %001100

Pattern6        DATA    %001100       'Out from center 3 Chan Chase
                DATA    %011110
                DATA    %111111
                DATA    %110011
                DATA    %100001

Pattern7        DATA    %000001       '6 Letter Theatre Marquee
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111111
                DATA    %000001
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111111
                DATA    %000001
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %000000
                DATA    %000000
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %000000
                DATA    %000000
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %111110
                DATA    %111100
                DATA    %110000
                DATA    %100000
                DATA    %000000
                DATA    %000000

JonnyMac

February 22, 2008, 09:21:31 PM #1 Last Edit: February 22, 2008, 09:33:30 PM by JonnyMac
Since you're a good programmer, Geo, let me give you some hints and see if you can get it going -- that's the best way to learn.

Hints:
  -- each RC-4 has four outputs (4 bits)
  -- a nibble is four bits
  -- the BS2 can access the nibbles in a byte using .NIB0 (lower 4 bits) and .NIB1 (upper for bits) notation

Therefore, you could read a pattern into your variable called leds and then transmit it thusly:

  SEROUT Sio, Baud, ["!RC4", 0, "S", leds.NIB0, "!RC4", 1, "S", leds.NIB1]

At 38.4 kBaud this command will take about 3.6 milliseconds; you may want to consider that in your timing.  For the RC-4s to work at 38.4 you must install the B/R jumper.

Give it a shot; if you have trouble I'll update your code tomorrow -- it's time for me to have dinner and call it a day.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

February 23, 2008, 12:08:50 PM #2 Last Edit: February 23, 2008, 12:20:10 PM by jukingeo
Quote from: JonnyMac on February 22, 2008, 09:21:31 PM
Since you're a good programmer, Geo, let me give you some hints and see if you can get it going -- that's the best way to learn.

Oh, gee.  I don't think I can call myself a 'good' programmer yet.  I just started only about a half year ago.   Most of what I did was based on variants of your programs.  I did very little on my own.   As it is the program I presented to convert to RC-4 use is really your program.  I just heavily altered it.   This is one of my favorite programs and I will be using it as the basis for most of my light controller needs.

QuoteHints:
  -- each RC-4 has four outputs (4 bits)
  -- a nibble is four bits
  -- the BS2 can access the nibbles in a byte using .NIB0 (lower 4 bits) and .NIB1 (upper for bits) notation

Ok, so then I WAS on the right track when I tried this.   So this is what I thought:

My positions are decimal 1-6 or as the program shows binary %000000

I had two address to deal with.  One board I set at %00 and the other %11.

Now the issue is that I had to have my chase routine count the nibble positions up to 4 on the first board, and I didn't run into any problems going that far.  But now locations 5 & 6 needed to transfer to the second RC-4 and it has to interpret that as positions 1 and 2 on it's board.

With this in mind, I did reason that I needed to split my byte information up into two nibbles considering that I could only drive up to a nibble's worth of information to drive the relays on a single RC-4.   So I would address positions 1-4 on the first RC-4 (Address %00) and postions 5 & 6 would be a hi nibble routed to the second RC-4 (Address %11).

So I read the portion in the Editor's help section on dealing with dividing down words, bytes, nibbles and bits.   However, I think I may have done something wrong because you mentioned to use Nib0 and Nib1.  I was using HIGHNIB and LOWNIB.   Perhaps that was my problem? 


QuoteTherefore, you could read a pattern into your variable called leds and then transmit it thusly:

  SEROUT Sio, Baud, ["!RC4", 0, "S", leds.NIB0, "!RC4", 1, "S", leds.NIB1]

At 38.4 kBaud this command will take about 3.6 milliseconds; you may want to consider that in your timing.  For the RC-4s to work at 38.4 you must install the B/R jumper.

Give it a shot; if you have trouble I'll update your code tomorrow -- it's time for me to have dinner and call it a day.

Wow, I think about it now and I believe I was so close.  Now I could shoot myself for deleting the program I was working on.  Anyway, I did want to use this to play around with timing to see how fast I can chase the RC-4.  With one board, I got my PAUSE commands down to about 50 (ms).  Below that, the LEDs on the RC-4 don't seem to chase anymore, but flicker.  So more than likely I am reaching the lower speed limit here.   Now I have to see how it behaves with two boards.  But in terms of one board on the Prop-2...a chase is pretty doable.  I am sure that my lower limit will move up a bit when using a Prop-1.

Anyway, I will poke around with this again, but this time using the Nib0 and Nib1 commands instead of what I was using.  Perhaps that is where my problem lies.  But I just realized that  I am confusing the issue with a nibble in regards to my decimal positions and the binary positions.   A nibble counts up to 16 in decimal, not 4.   So I think I ran into a problem there with one of my simpler FOR NEXT counter type chasers.  So I have go back and fix that as well.   But I do prefer a data table chaser and I really wanted to convert the above program because it is such a flexible program.

But I am happy to know that I AM on the right track and I just have to rethink a few minor things.

Thanx,

Geo

jukingeo

Hello Jon,

I was reading into this FAR too much.   In fact since this program uses binary values to begin with it made the conversion SO much easier than it would have been with a FOR NEXT loop I was messing around with.

Anyway the Nib0 and Nib1 was the ticket in this case.  Another problem was that in my first attempt, I used "R" instead of "S" in the RC-4 command line.   So that was another mistake.  So really all I had to do was change my nibble designations and correct the command line to output to the two RC-4's.  It worked first shot.   I can't believe how minor the alterations were!

The program IS running a bit slower due to the serial transmission, but all I had to do was alter the value on the variable control for the delay and I got it to chase pretty quickly.  So this DOES prove that you CAN use chaser effects across multiple RC-4's.  But the catch is that I am using a Prop-2.  Eventually I am going to convert this program for use on a Prop-1.  So I will have to see what the slowdown is using the Prop-1 with this setup.

The point is with the addressability of the RC-4, I can add far more outputs to a Prop-1 than I need, let alone a Prop-2.  So I can save the Prop-2 for more 'heavier' programming...such as the dimming chaser routine we worked on together a while back.   Given that these chase routines are pretty small, a prop-1 is probably more than enough.

But this is looking good.  I just can't believe how close I was on this one.  I just messed up on two little things.

Thanx again, Jon

Anyway, this is the completed program:

' =========================================================================
'
'   File...... Pattern_Chaser_RC-4Drive.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 2-23-2008
'   Revised by Jukin'Geo (added auto pattern change timing loop & RC-4 Drive)
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN      7                      ' Sets RC-4 I/O to Pin 7
Speed           PIN     15                      ' SETUP = DN, no ULN
PatSelect       PIN     14                      ' SETUP = DN

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

Open            CON     $8000
T38K4           CON     6
Baud            CON     Open | T38K4                    ' Sets Baud

Addr1           CON     %00                             ' %00 - %11 1st RC-4 Address
Addr2           CON     %11                             ' %00 - %11 2nd RC-4 Address

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0

timeselect      CON     300                     'set time for pattern change


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

leds            VAR     Byte
  set1          VAR     leds.NIB0
  set2          VAR     leds.NIB1

patNum          VAR     Nib                     ' pattern, 0 - 3
pntr            VAR     Word                    ' start of pattern
offset          VAR     Byte                    ' offset into pattern
patLen          VAR     Byte                    ' length of pattern
patbuf          VAR     Word                    ' pattern time buffer

delay           VAR     Word


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

Reset:

  SEROUT Sio, Baud, ["!RC4", Addr1, "X", "!RC4", Addr2, "X"]  ' all off


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

Main:

FOR patbuf = 1 TO timeselect                    ' auto pattern change
  IF (PatSelect = Pressed) THEN                 ' button pressed?
    leds = %000000                              ' clear to indicate press
    patNum = patNum + 1 // 7                    ' point to next pattern
    offset = 0                                  ' reset to start
    DO WHILE (PatSelect = Pressed)              ' force release
    LOOP
  ENDIF

  LOOKUP patNum, [Pattern1, Pattern2, Pattern3, Pattern4, Pattern5, Pattern6, Pattern7], pntr
  LOOKUP patNum, [10, 20, 6, 6, 3, 5, 40], patLen

  READ pntr + offset, leds                      ' update LEDs
  SEROUT Sio, Baud, ["!RC4", Addr1, "S" , set1, "!RC4", Addr2, "S", set2]  'Display LEDs
  offset = offset + 1 // patLen                 ' adjust offset

Speed_Delay:
  HIGH Speed                                    ' charge RC circuit
  PAUSE 1
  RCTIME Speed, 1, delay                        ' read raw delay
  delay = delay / 3 + 5                         ' set new range
  PAUSE delay                                   ' hold a bit

NEXT

patNum = patNum + 1 // 7

GOTO main


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


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

Pattern1        DATA    %000001        'Cylon Eye
                DATA    %000010
                DATA    %000100
                DATA    %001000
                DATA    %010000
                DATA    %100000
                DATA    %010000
                DATA    %001000
                DATA    %000100
                DATA    %000010

Pattern2        DATA    %000001       'KITT - Knight Rider
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111110
                DATA    %111100
                DATA    %111000
                DATA    %110000
                DATA    %100000
                DATA    %110000
                DATA    %111000
                DATA    %111100
                DATA    %111110
                DATA    %111111
                DATA    %011111
                DATA    %001111
                DATA    %000111
                DATA    %000011

Pattern3        DATA    %000001       'Standard 6 Chan Chase
                DATA    %000010
                DATA    %000100
                DATA    %001000
                DATA    %010000
                DATA    %100000

Pattern4        DATA    %001110       '3-on 3-off Chase
                DATA    %011100
                DATA    %111000
                DATA    %110001
                DATA    %100011
                DATA    %000111

Pattern5        DATA    %100001       'In to center 3 Chan Chase
                DATA    %010010
                DATA    %001100

Pattern6        DATA    %001100       'Out from center 3 Chan Chase
                DATA    %011110
                DATA    %111111
                DATA    %110011
                DATA    %100001

Pattern7        DATA    %000001       '6 Letter Theatre Marquee
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111111
                DATA    %000001
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111111
                DATA    %000001
                DATA    %000011
                DATA    %000111
                DATA    %001111
                DATA    %011111
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %000000
                DATA    %000000
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %000000
                DATA    %000000
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %111111
                DATA    %111110
                DATA    %111100
                DATA    %110000
                DATA    %100000
                DATA    %000000
                DATA    %000000





JonnyMac

We have a little demo for trade shows that shows how to chase 16 channels with four RC-4s;  in that case we read a word out of a DATA tables and send NIB0, NIB1, NIB2, and NIB3 (NIB2 and NIB3 are only valid with Word variables).  That demo has helped us sell a lot of RC-4s to sign makers!

If you use the Prop-1 you'll have to take a different approach, something like this:

  READ pntr, lights
  SEROUT Sio, Baud, ("!RC4", 0, "S" lights)
  lights = lights / 16
  SEROUT Sio, Baud, ("!RC4", 1, "S" lights)


or, if you have variables to spare...

  READ pntr, lights0
  lights1 = lights0 / 16
  SEROUT Sio, Baud, ("!RC4", 0, "S" lights0, "!RC4", 1, "S" lights1)


A couple notes: 1) there is no NIB access in the Prop-1 so to get to the high nibble of a byte you must divide the byte by 16 and, 2) the RC-4 "S" command only uses the lower four bits of the value that sent to it, so it doesn't matter what's in the upper nibble.

Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on February 23, 2008, 02:04:01 PM

If you use the Prop-1 you'll have to take a different approach, something like this:

  READ pntr, lights
  SEROUT Sio, Baud, ("!RC4", 0, "S" lights)
  lights = lights / 16
  SEROUT Sio, Baud, ("!RC4", 1, "S" lights)


or, if you have variables to spare...

  READ pntr, lights0
  lights1 = lights0 / 16
  SEROUT Sio, Baud, ("!RC4", 0, "S" lights0, "!RC4", 1, "S" lights1)


A couple notes: 1) there is no NIB access in the Prop-1 so to get to the high nibble of a byte you must divide the byte by 16 and, 2) the RC-4 "S" command only uses the lower four bits of the value that sent to it, so it doesn't matter what's in the upper nibble.



I got the bit on when using 4 RC-4's that you have to up the variable to word status and then access it using the 4 nibble commands.

What I am not totally clear on is how to do things on the Prop-1 considering the fact there is no nibble access.   Now the divide by 16 is for the use of two RC-4's or all four?  Would that be [variable] / 8 for two boards?  Or how does that work?

For the most part I probably will be using the RC-4s on a Prop-1 because the Prop-2 has the 16 i/o's to begin with.  However, I can see a few applications for the RC-4 in regards to a pinball machine project I am contemplating to do with all control based on Prop-2 (or for that matter Prop-SX) controllers.  But in terms of the output in that case since the drive is mostly small light bulbs, the DC-16 is probably a better bet.

Anyway, thanx for the help.  I can't believe how close I was on that one...only two small things I had out of whack.  Now it runs perfect.  In fact I am making an alternative program that will run the full 8 channels.

Geo



JonnyMac

Sorry if I wasn't clear, nibble access only works on the Prop-2.  With the Prop-1 you have to divide to get to the high nibble of a given byte.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on February 24, 2008, 01:33:00 PM
Sorry if I wasn't clear, nibble access only works on the Prop-2.  With the Prop-1 you have to divide to get to the high nibble of a given byte.

That part I got in that you don't have nibble access on the Prop-1 

What I didn't get was how the divide by 16 thing works.  Is that for using four RC-4's?  If I use 2 boards would that be divide by 8 instead?  That was the part I am not so sure on and if you can clear that up, that would be good.

Thanx,

Geo


JonnyMac

February 24, 2008, 03:57:52 PM #8 Last Edit: February 24, 2008, 03:59:55 PM by JonnyMac
You might want to try an experiment to prove this to yourself.   Here's some Prop-1 code:

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

SYMBOL  testVal         = B2

Main:
  testVal = $A5
  DEBUG $testVal
  testVal = testVal / 16
  DEBUG $testVal
  END


Note how the A shifts from the upper nibble to the lower nibble after the divide.

If you want to use one variable to control 16 lights in a Prop-1, you'll want to do something like this:

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

SYMBOL  relays          = B0

SYMBOL  lights          = W5
SYMBOL   lightsLo       =  B10                  ' low byte of W5
SYMBOL   lightsHi       =  B11                  ' high byte of W5

Main:
  lights = %1110110011110001
  DEBUG "Lights = ", #%lights, CR, CR

  relays = lightsLo & %00001111
  DEBUG "RC-4 #0 = ", #%relays, CR

  relays = lightsLo / 16
  DEBUG "RC-4 #1 = ", #%relays, CR

  relays = lightsHi & %00001111
  DEBUG "RC-4 #2 = ", #%relays, CR

  relays = lightsHi / 16
  DEBUG "RC-4 #3 = ", #%relays, CR

  END




Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Hello,

Thanx Jon for the code.  I don't have a Prop-1 as of yet, but I am going to copy the program you wrote and when I get one I will see how it works then.

I guess I can rearrange the program around to see how it works on the Prop-2.  Once I get a 'feel' for it and see what is happening I can understand it better.

Geo