Go Down

Topic: Delay between row-scanning/setting how long it loops for (Read 662 times) previous topic - next topic

Kaph

Dec 27, 2012, 05:07 pm Last Edit: Dec 27, 2012, 05:18 pm by Kaph Reason: 1
Hi there,

I'm currently playing around with an 8x8 Matrix using two shift registers through transistors. I'm using a delay between each row, of 1ms, so that all the rows aren't on at the same time, but still seem on.

I'm not convinced this is really necessary and I'm not particularly sure why I've got it in my head I need to do this, as surely without a delay the rows are still being scanned, on each clock tick of the processor?

I think I must have felt I needed to "force" a delay so that all the rows aren't on at the same time.

Can someone assert that no delay is needed between row scanning?

My other query is with regards to displaying multiple images.

Say I wanted to have all the outer leds on, then the leds in the middle, alternating between the two. If I just put them one after the other, both would come on at the same time rather than flashing between the two.

Is there anyway to force it to loop the first "image" for say, 500ms, then the second, for 500ms?

fungus


Can someone assert that no delay is needed between row scanning?


With a matrix you can only switch on one row at a time. If you switch two rows on at the same time you double the power handling requirements of the shift registers, which could be bad.

With a hardware shift register the switch between rows should be so fast that it doesn't cause any problems. If you're truly paranoid you could put a delay between rows. It doesn't need to be a millisecond, a microsecond is enough (ie. turn all rows off then turn the next row on as fast as the CPU will go...)

Whatever you do, make sure you have good decoupling. Bad decoupling is worse for the hardware than any slight overlap in the row switching.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Kaph



Can someone assert that no delay is needed between row scanning?


With a matrix you can only switch on one row at a time. If you switch two rows on at the same time you double the power handling requirements of the shift registers, which could be bad.

With a hardware shift register the switch between rows should be so fast that it doesn't cause any problems. If you're truly paranoid you could put a delay between rows. It doesn't need to be a millisecond, a microsecond is enough (ie. turn all rows off then turn the next row on as fast as the CPU will go...)

Whatever you do, make sure you have good decoupling. Bad decoupling is worse for the hardware than any slight overlap in the row switching.



That's why I was concerned about the delay being so incredibly small that in effect there is none, leading to two rows+ being on at the same time. Thanks for the recommendation - shall do that instead!

Wasn't aware of decoupling. Shall go read up.

Many thanks!

In terms of having it display something for a certain period - how would I go about doing this? This is my code:

Code: [Select]
void loop() {
  grid(255,231,231,129,129,231,231,255);
}


// Various functions

void grid(int a, int b, int c, int d, int e, int f, int g, int h) {
  shift(1, a);
  shift(2, b);
  shift(4, c);
  shift(8, d);
  shift(16, e);
  shift(32, f);
  shift(64, g);
  shift(128, h);
}

void shift(int r, int c) {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, r);
  shiftOut(dataPin, clockPin, MSBFIRST, c);
  digitalWrite(latchPin, HIGH);
}


Now this works absolutely fine. But say I wanted it to remain on for 500ms, then display nothing -grid(0,0,0,0,0,0,0,0)-, for 500ms, how would I do this?

Many thanks!

fungus

#3
Dec 27, 2012, 07:50 pm Last Edit: Dec 27, 2012, 07:54 pm by fungus Reason: 1

Now this works absolutely fine. But say I wanted it to remain on for 500ms, then display nothing -grid(0,0,0,0,0,0,0,0)-, for 500ms, how would I do this?


First define the 'tick' rate of your program (eg. 500ms). Now use the function 'millis()' to update at that rate:

Code: [Select]

// What to display...
bool displayBlank = false;

void loop()
{
// Will go 'true' on a program tick
 bool tick = false;

  // Program timing happens here
  static unsigned long prevTime=0;
 unsigned long elapsed = millis()-prevTime;
 if (elapsed > 500) {
   tick = true;
   prevTime += 500;
 }

 // 'tick' indicates we need an update
 if (tick) {
   // Do something, eg. switch between blank/not blank...
   displayBlank = !displayBlank;
 }

 // Refresh the display
 if (displayBlank) {
   grid(0,0,0,0,0,0,0,0);
 }
 else {
   grid(255,231,231,129,129,231,231,255);
 }
}



This avoids locking up the CPU so you can keep your display running.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

CrossRoads

I do it as a more general approach, blink without delay style.
You have several time checks going on at once.
The data you are displaying is kept in an 8 byte array.
You check for 5mS, if elapsed you turn off the current byte and turn on the next byte.
(5mS * 8 bytes = 40mS, 1/40mS is a 25 Hz refresh rate. Go a little quicker if you want.)
You check for 500mS, if elapsed you update the array as needed.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Kaph

Thanks very much guys - shall try  those suggestions out! I hadn't considered using time and checking expiry, shall have a play now.

Is there a way to do it with interrupts? I've read a little bit about them, but not entirely confident. I'd like to try scrolling characters. I've had a look at some of the matrix guides on the learning things, but I'd like to code it myself rather than use libraries as I'm after understanding.


CrossRoads

"Is there a way to do it with interrupts? "

Why?
I control four MAX7219s to scroll text across this 8x32 display, updating as I desribed above. No interrupts needed.
Have a youtube post of it, no idea what I called it now. Has been posted here in forum too.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

http://www.crossroadsfencing.com/BobuinoRev17/Scroll_Test.AVI

This clip has slow scroll speed, holding each position for 40-50mS seemed to about the fastest you could go & still be readable.
http://arduino.cc/forum/index.php/topic,126144.0.html
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Kaph

#8
Dec 27, 2012, 11:02 pm Last Edit: Dec 27, 2012, 11:04 pm by Kaph Reason: 1
I've now got it working with a mixture of your suggestion using arrays, and using fungus' way of counting time.

Your matrix looks great. I'm unsure as to what entirely you meant by the following:

Quote
You check for 5mS, if elapsed you turn off the current byte and turn on the next byte.
(5mS * 8 bytes = 40mS, 1/40mS is a 25 Hz refresh rate. Go a little quicker if you want.)


So you're scanning through the rows at 5ms?

Apologies for my sluggishness!

Have yet to start scrolling characters. Need to get my head around the logic.

CrossRoads

I am using MAX7219s in my 8x32 display, they take care of the multiplexing so I don't  need to.

Where you are using 2 shift registers, you have to take care of that multiplexing yourself.
So yes, hold each column for 4-5mS.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up