Pages: 1 ... 4 5 [6] 7 8 ... 20   Go Down
Author Topic: ShiftPWM support topic. Latest update: Schematics, high power LED's, LED strips  (Read 66460 times)
0 Members and 2 Guests are viewing this topic.
Eindhoven
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Salsaman, you are the first to come back with results on video!
Looks great. That's what makes it worth making this publicly available and supporting it. All the projects together should make a great gallery.

Now for somethings else: Who wants to test a matrix version of ShiftPWM?
This version uses shift registers for the columns, driven by SPI, and shift registers to alternate rows, bit banged. Both invertible, so it will suit any matrix setup.
Performance is about the same as one long chain of shift registers, but the amount of registers you require is a lot less. Downside is of course that the maximum on time of each led i 1/rows. But you can use more current per led to get about the same brightness.

8x8 RGB matrix: 3 column registers, 1 row register. 64 brightness levels, total refresh rate 60Hz (so combined pwm frequency of 8*60Hz). Load = 0.54.

16x16 RGB matrix: 6 column registers, 2 row registers, 32 brightness levels, total refresh rate 60Hz (so combined pwm frequency of 8*60Hz). Load = 0.79.

I don't have a led matrix, so I cannot test this code myself. Would be cool if it just worked, wouldn't it?

Code is attached, unpack in the library directory like ShiftPWM.

* ShiftMatrixPWM.rar (13.53 KB - downloaded 112 times.)
« Last Edit: September 01, 2011, 08:51:16 am by elcojacobs » Logged

Australia
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

THANK YOU ELCO!

I will be playing with your code this weekend for sure. I will let you know how it goes. (reading through the example and code now.)
Quote
16x16 RGB matrix: 6 column registers, 2 row registers, 32 brightness levels, total refresh rate 60Hz (so combined pwm frequency of 8*60Hz). Load = 0.79.
Shouldn't that be "(so combined pwm frequency of 16*60Hz)"? It looks like that in the example.
*edited*
Reading through it, I just want to make sure I understand this right. There will be 2 chains of SR's coming from the Arduino. One chain to run the Columns (the R,G,B channels). And a seperate chain for driving the Row selection (the common LED lead).
With the above in mind I am assuming the Row selection SR's are being bit banged via normal port toggling and the Columns are being bit banged via the SPI.

This is a very flexible design. Thank you for putting the seperate inverting options in. I can't wait to build a proto setup and try this on a matrix.
« Last Edit: September 01, 2011, 07:49:16 pm by milamber » Logged

Eindhoven
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Shouldn't that be "(so combined pwm frequency of 16*60Hz)"? It looks like that in the example.
You are right, hasty copy paste job.
The refresh rate for each led of the 16x16 RGB matrix is 60 Hz, but it is 16 rows, so the PWM is as fast as 16x60=960 Hz, where each 60Hz is on a new row. Each brightness level is 1/(60*32*16) seconds and maximum on time for a led is 1/(60*16).
Not the best explanation, but I have had a few beers.
Logged

Eindhoven
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reading through it, I just want to make sure I understand this right. There will be 2 chains of SR's coming from the Arduino. One chain to run the Columns (the R,G,B channels). And a seperate chain for driving the Row selection (the common LED lead).
With the above in mind I am assuming the Row selection SR's are being bit banged via normal port toggling and the Columns are being bit banged via the SPI.

This is a very flexible design. Thank you for putting the seperate inverting options in. I can't wait to build a proto setup and try this on a matrix.

