LED Clock: Programming the A6276 LED Driver

Banging Bits

I got the LogoChip controlling the A6276 tonight. I programmed from the bottom up, writing code to bang the bits first, and ending up with . . . not much more than code to bang bits. It’s really pretty easy–put the bit on the line feeding the serial data input, strobe the clock line (active high), and when you’re ready strobe the latch line (also active high) to copy the data to the output register.

I started out using pins A0 – A2 for the control lines, and for some reason I still haven’t figured out, they didn’t work. I could set the data bit (A0) high; but every time I toggled the clock line (A1), the data line fell low again, preventing me from shifting a 1 into the input register. Huh?? When I moved the lines to B0 – B2, they worked fine without any other changes to the code. Huhuuuhhhh?????

Strobing Clock and Latch Lines

Given that the 6276 can shift data at 10Mhz, the LogoChip PIC is running on its internal 10MHz oscillator, each PIC operation takes at least one clock cycle, and each Logo instruction probably takes several PIC operations, I should be pretty safe toggling the clock and latch lines high on one instruction and low on the next without a delay in between. I did test with mwaits in between, but it really didn’t make any difference except to slow it down. I guess conceivably I could see problems when I’m trying to shift real data later, so I’ll keep it in mind.

The Code

Here’s what I ended up with:

  • a6276.txt – Program to control Allegro MicroSystems A6276 LED driver

Here’s the code:

;   a6276.txt
;   20-Jun-2006  Keith Neufeld
;   Drive an Allegro MicroSystems A6276 constant-current LED driver chip.
;   The chip takes three inputs:
;   A0  serial data in (SDI)
;   A1  clock (CK)
;   A2  latch enable (L)

;   Debug system

constants [[debug 0]]
;constants [[debug 1]]

;   Section to manipulate A6276.

constants [
    [a6276-sdi-port portb] [a6276-sdi-ddr portb-ddr] [a6276-sdi-bit 0]
    [a6276-ck-port portb] [a6276-ck-ddr portb-ddr] [a6276-ck-bit 1]
    [a6276-l-port portb] [a6276-l-ddr portb-ddr] [a6276-l-bit 2]

;   Push one bit into input register.
to a6276-bit :bit
    ;   Put bit on data input port.
    ifelse :bit [
        if debug [ prs "setbit ]
        setbit a6276-sdi-bit a6276-sdi-port     ;   set 1 output
    ] [
        if debug [ prs "clearbit ]
        clearbit a6276-sdi-bit a6276-sdi-port   ;   set 0 output

    ;   Clock it.
    setbit a6276-ck-bit a6276-ck-port   ;   rising edge
    clearbit a6276-ck-bit a6276-ck-port ;   falling edge

;   Latch input register to output register
to a6276-latch
    setbit a6276-l-bit a6276-l-port     ;   rising edge
    clearbit a6276-l-bit a6276-l-port   ;   falling edge

;   Turn off all LEDs.
to a6276-off
    repeat 16 [ a6276-bit 0 ]

;   Initialize port settings and turn off all LEDs.
to a6276-init
    clearbit a6276-sdi-bit a6276-sdi-port       ;   zero data input
    clearbit a6276-ck-bit a6276-ck-port ;   zero clock
    clearbit a6276-l-bit a6276-l-port   ;   zero latch enable

    clearbit a6276-sdi-bit a6276-sdi-ddr        ;   set pins as outputs
    clearbit a6276-ck-bit a6276-ck-ddr
    clearbit a6276-l-bit a6276-l-ddr

    a6276-off                           ;   turn off all LEDs

;   Routines to tie it all together

to init-all

to powerup

to startup

Oh, and One More Thing . . .

The blue LEDs are still bright.

Leave a Reply