ShiftPWM support topic. Latest update: Schematics, high power LED's, LED strips

hi,

i wanted to use Common Anode LED'S with the Shift PWM library what changes should i make to the circuit and in the arduino code.

Thanks :slight_smile:

In the example code, you'll see this:

const bool ShiftPWM_invertOutputs = 1; // if invertOutputs is 1, outputs will be active low. Usefull for common anode RGB led's.

You can toggle whether a high level or a low level will turn on the led with that const int.
I use common anode RGB leds for the example.

More testing.
I was not connecting the full matrix before, so I decided to wire the whole thing up and found something I didn't see before. I now have the full 16x16 mono matrix wired and functions that should be writting to the first row (Row=0) are actually appearing on row 16. It seems that the rows are off by 1. If I tell row one to have a LED turned out (Which should be the second row of the matrix) I get LED's on the first row of the matrix. I did this test this morning before work. I will see if I can look through the code and see where this might be happening. At a guess, I think it would be in the functions for bit banging the Row SR's.

Hi Milamber,

I have changed the code quite a bit, see the attachment. The code is a bit easier to read now I think. I also turn off all LED's before switching rows, but that was a quick edit so I'll still have to double check the new code.

I still have a very strange bug: the second led of the first row is always off and the first row is always softly on. I hope it is a hardware problem, because I have no idea what can cause this in software. It's not a defective LED, because when you set the number of rows to 4 (so it repeats twice) the error is repeated as well. Maybe you can spot the bug.

I have only tested with setAll and the two at a time loop.

I have checked the signals with a scope:

  • The rows perfectly alternate. No gaps in between.
  • The PWM period nicely overlaps with the row switching.

ShiftMatrixPWM.zip (14.5 KB)

Saw your update and had to run a quick test before going to work.
The two functions seem to be working.
But now my rows are back to front, what should be row0 is now row15 and row15 is now row0.
Did you change the most significant bit anywhere, it just seems to be back to front.

Apart from that it seemed to work very well. Obviously I will do more when I get home.
Thanks so much Elco for continuing to look at this. I know this is well beyond the scope of your original project!

Okay milamber,
I changed it back for you. Performance suffers a small bit (187 to 193 clockcycles per interrupt for 8x8), but it is a more logical setup.

