Ports on Atmega2560

I am designing a 32x32 LED matrix and hoping to do it without shift registers. I also want to save PORTD for a RTC and PORTB for the ISP. I was/am planning to use PORTS A, C, E, F, H, J, K, and L for digital I/O - but as I watch my code, I am losing bits 3, 4, and 5 on PORT E due to TIMER3. I am still reading the data sheet to understand this - I'm not quite there - yet. I am also at a loss why PORT G only has 6 bits. I do have some choices - 1) drop the RTC, 2) use shift registers, 3) use 6 bits from PORT G and two from PORT E. But - my main purpose is to learn more about programming and the Atmega processors. Any advice / suggestions / comments are welcome.....


Why are you loosing bits on port E if you're using the timer? You'd be using timer 3 if you wanna have PWM on these bits but you don't loose the digital outs if you use timer 3. Perhaps I misunderstood you but you haven't told us why you need timer 3 and why you think you loose pins if you use timer 3.

Here is the timer / interrupt code:

TCCR3B |= (1<<WGM12); // Configure Timer 3 for CTC Mode
TIMSK3 |= (1<<OCIE3A); // Enable Interrupt
OCR3A = 2000; // Set CTC compare value to 1Hz at 1MHz AVR Clock with prescalar of 64
TCCR3B |= ((1 << CS10) | (1 << CS11)); // Start timer at Fcpu/64

I am using the timer to trigger the interrupt to refresh the matrix display - very standard stuff. As I was stepping through the code checking to be sure the output ports were setting correctly (using AVR Studio), I noticed the pins on PORT E worked as expected until I got to pins 3-5. The program is setting the pins to 1 - one by one. Pin 3 goes on (program step) then 4 goes on (program step), then 3 goes off(not in my logic - that I know of maybe the timer ??) then 5 goes on (program step) and 4 goes off (seemingly by itself). Pins 6 and 7 are set by the program and stay on - as expected.

Why do you want to eliminate shift registers? Just board space? Because those shift registers are so fast it isn’t as if the observer is going to notice that you are refreshing slower, it’s going to be sufficient anyway unless your chain of shift registers are huge. You can use digitalWriteFast to write to those things and they keep up fine. If you are eliminating external circuitry that implies you are driving the matrix directly. So 1024 LEDs direct drive off a 2560? Have you considered the overall current limitations of the microcontroller?

With only 32 LEDs on at a time, I should be using about 640mA. I am planning to use MIC2981 to source the current and ULN2803 as a common sink. They should be able to handle the load. My reason for looking at doing the circuit w/o shift registers was simplicity and board space. Another reason is the learning curve. I am fairly new at circuit design. If (when) this project is running, I want to design an RGB version. Definitely will need shift registers for that one!!