How to Set DMD Brightness

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

Re: How to Set DMD Brightness

Post by stryker » Sun Feb 24, 2013 11:48 am

Thanks again, that's good information.

I've just spent a bit of time reading about PIC PWM and what you're doing there is quite straightforward, and similar to the Atmel as you suggested. I presume you only need to have the external .AND. circuitry because the pin driving nOE is not supported by hardware PWM, or is there something cleverer there I'm missing?

The first thing that stands out is the frequency of your PWM - the Arduino IDE analogWrite() function is just 490Hz (using a prescaler of 64) in contrast to your 3kHz. With port manipulation I will change this to a prescaler of 8 and see if we can see an improvement. It will be a few nights before I can get this done, but will return here with the results...and hopefully some working code.

Cheers, & thanks again ! Geoff

42n8
Posts: 46
Joined: Wed Dec 26, 2012 8:10 pm
Location: Auckland, NZ

Re: How to Set DMD Brightness

Post by 42n8 » Sun Feb 24, 2013 1:28 pm

The first thing that stands out is the frequency of your PWM - the Arduino IDE analogWrite() function is just 490Hz (using a prescaler of 64) in contrast to your 3kHz.
Bearing in mind that I slow the frequency down by a factor of 30 within the interrupt so the actual frequency will be close to 100 Hz. Thats 100 counts per second or to put it another way, roughly 2.5 seconds to go from the dimmest setting to the brightest.

So frequency applies to the rate of change that the PWM can achieve. For the purposes of this, within reason, we don't care how long it takes provided that we can control it comfortably.

To answer the other question, yes the pin does reside on a PWM port but I chose not to use it because that particular timer is used by the SPI library. Now, it is possible to use it but I wanted to have both local and software control so it just made sense to use the other PWM system.

Regards

42n8
Posts: 46
Joined: Wed Dec 26, 2012 8:10 pm
Location: Auckland, NZ

Re: How to Set DMD Brightness

Post by 42n8 » Sun Feb 24, 2013 1:32 pm

always at full brightness as if the nOE pin were grounded.
setting the PWM register is a once only operation.
Both of these statements must be true. So why doesn't it work?

I've looked into this a bit more and, as expected, there are basic working examples. One in particular demonstrated clearly the PWM in action.

See http://extremeelectronics.co.in/avr-tut ... s-part-ii/

The DMD will be at it's brightest anyway so it seems that the PWM is not operating for some reason.

This lead me to think that something else was going on. Port function precedence maybe? For example, if the Digital output took precedence over the PWM function then the PWM would work, but only when the Digital output is inactive and this theory seemed to explain it.

That took me to the datasheet. Right there, on pages 90 and 91 is the information for overriding the port functions.

It seems that you would need to set the port into and out of PWM mode, essentially toggling it and thereby reducing the time the nOE can be active.

Let's see if this is the real answer.

Regards

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

Re: How to Set DMD Brightness

Post by stryker » Sun Feb 24, 2013 2:14 pm

42n8 wrote:
always at full brightness as if the nOE pin were grounded.
setting the PWM register is a once only operation.
Both of these statements must be true. So why doesn't it work?
Looks like we've both been staying up reading. I think I found the answer - at least for our example. I'm using the TimerOne library to trigger the rescan of the DMD. From the fine print on that,
While uses these libraries, analogWrite() to those pins will not work normally, but you can use the library pwm() function
I'll try with the PWM function in the library rather than the Arduino analogWrite() and I expect (since you've counted out the high frequency idea I had earlier) that we'll have a working dimmer.

Cheers ! Geoff

42n8
Posts: 46
Joined: Wed Dec 26, 2012 8:10 pm
Location: Auckland, NZ

Re: How to Set DMD Brightness

Post by 42n8 » Sun Feb 24, 2013 2:31 pm

I'll try with the PWM function in the library rather than the Arduino analogWrite()
Sounds to me like the PWM library takes care of the port precedence.

Lets hope that turns out to be a true statement Geoff


Regards

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

Re: How to Set DMD Brightness

Post by stryker » Sun Feb 24, 2013 2:34 pm

There was also a newer version of the library that supports this. Previously, I wasn't using that.

It's tomorrow already. Time to hang this up for the night. Will confirm once we've tested this out.

Geoff

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

Re: How to Set DMD Brightness

Post by stryker » Mon Jun 03, 2013 12:38 pm

Hi,

Apologies for the break in comms. I've finally got a half dozen DMDs for playing with...so don't have to bother other people emailing code around for testing.

So I started where we left off here, and unfortunately what we thought might solve the issue, doesn't dim it at all. I ran the below code which steps through the array of PWM values, displaying the value at that PWM brightness. Still the DMD runs at full brightness...

