Shop OBEX P1 Docs P2 Docs Learn Events
Light Controller Problem — Parallax Forums

Light Controller Problem

lboucherlboucher Posts: 139
edited 2009-03-13 04:00 in General Discussion
HI Everyone

So i am really new to SX and assembly.

I am trying to make an SX christmas light controller. (Actually several connected together)
So out of the 20 IO pins on the SX28 i plan to have 17 light channels, 1 rx serial line from a laptop, 1 tx serial line to the next microcontroller in the in the sequence, and 1 zero cross detector.

I have not implimented the serial tx yet.

So far i have implimented an interrupt based serial receive, and dimming control for 4 channels.
This works just fine.

When i try to take this same code and ramp up to 17 channels it doesn't work.
I am thinking i am doing something wrong with banking?

I really don't know how to debug this problem and need help.

I have attached my code for the working 4 channel controller and the non working 17 channel controller.
Please help.

Comments

  • PJMontyPJMonty Posts: 983
    edited 2009-03-12 06:32
    lboucher,

    Since SX/B arrays can only have 16 entries (if I remember), just try expanding up to a 16 channel dimmer. Yes, you'll have a spare pin unused, but I have a feeling it will make all your code work without a lot of effort.

    Thanks,
    PeterM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-03-12 09:46
    You need at least to set the correct bank in the interrupt routine.
    I did it for you in the attachement.

    SXB does support large arrays on sx28,so you could use
    level var byte (17) span
    acc var byte (17) span
    for index = 0 to 16
    · acc(index) = acc(index) + level(index)
    next

    But this does generate slightly more code due to the spanned arrays.

    regards peter
  • lboucherlboucher Posts: 139
    edited 2009-03-12 12:45
    Thanks i will have to try this late tonight after work.
    Why do i only need to set the right bank in the interrupt routine, do i not also have to worry about the main program?

    Thanks
    LUcas
  • ZootZoot Posts: 2,227
    edited 2009-03-12 14:11
    Because the FSR (which is the register that determines what bank you are "working in") is saved and restored automatically by the SX at the hardware level upon entering/leaving the ISR. So is W and STATUS (but not M nor any other normal registers).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-03-12 17:15
    Since your code seems to be using some of my code -- which I "liberated" from someone else -- I've updated the base of your program. I don't have anything to test this on so I'll leave it to you. Since you're using all of RC and RB the strategy employed in this version uses fewer cycles to handle those ports.

    If you use RS-485 or some other multi-drop scheme you may not need to implement TX.

    [noparse][[/noparse]Edit] Inserted required BANK statements.

    Post Edited (JonnyMac) : 3/12/2009 9:48:08 PM GMT
  • lboucherlboucher Posts: 139
    edited 2009-03-12 21:08
    Thanks, and thanks for the original code.

    I am implimenting Renard Version 1 by the way.

    Looking at this breifly at work i have questions.

    first of which is, why is there no "bank" statements don't ya need them?

    What does the Delay MS sub function do?
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-03-12 21:44
    Sorry, I was not quite awake when I wrote that and the Starbucks had not kicked in! I fixed the post above.

    DELAY_MS is a replacement for PAUSE in case you want to do some stand-alone sequencing and need a way to do accurate delays. If you want to hold the program for one second you do this:

    DELAY_MS 1000

    If you use PAUSE the delay won't be accurate because the ISR will extend the timing. BTW, in my updated program I recoded DELAY_MS and RX_BYTE in Assembly.

    Post Edited (JonnyMac) : 3/12/2009 10:18:22 PM GMT
  • lboucherlboucher Posts: 139
    edited 2009-03-13 04:00
    Thanks all, up and running great.
    Even have the TX implimented, i think it is working, but need to set up a second SX chip to be sure.
Sign In or Register to comment.