Just to react to your latest edit: You are exactly right. The row selection has to happen only one in 1 in nr_brightness_levels interrupts, so it would be a shame to send it out via the SPI each interrupt. The columns are RGBRGBRGB.... and the rows are the common cathodes/anodes.
The row selection is done via fast sbi and cbi instructions. The alternative pins_arduino include i wrote makes sure the ports/masks are known at compile time to compile to fast code.
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok I put a breadboard prototype together and quickly ran through some things. Just to let you know I am not using 595's I have some constant current SR's (MBI5026). Everything compiled and uploaded fine. I had some weird display issues to start with but I worked out it was that I didn't have the setting right. Fixed those up and it behaved very well. The set all function worked well in the all fade in and then fade out code. After that I had issues. I don't know why but the two led chasing code was commented out. The next function was the rainbow which didn't run. The micro just seemed to hang and needed to be reset. If I comment out the rainbow lines then it runs the main loop over and over fine, which now only has the fade in and fade out. I uncommented the two led chase code and recompiled and uploaded.

That ran fine as well. So setall was working and set one was working.

One of the weird things I came across was flickering. I played with the frequency and found that if the divided frequency was not a whole number it got the occasional odd flicker. Not sure how to explain that further. but I was able to play with it and find a frequency that was solid. After that the functions that were working ran well.
Due to time restraints (and family commitments) I am not sure I will be able to test further for a few days. I was unable to do any debugging on why the group by 3 rainbow didn't work.

Thanks again Elco. For my purpose even this does great!
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright. I have done some further testing and some digging through the libraries code.

As previously stated setall and setone work exactly as expected. Onebyonefast and slow don't seem to output anything to the matrix but they do seem to be doing something and it eventually moves on to the next piece of code.

I do have a question about CShiftMatrixPWM.cpp, for the group by functions you have (for example the SetGroupOf3):
Code:
m_PWMValues[row*m_amountOfColumns,group*3]=v0;
m_PWMValues[row*m_amountOfColumns,group*3+1]=v1;
m_PWMValues[row*m_amountOfColumns,group*3+2]=v2;
From the setone function above, it looks like this:
Code:
m_PWMValues[row*m_amountOfColumns+col]=value;
Shouldn't the SetGroupOf3 function look more like:
Code:
m_PWMValues[(row*m_amountOfColumns)+(group*3)]=v0;
m_PWMValues[(row*m_amountOfColumns)+(group*3+1)]=v1;
m_PWMValues[(row*m_amountOfColumns)+(group*3+2)]=v2;
*Changed the "," to "+" and added the brackets (not sure if they are needed)
With the original code I couldn't get SetGroupOf3 to work. But with the modification it seemed to work fine for individual calls to it.
I did however have issues with the rainbow function. I had two main problems:
1) In my 16 row matrix, row 16 would only very occasionally have LED's on and they wouldn't stay on long at all. Where as the rest of the display was showing a slowly moving patern. (this was a non RGB matrix)
2)If I upped the number of columns to max (I assume max LED's to still be 768??) meaning setting it to 6 SR's and 16 Rows. I would get the pattern for the first 5 rows then nothing until the 14th row. Again occasional light would light up briefly in the non working areas.

As I said though, individual calls to the SetGroupOf3 worked in all positions. So not sure what is going on there. I need to test the SetGroupOf3 as this were I want to go.

Thanks again Elco. If you have some time to look at it can you check if the above makes sense. If you make any modifications I am happy to try them out.
Logged

Eindhoven
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi milamber,

I almost have a red 8x8 matrix setup on my breadboard so I can debug it myself.
Your comment about the indexing of m_PWMValues is right, it is indeed a mistake on my part.

Hopefully I have some time to debug tomorrow.
Logged

India
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Eindhoven
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the example code, you'll see this:
Code:
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.
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Eindhoven
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.46 KB - downloaded 54 times.)
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Eindhoven
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
DrawLine(startX,startY,endX,endY)
SetField(0b11000011,
            0b11000011,
            0b00000000,
            0b00011000,
            0b00011000,
            0b100000010,
            0b01000010,
            0b00111100,
            63)

* ShiftMatrixPWM.rar (13.55 KB - downloaded 101 times.)
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
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?
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.
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.
Code:
  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.
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.
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: 1 ... 4 5 [6] 7 8 ... 20   Go Up
Jump to: