Standalone AVR IO Control - Chip and Programming Questions

Hi all,

This is my first project graduating from normal Arduino programming to using an AVR chip directly. My application is relatively simple (sending commands to the chip to set ports either high or low), but I need between 56 and 62 IO ports, depending on final design decisions.

My current setup roughly copies existing Arduino setups: I send commands over USB to a FT232R chip which then contacts an ATMega2560 via TX and RX and tells it which pins to set low or high. I expect my code to be quite small, as the chip won't be doing many calculations of its own. After trying my best to research the answers to my questions, I have 2 main concerns left:

  1. I have recently begun to wonder if I wouldn't be better off with 3 ATMega328p's communicating via SPI/I2C due to the ease of programming them and incorporating into a breadboard. Note that I've only been looking at existing Arduino chips to make things simpler for myself. I will be making 3-4 devices total, so I will be designing this all into a PCB. Are there any recommendations for which chip setup is easier, or for a completely different chip?

  2. Initially I was thinking of using AVRstudio and a programmer, but it seems that using the Arduino IDE and Arduino Uno as ISP might be easiest. I have some concerns about using the Arduino IDE though. I don't want to use the Mega pinout, as I want more control over which pins I am using so I don't overload the max current of any port (as outlined in the ATMega2560 datasheet). If I use "port manipulation", will that give me access to all the pins? Are there any other concerns for using the Arduino IDE for a standalone chip? Can an Uno even be used to program an ATMega2560 successfully?

Hopefully that made sense. Thank you!!

  1. I have recently begun to wonder if I wouldn't be better off with 3 ATMega328p's communicating via SPI/I2C due to the ease of programming them and incorporating into a breadboard.

That's not really "elegant" but it might be the easiest approach.

You can also expand the number of I/O ports with a multiplexer or [u]shift registers[/u]. For example, I have an Uno running 48 individually-addressable LEDs driven by special-purpose serially addressed (shift register) LED driver chips, and it only takes 3 I/O pins.

  1. Initially I was thinking of using AVRstudio and a programmer, but it seems that using the Arduino IDE and Arduino Uno as ISP might be easiest. I have some concerns about using the Arduino IDE though. I don't want to use the Mega pinout, as I want more control over which pins I am using

I'd say at least start developing your project with the IDE.

And it might be just as easy to modify the IDE as to "start from scratch".

...The coolest thing about the Arduino is the IDE and the fact that the bootloader is "built-into" the board, and the board itself is the hardware development kit. I've used several different compliers/IDEs over the years and I usually allow a day to get the compiler installed and configured, and get "hello world" running. It took me about 15 minutes to download & install the Arduino IDE and get "Blink" running, and that was amazing!

If I use "port manipulation", will that give me access to all the pins?

I've never used the port commands but I assume so. But, the other microcontrollers/microprocessors I've used only had port commands.

Yes, it maybe time to start using ‘Shift Registers’.

Look into TPICs

tpic6.PNG

You could drive the project with an ATmega88 (will fit and work on an Uno) and 7 or 8 shift registers. If you need more than 6mA a pin with all pins ON, get a ULN2803 or like per register or wire transistors to all those pins and resistors either way. 56 to 62 outputs is going to take a lot of wires no matter what.

Shift registers on SPI bus get filled at 512K bytes per second. 64 bits is only 8 bytes, you could change them pretty frequently.

Thanks for the quick replies.

After a short shift registers tutorial, it seems they will be appropriate for this project. Just to make sure I understand the concept:

I can send bits to a daisy-chain of shift registers, telling them whether to set their output pins high or low. I can then latch them to get all of the pins to activate at once. The outputs are independent of one another, so I can set them all high, all low, or some mix (unlike with a multiplexer).

I've used "shift registers" in LabVIEW for years, but never really used the physical thing... I think it gave me an inaccurate idea of what they can and can not do.

Regarding the controller chip - is there a reason you recommend the ATMega88 over the ATMega328? Also, would it be reasonable to cut out the extra chip and just use the FT232R (or ATMega16U2... or equivalent) to control the shift registers directly?

"I can send bits to a daisy-chain of shift registers, telling them whether to set their output pins high or low. I can then latch them to get all of the pins to activate at once. The outputs are independent of one another, so I can set them all high, all low, or some mix (unlike with a multiplexer)."

Correct.

Select TPICs if you need to drive high currents.

The HIGHs may vary as to current available per pin. IIRC the total may be 40 or 50mA max (exceed at peril) so what connects, matters.

I got output shift registers at 5 for $1. To do the shift-out tutorial right, the leds will not be bright. Input shift regs run closer to 1 ea and port expanders (bi-directional shift registers, many 4-bit versions) and drivers cost > 1 each.

Output shift register pins can open the gates of the low price (10 and 15 cents ea in qty 50 and 60) TTL level FETs I got off eBay (tested some, they work) without hurting Arduino pins. I tried it so I know it can be done, pins to FET gates w/o resistors. The gate capacitances aren’t so high when the full open voltage is so low? These are 2N7000 (or maybe 2N7777, 250mA max) and IRLZ44N (many amps max), I’m sure there’s loads more.

What I should look for is an 8 channel FET chip, like the ULN2803 Darlington array but efficient FETs instead. However the 7 channel ULN28xx chips are real cheap and can boost very small current to 20-25mA without much loss, if budget matters enough.