Hey all, I am having a horrible time trying to interface with the LT8500 part.. it is a new chip that can do 48 channels of pwm right off the chip.
datasheet:
http://www.linear.com/product/LT8500
The trick is, that it wants a strange data set. It wants 48 12-bit data fields and an 8 bit command field. This means that I am changing spi modes from 12 to 8 to write a whole 584 bit stream.
I have verified with a scope that I can get the mbed to switch modes, it drops a 12 pulse spi clock then a 8 pulse command clock.
I can't get the part to actually do anything however. This is really grinding my gears. I am tempted to just bit bang the interface but that seems to be way more effort than needed.
I have a logic analyzer on order and I should be able to get crazy with it soon.
I have been able to verify that SOMETHING is being shifted out of the out pin, but it is not the right data.
Here is my code:
- include "mbed.h"
Ticker PWMCLK;
DigitalOut myClock(p20);
DigitalOut myled(LED1);
DigitalOut led3(LED3);
DigitalOut led2(LED2);
SPI spi(p11, p12, p13); mosi, miso, sclk
DigitalOut LDI(p16);
Serial pc(USBTX, USBRX); tx, rx
const int spiFormat=0;
const int spiFreq = 1000000;
void Pulse()
{
myClock=!myClock;
led2=myClock;
}
void send(){
LDI=0;
LDI=1;
wait_us(2);
LDI=0;
}
void WriteValues(int value){
spi.format(12,spiFormat);
spi.frequency(spiFreq);
int p =0 ;
for (int i = 0;i<48;i++)
{
p=spi.write(i*100);
pc.printf("I just wrote this value: %d and read this one : %d \n",i*100, p);
}
}
int WriteCommand(int Command){
spi.format(8,spiFormat);
spi.frequency(spiFreq);
int spiread = 0;
switch (Command)
{
case 1:output enable
spiread = spi.write(0x30);
case 2: correction frame
spiread = spi.write(0x20);
case 3: asychronus update frame
spiread = spi.write(0x10);
default:
spiread = spi.write(0x00); defaults to sych update
}
send();
return spiread;
}
int main() {
LDI=1;
wait(0.1);
LDI=0;
wait(0.1);
myClock =1;
PWMCLK.attach_us(&Pulse,5);
WriteValues(89);
WriteCommand(2);
WriteValues(287);
WriteCommand(3);
WriteValues(4000);
command = WriteCommand(1);
/*
spi.format(12,spiFormat);
int command =0;
spi.frequency(spiFreq);
for (int i = 0;i<48;i++)
{
pc.printf("value No %d = %X\n", i,spi.write(368));
}
pc.printf("command = %X\n", command);
int counter=0;
led3=1;
while(1) {
int readspi =0;
if (counter >3000)
counter = 0;
else
counter++;
WriteValues(counter);
if (counter==0)
readspi = WriteCommand(1);
else
readspi = WriteCommand(3);
myled=1;
pc.printf("Derp = %X\n", readspi);
wait(0.2);
}
}
Hey all, I am having a horrible time trying to interface with the LT8500 part.. it is a new chip that can do 48 channels of pwm right off the chip. datasheet: http://www.linear.com/product/LT8500 The trick is, that it wants a strange data set. It wants 48 12-bit data fields and an 8 bit command field. This means that I am changing spi modes from 12 to 8 to write a whole 584 bit stream.
I have verified with a scope that I can get the mbed to switch modes, it drops a 12 pulse spi clock then a 8 pulse command clock.
I can't get the part to actually do anything however. This is really grinding my gears. I am tempted to just bit bang the interface but that seems to be way more effort than needed.
I have a logic analyzer on order and I should be able to get crazy with it soon.
I have been able to verify that SOMETHING is being shifted out of the out pin, but it is not the right data.
Here is my code:
Ticker PWMCLK; DigitalOut myClock(p20); DigitalOut myled(LED1); DigitalOut led3(LED3); DigitalOut led2(LED2); SPI spi(p11, p12, p13); mosi, miso, sclk DigitalOut LDI(p16); Serial pc(USBTX, USBRX); tx, rx
const int spiFormat=0; const int spiFreq = 1000000;
void Pulse() { myClock=!myClock; led2=myClock; }
void send(){ LDI=0; LDI=1; wait_us(2); LDI=0;
}
void WriteValues(int value){ spi.format(12,spiFormat); spi.frequency(spiFreq); int p =0 ; for (int i = 0;i<48;i++) { p=spi.write(i*100); pc.printf("I just wrote this value: %d and read this one : %d \n",i*100, p); } }
int WriteCommand(int Command){ spi.format(8,spiFormat); spi.frequency(spiFreq); int spiread = 0; switch (Command) { case 1:output enable spiread = spi.write(0x30); case 2: correction frame spiread = spi.write(0x20); case 3: asychronus update frame spiread = spi.write(0x10); default: spiread = spi.write(0x00); defaults to sych update } send(); return spiread; }
int main() { LDI=1; wait(0.1); LDI=0; wait(0.1); myClock =1; PWMCLK.attach_us(&Pulse,5); WriteValues(89); WriteCommand(2); WriteValues(287); WriteCommand(3); WriteValues(4000); command = WriteCommand(1); /* spi.format(12,spiFormat); int command =0; spi.frequency(spiFreq); for (int i = 0;i<48;i++) { pc.printf("value No %d = %X\n", i,spi.write(368)); }
pc.printf("command = %X\n", command);
int counter=0; led3=1; while(1) { int readspi =0; if (counter >3000) counter = 0; else counter++; WriteValues(counter); if (counter==0) readspi = WriteCommand(1); else readspi = WriteCommand(3); myled=1; pc.printf("Derp = %X\n", readspi);
wait(0.2);
} }