Code: Select all

#include <SPI.h>                                           // for DMD display
#include <DMD.h>                                           // also, for DMD display
#include <TimerOne.h>                                      // and THIS, is for the DMD display periodic refreshes
#include <Arial_black_16.h>                                // ...big type: 16px tall & 10px wide

// DMD
DMD dmd(1,1);
const int nOE = 9;
unsigned int nOEvalue[12] = {1023, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0};
int nOEidx = 0;
int incrementer = 1;

// DMD refresh scanning is driven by the Timer1 interrupt
//
void ScanDMD() { 
  dmd.scanDisplayBySPI();
}

void setup() {
  Timer1.initialize(5000);
  Timer1.attachInterrupt(ScanDMD);

  dmd.clearScreen(true);
  dmd.selectFont(Arial_Black_16);

  pinMode(nOE, OUTPUT);
}

void loop() {
  nOEidx += incrementer;
  if(nOEidx == 11 || nOEidx == 0) incrementer *= -1;

  Timer1.pwm(nOE, nOEvalue[nOEidx]);
  
  dmd.drawChar(  0,  1, '0'+((nOEvalue[nOEidx]%10000) /1000),  GRAPHICS_NORMAL );            // thousands
  dmd.drawChar(  8,  1, '0'+((nOEvalue[nOEidx]%1000) /100),  GRAPHICS_NORMAL );              // hundreds
  dmd.drawChar( 17,  1, '0'+((nOEvalue[nOEidx]%100)  /10),   GRAPHICS_NORMAL );              // tens
  dmd.drawChar( 25,  1, '0'+ (nOEvalue[nOEidx]%10),          GRAPHICS_NORMAL );              // units
  
 delay(500);
}
So there's clearly something else I'm missing? I'm presently running one DMD directly off a Freetronics Eleven so will grab an ATX supply and see if there's anything different to see with more juice present also.

Geoff

42n8
Posts: 46
Joined: Wed Dec 26, 2012 8:10 pm
Location: Auckland, NZ

Re: How to Set DMD Brightness

Post by 42n8 » Mon Jun 03, 2013 7:43 pm

G'day Geoff,
Pleased to see you had another hack at it. Some time back I wrote a service manual for the DMD as a cheat sheet because I didn't want to keep revisiting fault finding procedures looking for solutions.

Casting my eye down through it, I see that I made a note that some faults are not apparent when the board is NOT being PWMed .

"Since the Gate is under the control of the PWM on nOE and the problem is most apparent when the Pulse Width is short then perhaps the condition is occurring because the Gate is not returning to its OFF state fast enough, if at all. This problem isn’t obvious in an application that doesn’t PWM nOE."

That statement seems to ring a bell in the back of my mind. I think that the board does respond to a PWM signal when powered by the CPU, which means that when you power it from the ATX supply it will be seriously bright but your PWM solution still won't work.

I'll break out a system a bit later on this week to confirm my thoughts on the matter and get back to you.


Regards
42n8

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

Re: How to Set DMD Brightness

Post by stryker » Mon Jun 03, 2013 9:12 pm

Hi 42n8,

Thanks for sparing some time on this. It really has been a puzzle.
42n8 wrote:G'day Geoff,
I think that the board does respond to a PWM signal when powered by the CPU, which means that when you power it from the ATX supply it will be seriously bright but your PWM solution still won't work.
It would be a shame if it doesn't dim when on dedicated power supplies, since that's precisely when you'd most be wanting to dim it, but at least it would put this challenge to bed.

Looking forward to your results,
Geoff

42n8
Posts: 46
Joined: Wed Dec 26, 2012 8:10 pm
Location: Auckland, NZ

Re: How to Set DMD Brightness

Post by 42n8 » Tue Jun 04, 2013 10:41 am

I think that the board does respond to a PWM signal when powered by the CPU, which means that when you power it from the ATX supply it will be seriously bright but your PWM solution still won't work

Heya Geoff,
I can confirm that a single does indeed respond to PWM when powered from USB.

Powering the DMD from an external source is not the solution to the issue.

So I decided to try somethig a bit different based on the idea that nOE is just setting the time that the data is displayed. Since PWM performs exactly the same function I thought that the nOE signal might just be redundant and that proved to be the case.

I removed the connection to the nOE port and just fed the nOE line with the PWM signal
I haven't yet tried this with a program that does anything and it might become unstable but somehow I don't think there will be any problem at all with this configuration.

In your case, you may be able to PWM the nOE port directly and disable anything to do with nOE; you should be able to remove all references to it from the source and save some space.




Regards

42n8

Post Reply