How to send 32 bit command to programmable PWM controller?

1 回表示 (過去 30 日間)
Alexey Onischenko
Alexey Onischenko 2016 年 1 月 1 日
コメント済み: Alexey Onischenko 2016 年 1 月 14 日
Hello! I have Allegro A6281 programmable PWM led controller. Below is the PWM command format, where each PWM counter corresponds each color of LED (r, g, b).
Each color has 10 bits of the 32 bit command word, as shown in the above diagram. The 10 bits allow PWM control of LED brightness to 1024 possible levels. This is only true if the remaining 2 bits are set to zero. I trying to send data directly through raspberry SPI interface. Here is my code:
clear all;
becky = raspi('10.1.2.10', 'pi', ....);
latchPin = 17;
enableSPI(becky);
bSPIdev = spidev(becky, 'CE0');
writeDigitalPin(becky, latchPin, 0);
writeDigitalPin(becky, latchPin, 1);
spi_response = writeRead(bSPIdev, [1023 1023 0 0]) %trying to light up just two colors
writeDigitalPin(becky, latchPin, 0);
%The LI (Latch Input) pin causes the LED controller to accept whatever is in its shift register as a new %command. If you send the LI pin high and then low after 32 clocks, the first ShiftBar in the chain has all %new data from the DI pin.
disableSPI(becky);
But nothing happens =(
What I'm doing wrong?

回答 (1 件)

Venkatachala Sarma
Venkatachala Sarma 2016 年 1 月 14 日
編集済み: Venkatachala Sarma 2016 年 1 月 14 日
Hi,
The process of writing data to the SPI Device is okay. But the data format which writes the control registers may not be right. Try to follow the code available in the following links :
This should be able to help you in setting the data in a proper format in the PWM and current control registers.
Regards,
Venkatachala Sarma
  2 件のコメント
Alexey Onischenko
Alexey Onischenko 2016 年 1 月 14 日
編集済み: Alexey Onischenko 2016 年 1 月 14 日
Thank you very much!
Going to test my solution with the right command.
Also, I rewrote code to be able to send SPI data from Simulink to raspberry. WiringPi makes me happy)
Add:
I made the next code. It crates the 32 bit command word. I decided just to put it into the function writeRead just as-is, without per-bit parsing. Is that correct?
latchPin = 4;
enableSPI(becky);
bSPIdev = spidev(becky, 'CE0');
sendWord = 0;
red = 127;
blue = 33;
green = 33;
control = 1;
ledColors = zeros(3);
if (red < 0); red = 0; end
if (green < 0); green = 0; end
if (blue < 0); blue = 0; end
if (red > 1023); red = 1023; end
if (green > 1023); green = 1023; end
if (blue > 1023); blue = 1023; end
if (control > 0)
ledColors(1) = rem(red, 128);
ledColors(2) = rem(green, 128);
ledColors(3) = rem(blue, 128);
sendWord = bitshift(1, 30);
end
sendWord = bitor(bitor(bitshift(ledColors(3),20),bitor(bitshift(ledColors(1),10),ledColors(2))), sendWord);
%sendWord now is = 1000010000100011111110000100001 (is that require "fliplr()"? or writeRead places first bit from the left of the sendWord to the last place in the register and so on?
spi_response = writeRead(bSPIdev, sendWord)
writeDigitalPin(becky, latchPin, 1);
pause(0.015);
writeDigitalPin(becky, latchPin, 0);
%writeDigitalPin(becky, latchPin, 0);
disableSPI(becky);
I very hope that you will route me to the right path with this freaky thing)
Thank you!
Alexey Onischenko
Alexey Onischenko 2016 年 1 月 14 日
Yes, I really hope, that you will come back)

サインインしてコメントする。

コミュニティ

カテゴリ

Help Center および File ExchangeInstallation Setup and Configuration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by