Author Topic: How many shift registers can an ATmega328P actually drive?  (Read 4635 times)

0 Members and 1 Guest are viewing this topic.

Offline botcrusherTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
How many shift registers can an ATmega328P actually drive?
« on: March 04, 2016, 12:46:15 pm »
Hello World!
My first post here on eev, question on how many shift registers you can actually drive from a run of the mill ATmega328P (running on a regular arduino board)
The arduino documentation says
Quote
Theoretically infinite
(Can't find where it says that at this moment) But obviously you'll run into a bandwidth issue after a short time.

Why am i interested in so many shift registers? Eh... No good reason, I've just *maybe* ordered a lot of 50 74HC595, so driving 480 / (160 3-colour leds) or anything else i can hook up sounds like fun to me.

once i hit saturation, any way i can use some kind of external chip (maybe an eeprom?) or other chip to latch certain sections?
Or, maybe i could drive parallel sections of these, i'd only need to change certain ones at the same time.
many of the lights will be connected to SSRs or transistors (think those lovely Sketchy meteor lights) or any other cheap-but-cool-but-might-blow-up-or-fry-me Chinese light.

I'm open to any theories, suggestions, or "have you gone mad?" posts.
 

Offline Robartes_m

  • Contributor
  • Posts: 21
  • Country: be
Re: How many shift registers can an ATmega328P actually drive?
« Reply #1 on: March 04, 2016, 12:58:08 pm »
Well, there's logically and electrically.

Logically, it really depends on how many LEDs you want to drive and how quickly you want to refresh them. That, combined with the clock rate at which you shift out data limits how many shift registers you can chain.

Electrically, there is things like signal degradation and propagation times (notably that of the latch signal) that will limit the number of registers you can chain.

 

Offline MK14

  • Super Contributor
  • ***
  • Posts: 4527
  • Country: gb
Re: How many shift registers can an ATmega328P actually drive?
« Reply #2 on: March 04, 2016, 01:06:38 pm »
You might find that (for LEDs), you are better off with some of the many available special purpose LED driver ICs.

They can have many useful features (at reasonable cost), such as (as well as already being serial, i.e. the shift registers are built in). Allowing many brightness levels, with built in programmable (moderately high, constant and programmable) current drivers. With (potentially), many led outputs, per IC.

Example:

TLC59281DBQR, about $0.50 in quantity, with 16 outputs.
« Last Edit: March 04, 2016, 01:09:22 pm by MK14 »
 
The following users thanked this post: ilium007

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14159
  • Country: de
Re: How many shift registers can an ATmega328P actually drive?
« Reply #3 on: March 04, 2016, 01:09:38 pm »
There is a limit how much capacitance the output of the µC can drive an still keep a reasonable rise time. At something like a 500 ns maximum rise time and a 20 mA output current this gives 10 nC or about 2 nF as maximum capacitance. This is something like 100 Chips or 20 m of cable.  However it is possible to use extra drivers for the clock signal and thus increase the power as much as needed, as you could have something like 10 Chips plus 1 clock driver for the next section.


So the limit is more the memory, unless you have a loop and use the shift registers as memory too.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12851
Re: How many shift registers can an ATmega328P actually drive?
« Reply #4 on: March 04, 2016, 01:11:03 pm »
The issues are update rate and available RAM to store the data to be shifted out via the SPI peripheral.   The device only has 2KB of RAM total, and it can all be shifted out in a small fraction of a second.   However you would need clock distribution trees to provide buffered shift and store clocks to avoid fanout limitations.  As '595 type shift registers are entirely synchronous, propagation delays either in the daisy-chained data path or in the clock distribution trees are rarely significant.
 

Offline botcrusherTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
Re: How many shift registers can an ATmega328P actually drive?
« Reply #5 on: March 04, 2016, 01:42:08 pm »
Alright. So in theory, if i generated sequences and put them on an external eeprom, and then puked them out onto the "shift train" I'd then only have to worry about  clock?
 

Offline MK14

  • Super Contributor
  • ***
  • Posts: 4527
  • Country: gb
Re: How many shift registers can an ATmega328P actually drive?
« Reply #6 on: March 04, 2016, 01:47:04 pm »
Alright. So in theory, if i generated sequences and put them on an external eeprom, and then puked them out onto the "shift train" I'd then only have to worry about  clock?

Yes, that's right.

EEPROM for non-volatile storage.

Or ram, sram (maybe serial type, such as SPI), if its (power off) volatility does not matter.

If you were desperate (on a desert island, with *ONLY* 50 shift registers), you could even use your extra shift registers, as output port expanders. Giving you even more driving capabilities.

In the "old" days, some calculators, computers and even TVs (PAL with missing line replacement, using glass wire thingies), use to use a similar method.

E.g. Mercury delay lines, CCDs, various wire/glass vibrating delay lines etc etc.

Some literally were giant chains of shift registers, others used physical properties of stuff, to get a similar "signal". I.e. Delay lines, etc.
« Last Edit: March 04, 2016, 01:56:20 pm by MK14 »
 

Offline botcrusherTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
Re: How many shift registers can an ATmega328P actually drive?
« Reply #7 on: March 04, 2016, 02:21:03 pm »
Crazy thought, what if i used the clock to control a single shift register, and then connected a shift register to each parallel output, could i use the serial out pin to act as a clock for the later chips?
Bits 0-7 go into shift register, gets pumped into bit 0 of each following register,  bit 8 is fired from the ATmega, goes right to the serial out, serial out is connected to the clock in on each of the parallel registers.
I feel awfully evil right now.

To clarify, clock out bits 0-7 8 times to fill the other registers, then send an extra bit on the 8th iteration to clock the other registers
« Last Edit: March 04, 2016, 02:23:13 pm by botcrusher »
 

Offline MK14

  • Super Contributor
  • ***
  • Posts: 4527
  • Country: gb
Re: How many shift registers can an ATmega328P actually drive?
« Reply #8 on: March 04, 2016, 02:42:51 pm »
Crazy thought, what if i used the clock to control a single shift register, and then connected a shift register to each parallel output, could i use the serial out pin to act as a clock for the later chips?
Bits 0-7 go into shift register, gets pumped into bit 0 of each following register,  bit 8 is fired from the ATmega, goes right to the serial out, serial out is connected to the clock in on each of the parallel registers.
I feel awfully evil right now.

To clarify, clock out bits 0-7 8 times to fill the other registers, then send an extra bit on the 8th iteration to clock the other registers

You may just about, be able to get some sort of "crazy" scheme to work.

But in practice you would probably find it a developmental *NIGHTMARE*, and also it would probably be notoriasly unreliable in practice.

E.g. It could have what are called "Race hazards/conditions".

https://en.wikipedia.org/wiki/Race_condition

Essentially this would mean that, depending on temperature, luck and if there is a sun solar flare at the moment in time, your circuit could malfunction, explode, or even disappear entirely and reappear, simultaneously in two different universes, at different points in time.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12851
Re: How many shift registers can an ATmega328P actually drive?
« Reply #9 on: March 04, 2016, 02:45:27 pm »
Quote
Crazy thought . . . .
That would be total madness.  The overheads of bit-banging that would make it significantly slower than simply daisy-chaining them.

You don't have many good options to speed things up on an ATmega328P.  If you were using a more powerful MCU with DMA and a parallel master port with strobe, you may be able to boost performance at the expense of port pins by wiring N separate chains of shift registers to the port (where N is the PMP width in bits), and clocking them with the PMP strobe output.   Whether or not there is enough performance gain to be worth it depends on the maximum clock speed of the SPI peripheral,  whether or not it can do continuous back to back transfers, compared to the maximum DMA bandwidth to the PMP port, so you need to study the MCU in question's datasheet in detail.

One option that will work even with a relatively slow 8 bit MCU like the ATmega328P is to stream the data direct from an external SPI memory to the latch chain.   At its simplest this means the latch chain data in is connected to the memory SDO pin and the SCK clocks the latch chain shift clock (via an OR gate to include a /CS signal).  The MCU reads and discards a memory block, which transfers it to the latches, then the store clock is strobed to update them.   One can get more complex with a fast external clock generator gated by an output compare peripheral of the MCU or a divide by N counter, to generate a burst of N clock pulses on demand, and a multiplexor for SCK, so that once the transfer is set using the SPI peripheral, it can be handed off to the external clock that will transfer N bits without MCU intervention.
 

Offline botcrusherTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
Re: How many shift registers can an ATmega328P actually drive?
« Reply #10 on: March 04, 2016, 03:12:21 pm »
MUHUHAHAHAHAH!
I'm going to try that out once they arrive just to see how haphazard it would be.
But seriously, noted. Are there perhaps any arduino compatible boards that run at high speed? Or at least a board that uses C?
Assembler looks scary...
 

Offline MK14

  • Super Contributor
  • ***
  • Posts: 4527
  • Country: gb
Re: How many shift registers can an ATmega328P actually drive?
« Reply #11 on: March 04, 2016, 03:18:24 pm »
MUHUHAHAHAHAH!
I'm going to try that out once they arrive just to see how haphazard it would be.
But seriously, noted. Are there perhaps any arduino compatible boards that run at high speed? Or at least a board that uses C?
Assembler looks scary...

There are many (amazingly low cost), and potentially very high speed development boards, that work well with C.

By the sound of it, you maybe need to choose one, with many I/O pins, already built in.

For around the $10 mark, you can get something which is probably almost as powerful, as a PC from about a couple of decades ago.

Take your pick (Excuse the awful pic/pun/fun).

http://uk.farnell.com/embedded-development-kits-primary-platform
« Last Edit: March 04, 2016, 03:23:01 pm by MK14 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf