Go Down

Topic: ShiftPWM support topic. Latest update: Schematics, high power LED's, LED strips (Read 83 times) previous topic - next topic

elcojacobs

To answer another question:
I did not try 96 shift registers in a chain. With the printInterruptLoad() function I can check that the arduino is able to generate the signals, but I don't know if you would run into problems with long load lines. Maybe a buffer (for example two inverters) in series for the clock line would be required.

elcojacobs

On second thought, I might try SPI. It's just a few changes.
The SPI can output the byte while the avr is already calculating the next byte.
I will probably try this next week.

MexWave

Hi Elco,

Thanks very much for sharing this work!

I've tried the example sketch on a 1280-based mega (you asked if someone could try it with a 1280 in your original post?) and found initially it wouldn't compile. To get it to work I (rightly or wrongly) changed line 90 of "pins_arduino_compile_time.h" from:

Code: [Select]
volatile uint16_t * const port_to_output_PGM_ct[] = {

to:

Code: [Select]
volatile uint8_t * const port_to_output_PGM_ct[] = {

I'm not sure if this was correct, because when I run the sketch all three LEDs in the package (I'm currently only using a single RGB LED) seem to stay at a constant brightness. The circuit I've thrown together uses a single 595 and connects:






Arduino Pin595 Pin
814 (SER)
911 (SRCLK)
1012 (RCLK)


It's all running off 3.3v rather than 5v.

Any ideas?

Many thanks,

Mark

steene

Hey,

I think you could do it much faster with SPI.
There's a little trick when calculating the bitvalues
You can calc every bit with only 5 cycles and without branching
you can just use the carry flag result from the cp instruction and shift it to a register, like this:


ldd value
cp value, counter
rol register

(I think the carry flag is set when the counter is greater than the value, so this is exactly what you need for pwm)
So after executing this 8 times you got 8 values packed to one byte. you can now send this with the spi.

when you put your PWM Values in an array you can generate a whole byte with this code:

ldi r20, 8
label:

ld r21, X+
cp r21, counter
rol r22

dec r20
brne label

>> at this point you have a calculated a whole byte (in reg22) with 1+8*(2+2+1+1)+7*2+1 = 1+8*6+14+1 = 64 cycles

(I have not tested it so this might not be completely right but I think you get the idea)








elcojacobs


Hi Elco,

Thanks very much for sharing this work!

I've tried the example sketch on a 1280-based mega (you asked if someone could try it with a 1280 in your original post?) and found initially it wouldn't compile. To get it to work I (rightly or wrongly) changed line 90 of "pins_arduino_compile_time.h" from:

Code: [Select]
volatile uint16_t * const port_to_output_PGM_ct[] = {

to:

Code: [Select]
volatile uint8_t * const port_to_output_PGM_ct[] = {

I'm not sure if this was correct, because when I run the sketch all three LEDs in the package (I'm currently only using a single RGB LED) seem to stay at a constant brightness. The circuit I've thrown together uses a single 595 and connects:






Arduino Pin595 Pin
814 (SER)
911 (SRCLK)
1012 (RCLK)


It's all running off 3.3v rather than 5v.

Any ideas?

Many thanks,

Mark


Ah, thanks for trying this. I think the correction you made is right and that it should be unint8.
The problem could come from running on 3.3V. The atmega1280 has to run on 8 MHz. Please be sure that your code reflects this (F_CPU = 8E6). The calculations for the interrupt load have to be done with 8MHz as well. The built in function uses F_CPU for this.

What does the code report on the serial port?

Go Up