Skip to main content
deleted 2038 characters in body
Source Link
while (!StatusIsUpdating && !Serial.available()) {
//open the latch

  Loop1 = Loop1 + 1;
  Letter1 = displayBuffer[Loop1   ];
  Letter2 = displayBuffer[Loop1 + 5  ];
  Letter3 = displayBuffer[Loop1 + 10 ];
  Letter4 = displayBuffer[Loop1 + 15 ];
  Letter5 = displayBuffer[Loop1 + 20 ];
  Letter6 = displayBuffer[Loop1 + 25 ];
  Letter7 = displayBuffer[Loop1 + 30 ];
  Letter8 = displayBuffer[Loop1 + 35 ];
  Letter9 = displayBuffer[Loop1 + 40 ];
  Letter10 = displayBuffer[Loop1 + 45 ];

  digitalWrite(latchPin, LOW);
  // shift out the bits:


  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter10);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter9);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter8);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter7);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter6);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter5);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter4);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter3);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter2);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter1);
  //take the latch pin high so the LEDs will light up:
  digitalWrite(latchPin, HIGH);
  //delay(Time);
  shiftReg1 = shiftReg1 * 2;
  //delay(Time);
  if (Loop1 >= 5) {
    Loop1 = -1;
    shiftReg1 = 1;
    //break;
  }
while (!StatusIsUpdating && !Serial.available()) {
//open the latch

  Loop1 = Loop1 + 1;
  Letter1 = displayBuffer[Loop1   ];
  Letter2 = displayBuffer[Loop1 + 5  ];
  Letter3 = displayBuffer[Loop1 + 10 ];
  Letter4 = displayBuffer[Loop1 + 15 ];
  Letter5 = displayBuffer[Loop1 + 20 ];
  Letter6 = displayBuffer[Loop1 + 25 ];
  Letter7 = displayBuffer[Loop1 + 30 ];
  Letter8 = displayBuffer[Loop1 + 35 ];
  Letter9 = displayBuffer[Loop1 + 40 ];
  Letter10 = displayBuffer[Loop1 + 45 ];

  digitalWrite(latchPin, LOW);
  // shift out the bits:


  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter10);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter9);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter8);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter7);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter6);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter5);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter4);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter3);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter2);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter1);
  //take the latch pin high so the LEDs will light up:
  digitalWrite(latchPin, HIGH);
  //delay(Time);
  shiftReg1 = shiftReg1 * 2;
  //delay(Time);
  if (Loop1 >= 5) {
    Loop1 = -1;
    shiftReg1 = 1;
    //break;
  }
Post Migrated Here from electronics.stackexchange.com (revisions)
Source Link

More speed from ATMEGA328 Internal Clock

I have a board that is designed and produced. It was designed to use an Atmega328 with the internal clock. There is no space on the board to place an external clock. After completing these and testing them I have found that 8Mhz is too slow to complete my main loop actions seamlessly. The main loop involved shifting data out to 20 registers. Is there any way to speed this up without going back to the drawing board on the PCB design? Can another AVR be substituted as a drop in replacement with a faster internal clock? Can the internal clock be made to run faster or doubled to achieve 16Mhz?

The application is a matrix display that has 50 columns and 7 rows. The registers are the display buffers and represent the current state of the display. Because of the multiplexing in the matrix, only 1/5 of the pixels are illuminated at any given time. In order to trick the eyes into seeing all lit at the same time the speed needs to be faster. The display flickers with the interal clock. If I connect and UNO board instead of using the on board ATMEGA328 (QFP) it works good. So the difference between 8Mhz and 16Mhz is visible. If I can double the speed of the display loop than that is a solution. Below is the loop, for reference, latchPin = 8, clockPin = 12, dataPin = 11.

while (!StatusIsUpdating && !Serial.available()) {
//open the latch

  Loop1 = Loop1 + 1;
  Letter1 = displayBuffer[Loop1   ];
  Letter2 = displayBuffer[Loop1 + 5  ];
  Letter3 = displayBuffer[Loop1 + 10 ];
  Letter4 = displayBuffer[Loop1 + 15 ];
  Letter5 = displayBuffer[Loop1 + 20 ];
  Letter6 = displayBuffer[Loop1 + 25 ];
  Letter7 = displayBuffer[Loop1 + 30 ];
  Letter8 = displayBuffer[Loop1 + 35 ];
  Letter9 = displayBuffer[Loop1 + 40 ];
  Letter10 = displayBuffer[Loop1 + 45 ];

  digitalWrite(latchPin, LOW);
  // shift out the bits:


  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter10);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter9);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter8);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter7);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter6);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter5);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter4);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter3);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter2);

  shiftOut(dataPin, clockPin, MSBFIRST, shiftReg1);
  shiftOut(dataPin, clockPin, MSBFIRST, Letter1);
  //take the latch pin high so the LEDs will light up:
  digitalWrite(latchPin, HIGH);
  //delay(Time);
  shiftReg1 = shiftReg1 * 2;
  //delay(Time);
  if (Loop1 >= 5) {
    Loop1 = -1;
    shiftReg1 = 1;
    //break;
  }