I you could check this version, it all seems to work now.
I still have that the last row lights up, but I think there is something wrong with my matrix (it's prefab, so I cannot replace an LED).

The rainbow functions should work as well, but the number of column registers should a multiple of 3.

Do you have a 16x16 RGB matrix? I am very curious how that will look.
If this works well, next step is to add some line drawing functions, or functions to set a field of leds to a value:

DrawLine(startX,startY,endX,endY)
SetField(0b11000011,
            0b11000011,
            0b00000000,
            0b00011000,
            0b00011000,
            0b100000010,
            0b01000010,
            0b00111100,
            63)

ShiftMatrixPWM.rar (13.6 KB)

elcojacobs:
Okay milamber,
I changed it back for you. Performance suffers a small bit (187 to 193 clockcycles per interrupt for 8x8), but it is a more logical setup.

Sorry Elco. I didn't mean for that to be a problem it was just unexpected. I would prefer to see the speed increase versus the logical setup but that just me. It would just mean that in the physical setup the outputs could be connected with Row0 being the last pin and counting up? I don't see an issue with this if notes are included in the comments. Totally up to you Elco, this is your library and I am very thankful for the effort you have put into it.

elcojacobs:
Do you have a 16x16 RGB matrix? I am very curious how that will look.

No sorry I only have a mono matrix. And I don't have enough RGB LED's to attempt hand making one. Although I think I will be trying to order a RGB matrix, as I too would love to see what this looks like even at 8x8 RGB. I think it would look great at 16x16.
I wonder if anyone else out there with a RGB matrix could put a couple of Shift Register together and give it a go?

elcojacobs:
I still have that the last row lights up, but I think there is something wrong with my matrix (it's prefab, so I cannot replace an LED).

Apart from the Row lighting up out of sequence (which isn't an issue now), I have not had any odd behavior of any of the LED's. It does sound like either a fault with you matrix or some sort of bad/cross connection.

elcojacobs:
The rainbow functions should work as well, but the number of column registers should a multiple of 3.

I am using the MBI5026 chips. They have 16 outputs(2 x Normal SR's) so I can't connect a multiple of 3. But I did try just saying that I had a matrix of 3 SR's wide which should still work just the extra bits would get shifted in the process. All the other functions worked as expected but the rainbow still gave unusual results. The last four rows would be blank but then they would flicker with random data occasionally. Then on the wider rainbow the last four rows start off blank but then slowly fill up as the function progresses. Does anyone else have a matrix and would test this? I wrote a test loop just to use the groupby3 on each row and it worked fine.

  for(int group=0;group<5;group++){
    for(int row=0;row<numRows;row++){
      ShiftMatrixPWM.SetAll(0);
      for(int brightness=0;brightness<maxBrightness;brightness++){
        if(row<15){
        ShiftMatrixPWM.SetGroupOf3(row+1, group, brightness, brightness, brightness);
        }
        ShiftMatrixPWM.SetGroupOf3(row, group, maxBrightness-brightness, maxBrightness-brightness, maxBrightness-brightness);
        delay(10);
      }
    }
  }

So I think there is an issue with the rainbow function but not the groupby3 function.

elcojacobs:
If this works well, next step is to add some line drawing functions, or functions to set a field of leds to a value

WOW I never even thought of taking it that far. I was just glad to be able to set individual dots and let the library handle the rest. I think this would be really useful for a lot of people.

For anyone who is interested, I have started another thread for using ShiftMatrix as a streaming LED Video Matrix.
http://arduino.cc/forum/index.php/topic,72474.0.html
So far, I have a 16x16 mono testbed running at 15fps/32 brightness levels. I also tried 30fps/64 brightness levels and that worked without issue too.

Elco, what sort of tests would you like performed on library? My video routine is just updating the PWMvalues each frame of video. Is there anything else you would like to see done?

Very cool!
Video please :slight_smile:

I will add ShiftMatrix to my page soon if it is working well. Can I add your code as an example?

You are welcome to use the code Elco. I don't know if it would help anyone really. Its just taking the serial data and dumping it.
The Processing code to downscale is still something I am trying to get right. It is very sloppy code at the moment. But as soon as I get it up to scratch I will be posting it. But if people want to see it warts and all, I will post it :stuck_out_tongue:
And here is the DEMO:
This is the Bad Apple video scaled to 16x16 monochrome at 15fps/32 brightness levels 50Hz.
The flickering is a camera artifact and is not present looking at the display.

Nice!

When you are ready to upload the code, send me an e-mail. I'll add you to the project on google code, so you can add your stuff yourself and add/correct stuff later.

I have been trialling a few different combination's of Matrix dimensions. Through this and conversations with Elco, I can now say that ShiftMatrix will allow you to control 1024 LED's in a Matrix setup.

I had two setups which Elco sent me.

  1. 32x32
unsigned char maxBrightness = 15;
unsigned char pwmFrequency = 50;
int numColumnRegisters = 4;
int numRows=32;

Results:
Load of interrupt: 0.5095695972
Clock cycles per interrupt: 318.48
Interrupt frequency: 25600.00 Hz
PWM frequency: 1600.00 Hz
Divided over 32 rows, to have a total refresh rate of 50.00 Hz
Timer1 in use for highest precision.
Include servo.h to use timer2.
OCR1A: 624
Prescaler: 1

This worked but on my test setup this made the LED's much duller. This is due to the LED's only being on for 1/32nd of the time.

  1. 16*64
unsigned char maxBrightness = 31;
unsigned char pwmFrequency = 50;
int numColumnRegisters = 8;
int numRows=16;

Results;
Load of interrupt: 0.7825686931
Clock cycles per interrupt: 489.11
Interrupt frequency: 25600.00 Hz
PWM frequency: 800.00 Hz
Divided over 16 rows, to have a total refresh rate of 50.00 Hz
Timer1 in use for highest precision.
Include servo.h to use timer2.
OCR1A: 624
Prescaler: 1

This produced a much nicer output. Didn't seem dull in any way. The load is higher but you are getting twice as many levels as before. From Elco:

elcojacobs:
Due to the interrupt overhead, it is better to have more columns. All columns are driven in one interrupt, each interrupt one row is driven. This allows you to have 32 brightness levels. It also has the benefit that the maximum on time of your LED's is 1/16 instead of 1/32.

So there you have it people, 1024 LED's can be controlled in a Matrix with just one Arduino and some ShiftRegister's. All of that and with PWM to boot. VERY COOL ELCO!

I'm in the process of constructing a large RGB matrix and will probably try to implement this code once im done.
I see the code for the matrix control isn't posted on the google code page. Will it be soon or does somebody have an updated version I can work with?

Also, is the limitation of the code 1024 LEDs/3 =340 RGB leds? I'm shooting for upwards of 500.

mschn:
I'm in the process of constructing a large RGB matrix and will probably try to implement this code once im done.
I see the code for the matrix control isn't posted on the google code page. Will it be soon or does somebody have an updated version I can work with?

Also, is the limitation of the code 1024 LEDs/3 =340 RGB leds? I'm shooting for upwards of 500.

Above 1024 outputs it stopped working on an atmega328. I suspect it runs out of memory. It has only 2K flash and 1024 values take up 1K. An arduino mega might be able to cope with more LED's, but I have not tested it.

Could you add a link for the most recent ShiftMatrixPWM Library/.pde, please? has there been substantial progress recently?

edit: order

The latest version posted here is still the most recent version, but it seems to work fine.
I just have not updated the comments and documentation. I have been too busy building my new project, a fermentation fridge with data logging and a web interface.

Just use the code posted here and post again if you encounter problems.

How appropriate...keep me up to date on the fermentation fridge. I am in the process (still gathering supplies) of building an arduino-controlled corny kegerator. Re-purposed chest freezer, temperature controlled with the arduino and LCD readout for temps and beer names (and possibly amount left in keg). Brewing our pale ale this weekend along with a pumpkin ale. Anyway, off-topic, I will post back when I get a chance to try the matrix fully. Thanks!

hello,

I've made the circuit as shown in the ShiftOut Tutorial on the arduino website .i've used six 595 registers and common Anode Led's & i'm running the example that came with the code but it doesn't work as shown in the video ,Please help . . . .i'm attaching a video clip too ,kindly note that the last few led's don't light up properly

Video0030.3gp (116 KB)

Hello ,

I've tried all possible things that i'm aware of to make this thing work but its not happening ,the LED's Flicker too fast and the whole thing freezes ,Kindly help !!!

Abhay:
Hello ,

I've tried all possible things that i'm aware of to make this thing work but its not happening ,the LED's Flicker too fast and the whole thing freezes ,Kindly help !!!

Hello Abhay,
How exactly have you setup your circuit?
Did you setup as it says on the site:

Which hardware is used with ShiftPWM?

Basically just an Arduino and a chain of Shift registers. The circuit is exactly the same as in the ShiftOut tutorial on arduino.cc, but leave out the latch pin capacitor. You can choose the latch pin yourself, but the data and clock pins should be connected to the SPI pins MOSI and SCK.

What is not shown in that tutorial example is a decoupling capacitor, the capacitor that is shown in the tutorial is an error and should not be included on the latch pin! A decoupling capacitor is usually a .1uF ceramic type capacitor that is kept close to the IC and is across its Vcc and Gnd. This helps stop electrical noise from interfering with the IC. Using Shiftregisters like this is creating noise as you are switching power very fast. The effect gets worse the further from the source(Arduino) the signal gets. This could be what is effecting your output.

Grumpy_Mike is seen on a lot on the boards/threads here making sure that people use decoupling capacitors. Only reason I know of them is because of him (Big thanks Mike!). He even went so far as to make a tutorial of his own about them:
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

I hope this helps with your issues.(Did I get it right Mike?)