Pages: [1]   Go Down
Author Topic: Delay between row-scanning/setting how long it loops for  (Read 590 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: December 27, 2012, 11:18:26 am by Kaph » Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5536
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

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

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5536
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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.

« Last Edit: December 27, 2012, 01:54:13 pm by fungus » Logged

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27147
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

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.

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27147
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* 8x32shield.jpg (158.89 KB, 1043x629 - viewed 9 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27147
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

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.
« Last Edit: December 27, 2012, 05:04:40 pm by Kaph » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27147
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: