I'm using an Allegro 6280 PWM LED driver for a project. This is a cool little IC except for the fact that it is a 31 bit long input register. This is no problem if I simply loop through my 31 bits and set the pin states accordingly, but I'm wanting to use the atmega's on-board SPI to speed things up a bit (the 6280 requires an external clock source for it's 10 bit long PWM cycle).
The 31 bit long register looks like this in my application where R,G & B indicate the 10 bit PWM values for the attached LEDs.
0BBBBBBBBBBGGGGGGGGGGRRRRRRRRRR
These shift registers are chainable, so I've built a linked list to represent them:
struct Pixel {
uint16_t red;
uint16_t green;
uint16_t blue;
Pixel *next;
};
So, the idea is to set the latch pin low, iterate through all the Pixels and then after sending the last one set the latch high to latch the data into each register. This would seem easy except that due to the uneven length of the register I have to construct nasty-looking code to be able to loop around to the beginning again so that it never sends any empty bits. Also, the latch might need to happen after an arbitrary number of bits are transmitted, not just the last one.
Does anyone have any ideas on how to get this done, or am I simply barking up the wrong tree and stuck with manually twiddling the pin states?
Thanks.