SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By unebonnevie
#67489
Hi,

I am able to hook up and control the 8x8 matrix led with an ATMEGA8 and the ST M74HC595, which can gives 8 output at once. I am hoping people here have some HC595 experience. My circuit is 5V DC and my ATMEGA8 is running at 1Mhz, the default clock. I am able draw the rows of dots without any problem. The problem is when my row's data has a zero in it, suddenly all the output bits messed up. For example, 11111111 (binary) will display fine, but something like 11100111 will not show the row light up correct. The zeros (unlighted LEDs) in the row would be somewhere else. I have spent so much trying to figure it out.

Below is the routine that would draw an 8x8 pattern onto the 8x8 matrix led. Each clock (count) of the 4017 will turn on a column and then I attempt to light up each dot in the column (by traversing the rows) with the help of the HC595.

At HC4017 (decade counter) is driven by my ATMEGA8.

Thanks for any help! Much appreciated.

void drawPattern(int i) {

uint8_t j, k;

// Clear for shifting.
resetHC595(); // LOW on the shift clock. And LOW in the HC595 Serial-in pin.
// and LOW on the latch clock.

// Reset the HC4017
resetHC4017(); // make sure to scan from the first column onward.
// Upon reset, output zero of the HC4017 will be
// HIGH. Note that we don't use output zero of
// the the HC4017.

// TODO: This does not seem to help.
// Because a reset will trigger Output 0 to high on the HC4017, and we
// are not using/connected to output 0, we need to output a LOW signal
// to it. Our next HIGH clock would advance to output 1 and so on.
clockLowHC4017();

for (j = 0; j < 8; j++) {

// This clock signal is the output to pin 1 of the HC4017 to
// initiate one count. Each count, we will draw the entire pixels
// in a row.
clockHighHC4017();

// Shift out 8 bits--LSB first
uint8_t data = LETTERS[j];

for (k = 0; k < 8; k++) {

// Must go from LOW to HIGH in order to shift a bit
// into a shift register.
clockLowHC595();

// load the bit into the 595's serial-in pin ready for shifting.
if ((data & 0x80) == 0x80) {
loadBit(1);
}
else {
loadBit(0);
}

clockHighHC595();

// Next bit in the data
data <<= 1;
}

// This HIGH to LOW will not affect the shift register, basically
// completing the last clock pulse. Ready to output the 8 bits.
clockLowHC595();

// Now output the 8 bits from the shift register by setting the
// HC595's latch pin to HIGH!
setHC595Latch();
resetHC595Latch();
clockLowHC4017();

// TODO: Must calculate this base on the Mhz, so that you can
// delay precisly the # of ms.
// 320-350 => 1Mhz
delay_ms(320);
}
}
User avatar
By bigglez
#67495
unebonnevie wrote: The zeros (unlighted LEDs) in the row would be somewhere else.
Where?
unebonnevie wrote: At HC4017 (decade counter) is driven by my ATMEGA8.
Please post your schematic.

If you expect to light all 64 LEDs without flicker you will
need a much higher AVR clock frequency than 1MHz.
This is less of a problem at the moment, as you still
need a scheme to drive rows and columns.
By unebonnevie
#67501
thanks responding...Sorry I might have been not clear on the real problem, which is: If I wanted to display say, a row of 11111111, that is, light up 8 leds of a row, it works fine. BUT, when I have a zero in the binary data, e.g., 10111111, and want to display it (again as a row), the zero is unlit somewhere else in one of the 8 positions.

So, it looks like either have a timing problem or not shifting the zero(s) into the HC595 correctly.

It turns out that 1Mhz is fine, there is no flickering, if I control the delay time between drawing rows correctly. However, like you said, higher Mhz would be very good, which I tried out with 16Mhz. I use a ULN2803 to drive the leds. So they do light up nicely, no dimming or whatever.

As for schematic, sorry I can't draw on up with Eagle--no time. But I can describe.


-One ATMEGA8 pin connected (as a clock) to the 4017 to drive it. I wire the 4017 output pins 1-8 to the ULN2803 input pins (again 1-8). I don't use the outpint pin zero of the 4017, because I want full control to clocking the 4017 starting with output pin1. The eight 4017 outputs are connected to the 8 LED matrix's command anodes, which, are the rows.

-One ATMEGA8 pin connected to the RESET pin of the 4017 so that I can reset the 4017 at will, basically when I start drawing the entire LED, as you see from the code.

-All the ULN2803 output pins (8 of them) are connected to 8 common cathode pins, which are the columns, of the LED matrix.

So, when the 4017 clock is high, it is held high for the first (and so on as the clock progresses) column until the 8th one. For each clock, I draw a row of data to the LED matrix via the HC595.

I believe my code is very well-commented. But, something is not working right when display rows with zeros in them--basically shifting not correctly, etc.

But, I have researched and researched the net for a long time and saw example codes which match with my approach and which I verify against, still not working.
User avatar
By bigglez
#67515
unebonnevie wrote:As for schematic, sorry I can't draw on up with Eagle--no time.

But, I have researched and researched the net for a long time
Hmm. Time to research but no time to draw?
By unebonnevie
#67549
Hmm. Time to research but no time to draw?
Yeah, too much inspiration :-) But I think I described thoroughly enough.
By unebonnevie
#67561
Problem resolved! LOL and kicked myself!

My 8x8 LED's row pins are ordered with pin numbers 22 (for row 1), 19, 16, 13, 3, 6, 9, and 12 (for row 8 ). Hecked! I connected the output of the 8 pins from the HC595 to the LED's pin 3, 6, 9, 12, 13, 16, 19, 22 in that order!

WRONG! the hc595 output should be connected to the exact order (ahem) from the spec. :-)
The joy of electronics (since my beginning 3 months ago.) :-)