32 channel light controller - which ports to use?

Hi I'm building a 32 channel light system which will be controlled from a spare Arduino Mega I have left over from developing another project

It would make sense for me to output my data to ports as four bytes rather than single pins

The AT Mega has 54 Digital I/O pins it says

I can see from the pinout that Port A and port C appear to be available for me to use as 8 bit ports as the pins have no other assignments

But lots of other IO pins seem to have allocations for interrupts or serial comms. I don't need to use i2c or SPI for this application.

Are there two other 8 bit ports I can use in this way without interfering with other functions? Port L seems to be pretty much free.....

I appreciate I could just use shift register/latches but why add other external hardware (apart from load drivers) if I don't need to.

Rich

Does this help? Shows Mega digital/analog pin names and some of the common uses.
Also which ports are used.

ATMega2560.xlsx (14 KB)

Couldn't open that file - is it the same info as this?

http://forum.arduino.cc/index.php/topic,146511.0.html

Port L seems to be clear apart from one pin(48) says ICPS but I don't know what that means or what it is used for - any idea?

Port B has four pins allocated for SPI, but I don't need that feature so guess these pins are avilable for I/O if I don't use the SPI Library? The other port B are pins 10,11,12,13 that I know I can use

So can I output to ports A B C and L byte-wise?

Rich

Same data, different format.
Try this one.
Looks like A, B, C, E, F, K, and L are all available as complete ports.
The original is an excel file that you can manipulate any way you like.

ATMega2560.pdf (112 KB)

I decided to ressurrect this as I now have all the hardware built and tested for my 32 channel conroller and can turn channels on and off using PORTX commands

I am using Ports A B C and L (becuase they are all conneted to the double rows of Digital Pin connections on the Arduino Mega (apart from four bits of Port B which are on pins 10-13). This made it easy to connect up to.

Anyway I now have another couple questions... I have done a bit of reading up but i am a bit confused by all the info I have read about this - from 'weird algoriths' I can't quite get my head around, to 'just do it in assembler instead'

Q1. What is the most efficient way of doing Bit Rotate with Carry on an byte (exactly like the Atmel ROR and ROL instructions)

Q2. How do I do a Bit Rotate as in Q1 but on a 16bit integer instead of a byte- this would suit my light controller better as I have 16 'Red' channels and 16 'White' channels

Q3. If i am handling 16bit integers as in Q2. above, what is the most efficient way to then output the MSB of the integer to PORTA and the LSB to PORTB (effectively split the integer into two bytes) and of course the same for PORTC and PORTL

Cheers for your ideas Rich

dicky96: But lots of other IO pins seem to have allocations for interrupts or serial comms. I don't need to use i2c or SPI for this application.

Those pins are multifunction. They start as I/O pins and only become serial/i2c/SPI when you tell them to.

@fungus Cheers - I already got past that issue now and have four ports I am controlling fine - it's the stuff about ROL and ROR in the post above your reply that I am currently pondering over...

dicky96: @fungus Cheers - I already got past that issue now and have four ports I am controlling fine - it's the stuff about ROL and ROR in the post above your reply that I am currently pondering over...

For a byte you could use a lookup table.

For a 16 bit int you can do something like this:

unsigned int ror(unsigned int a)
{
  unsigned int b = (a>>1);
  if ((a&1) != 0) {
   b |= 0x8000;
  }
  return b;
}

@CrossRoads

Thanks for the PDF, however when I wired things up on my Arduino Mega 2560 I found that the pin assignments for Port L differed from the documentation

FYI

35 48 L PL0 icp4 36 49 L PL1 icp5 37 46 L PL2 t5 38 47 L PL3 5A 39 44 L PL4 5B 40 45 L PL5 5C 41 42 L PL6 42 43 L PL7

Rich

You think there’s an error in the MegaR3 schematic then?

Well I can only report what I found

I know what you mean though - at first I thought NO I must have mixed up the wiring to the output transistors or to the LEds or something but check and check again I can only say my results show the pin assignment is indeed how I have described it

I rewired my controller and now it works as expected. It would be good if someone else could check and confirm this one way or the other

Rich