DMD and clock skew?

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
User avatar
Simon
Posts: 25
Joined: Wed May 02, 2012 2:40 am

DMD and clock skew?

Post by Simon » Wed May 02, 2012 3:16 am

Hi all,

I'm relatively new to Arduino and brand new to the DMD, so please forgive me if this is an obvious question.

What I'm building is a timing board for the local swim club, using two DMD boards to display a stopwatch and results for each lane.

I'm tracking time using the built-in millis() call, but attaching a second DMD causes the clock to run slow by about 20%.

I'm driving the displays as per the example code, using TimerOne interrupts at a 5000ms interval. My suspicion (not knowing the Arduino architecture very well) is that updating the second (and subsequent) screens in interrupt context is preventing the timer which millis() depends on from incrementing, thus causing it to run slow.

Can anyone comment? I've noticed debenham's thread which suggests clocking the SPI faster, which I'll try tonight when I'm in front of the gear. My other thought is to call scanDisplayBySPI() from the main loop...

hads
Posts: 10
Joined: Tue May 01, 2012 3:58 am

Re: DMD and clock skew?

Post by hads » Wed May 02, 2012 4:10 am

You're correct in your assumption. The millis() function isn't super accurate and does not increment inside an ISR.

I'd suggest a real time clock (RTC):
http://www.freetronics.com/collections/ ... rtc-module

Cheers,

hads

User avatar
Simon
Posts: 25
Joined: Wed May 02, 2012 2:40 am

Re: DMD and clock skew?

Post by Simon » Wed May 02, 2012 4:45 am

hads wrote:You're correct in your assumption. The millis() function isn't super accurate and does not increment inside an ISR.

I'd suggest a real time clock (RTC), I don't believe Freetronics have one at the moment, here's some links to products that are commonly used

<snip>
Hi hads, thanks for the confirmation. I was aware that millis() doesn't increment inside an ISR, but I wasn't sure whether calling scanDisplayBySPI() via a TimerOne interrupt would prevent the interrupt which increments the time from firing. Having thought about it a little more, it's obvious that it will if the scanDisplayBySPI() method takes longer than 1ms, which is evidently what's happening with more than one display attached. I suspect that clocking the SPI faster will help here.

I've had a quick look at those three RTCs and unless I'm mistaken none of them provide sub-second resolution. I need to accurately measure time to millisecond resolution (well 10ms to be precise) so although those clocks won't drift over long periods of time unless they can supply the current time to the millisecond then they're not useful in this application.

hads
Posts: 10
Joined: Tue May 01, 2012 3:58 am

Re: DMD and clock skew?

Post by hads » Wed May 02, 2012 5:06 am

You're quite right, sorry. I was thinking of second accuracy rather than sub-second.

User avatar
Simon
Posts: 25
Joined: Wed May 02, 2012 2:40 am

Re: DMD and clock skew?

Post by Simon » Wed May 02, 2012 9:44 am

I appear to have sorted this one out. I'm now using debenham's version of the DMD library, rendering using a TimerOne instance and it's keeping time perfectly. The combination of his performance improvements and clocking the SPI faster seems to have done the trick.

dtbaker
Posts: 26
Joined: Sat Jun 02, 2012 12:52 pm

Re: DMD and clock skew?

Post by dtbaker » Sun Jun 03, 2012 4:04 am

I'm brand new to DMD and interested in running a stopwatch on it as well.

May I ask how you increase the SPI and load this other library on?

Do you have any sample stopwatch code?

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

Re: DMD and clock skew?

Post by Aussie_Wombat » Sun Jun 03, 2012 5:49 am

In the DMD.cpp (arduino\libraries\dmd\dmd.cpp) file it sets the spi speed to

Code: Select all

 SPI.setClockDivider(SPI_CLOCK_DIV128);	// system clock / 2 = 8MHz SPI CLK to shift registers
when opening the DMD class.

in the SPI.h (arduino\libraries\SPI\SPI.h)

it lists

Code: Select all

#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
//#define SPI_CLOCK_DIV64 0x07
so after the spi.h has been included, and before the

Code: Select all

DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
is called , just define the SPI_CLOCK_DIV128 as SPI_CLOCK_DIV64

ie

Code: Select all

#define SPI_CLOCK_DIV128 0x02 // actually SPI_CLOCK_DIV64's code..
this will override the spi.h libraries own define..

so that when the DMD code initialises the class, it sets the speed to faster (i think)
as the dmd.cpp states


A safer way would be to change the code in the dmd .cpp and then set your own define so that the spi defines are not changed..

ie

Code: Select all

 SPI.setClockDivider(mySPI_Speed);	// 
then in your sketch set

Code: Select all

#define mySPI_Speed 0x02  // SPI_CLOCK_DIV64
before calling the dmd dmd(#wide,#tall); code..


Cheers Dennis... (this is untested and only a theory)

[edit] follow the link.... viewtopic.php?f=26&t=293

User avatar
Simon
Posts: 25
Joined: Wed May 02, 2012 2:40 am

Re: DMD and clock skew?

Post by Simon » Mon Jun 04, 2012 12:54 am

I wasn't nearly so deft in my solution - I used a sledgehammer, and edited dmd.cpp directly to change the SPI speed :lol:

Post Reply