Arduino hangs if more than 4x DMDs declared

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
User avatar
stryker
Posts: 266
Joined: Sat Jan 14, 2012 2:44 pm

Arduino hangs if more than 4x DMDs declared

Post by stryker » Sat Jul 06, 2013 2:54 pm

Hi

I've been chasing this issue now for about 3 weeks. Our project will use 6 DMDs, arrayed 3 wide and 2 tall. I hit an issue where the sketch hangs in setup() if I declare

Code: Select all

DMD dmd(3,2); 
but it continues on fine if I use any combination of dimensions that arrive at 4 or fewer. I first thought I was out of RAM on the ATmega328 so rewrote the code to put literals into progmem, and commented out big chunks of the code. I added a heap of debugging print()s to show the available bytes of RAM at each step and after a short time ended up with a spreadsheet tracking how much RAM I had free, and calculated that for every additional DMD in that declaration, 64 bytes was consumed (2x2, 4x1 & 1x4 reported the same memory use).

Regardless, presuming it was RAM that's the killer difference between a 4 and 5 or 6 DMD in code, I needed to free up 128bytes...and now with 3x2 declared I have far more available RAM than when it originally had with 2x2 and it still doesn't work.

Then I uploaded the sketch to the ATmega with a ISP programmer and freed up another 500bytes or so more, and it still hangs in the same place so I'm convinced now it's not RAM.

Is there something fundamental that changes at the 4 DMD threshold? The line which it appears to hangs on is the Timer1.attachInterrupt. Commenting that out makes the sketch execute just as surely as declaring dmd(2,2), though that could be a red herring of course.

Other hardware in this project includes two MCP23008 I2C IO expanders, a DS1307 RTC, and 20x4 I2C LCD as well as a 1-wire DS18B20 thermometer. If it's not RAM, where else should I be looking for the culprit here?

Thanks!
Geoff

Aussie_Wombat
Posts: 51
Joined: Tue May 22, 2012 12:52 pm
Location: Adelaide, South Australia

Re: Arduino hangs if more than 4x DMDs declared

Post by Aussie_Wombat » Sun Jul 07, 2013 6:56 am

Hi Stryker, I found a similar issue, some time ago, in this viewtopic.php?f=26&t=3639 thread. The panels were drawing very slowly. 1 pixel per second. I never really resolved it, and just went on with my pic32 variant( works with 4x3 ) 12 panels..and I hope my (7x3) 21 panel version.

Regards Dennis
[edit]

If You set the panels to 2x2 , but leave the othres attached, do you still get output, at the normal speed.?

[/edit]

User avatar
stryker
Posts: 266
Joined: Sat Jan 14, 2012 2:44 pm

Re: Arduino hangs if more than 4x DMDs declared

Post by stryker » Sun Jul 07, 2013 7:52 am

Hi Dennis,

I've got the 6 DMDs but until now have been writing the code with just one connected for testing. I haven't actually chained them all up yet so can't comment. Did you have any joy with slowing the refresh as per the response you received?

I wonder if it is a race condition where it never gets out of the DMD refresh cycle before it has to start it again? I'll try something down that path later tonight and report back.

Cheers ! Geoff

User avatar
stryker
Posts: 266
Joined: Sat Jan 14, 2012 2:44 pm

Re: Arduino hangs if more than 4x DMDs declared

Post by stryker » Sun Jul 07, 2013 9:55 am

Oh my. Setting the interrupt to 7ms the code gets through setup() with a 3x2 DMD array declared

Code: Select all

  Timer1.initialize(7000); 
Dennis I really wish I'd contacted you sooner! Looks like the race condition suggestion could have been on the money. Hopefully the 'flicker' mentioned for refresh longer than 5ms isn't too bad. Any idea what the default refresh rate is on the PIC in contrast?

Will post again once we have the 6x DMDs in a frame and can see what the result is.
Geoff

Aussie_Wombat
Posts: 51
Joined: Tue May 22, 2012 12:52 pm
Location: Adelaide, South Australia

Re: Arduino hangs if more than 4x DMDs declared

Post by Aussie_Wombat » Mon Jul 08, 2013 8:03 am

Hi Geoff,

I found that if I had all 9 panels connected, and only told the arduino there was 3x1 then all of the panels worked, but obviously the last 6 were just out of sync with the first 3.

I was working on two controllers at the same time. The Arduino, and a Maximite Monochrome(pic32) . I just picked the one that worked for the number of panels I wanted to use. I timed the routine I added to the MMBasic source code, and it was just under a millisecond for one panel, and rose to 1,5 millisecond for 6 panels. So I assume I can still use the 5 ms refresh rate for the 21 panels .

I have successfully connected a Maximite to a Blutooth device, over a serial connection, Then used an android phone app to send text data to the dmd display to be output, via bluetooth...

regards Dennis.

TheRevva

Re: Arduino hangs if more than 4x DMDs declared

Post by TheRevva » Sun Oct 06, 2013 11:00 pm

Hi guys'n'gals,

Please excuse me 'butting in' to your topic, it's just that I _might_ have an explanation for you.
Looking through the default code in the library, it APPEARS to be setting the SPI clock to a rather s-l-o-w frequency. (The associated comment in the code states that it's set to 2MHz, but the actual code uses the divide-by-128 mode).
Assuming your AVR clock is 16MHz (We all HATE assumptions!), and assuming that you leave the default divisor as 128, then your SPI clock is ACTUALLY only running @ 125KHz!!!
With one quarter of the display being refreshed every time the TimerOne tick occurs, it means that there are 512 / 4 (128 pixels) * number of chained panels shifted out over the SPI bus on every tick.

Well.... This is all fine until your try to chain in the FIFTH (or more) module.
The SPI bus needs to send out 1/4 of the pixels every time TimerOne does a tick. With five panels, that equates to 512 / 4 * 5 pixels which is 640 pixels. Since the SPI bus is clocked at 125kHz (8uS period), this will take around 5120uS (5.120mS) let alone the extra overhead in toggling the OE and LATCH pins. This is (obviously!) longer than the TimerOne tick, so as soon as the interrupt routine has finished doing it's 1/4 update and returns to the mainline, the NEXT time tick has already occurred. Therefore, there is precisely ZERO available CPU time to actually do anything useful (such as actually spending time to write a pixel into the display buffer).

A potential cure is strikingly simple. All you need to do is to increase the SPI clock frequency to a more 'suitable' value. I would suggest that changing SPI_CLOCK_DIV128 to SPI_CLOCK_DIV16 will be adequate for UP TO 32 daisy chained panels. (i.e. Bump it from 125kHz to 1MHz). Looking at the overall construction of the DMD panel I would GUESS that it could probably still work with an even faster clock, but keeping it lower will help to limit a bit of generated RFI. (I'd recommend AGAINST turning on the DMD anywhere close to a radio aerial as I suspect it would positively SWAMP any radio signals with the harmonics!)
(Although you COULD use that generated RFI to 'play a tune' on your radio... LOL The AM band would probably give the best results...)

User avatar
stryker
Posts: 266
Joined: Sat Jan 14, 2012 2:44 pm

Re: Arduino hangs if more than 4x DMDs declared

Post by stryker » Mon Oct 07, 2013 1:39 am

Thanks that's a very nice find. We've just got our custom PCBs and the initial testing with 6 displays visibly flashes so you might have helped shortcut that debugging process some! Not sure how long before we get back to this one but will report on results when we do.

Thanks again,
Geoff

Post Reply