I've been learning a lot in the recent few weeks and I'm super excited to use Arduino. I just had a question about something that's bothering me. Say I want to create a row of 8 LEDs and lit all of them at the same time. Obviously a neat way to do this is by using a shift register. Now let's say I also want to change the brightness of the LEDs. I understand this can be done using PWM, but isn't PWM also being used for the shift register?
Allow me to explain:
My understand of shift registers: I want to lit all 8 LEDs at the same time. So what I really do is turn them on 1 by 1. But I turn them on so fast, POV (persistence of vision) occurs and I 'see' all of them lit all the time. The method achieved to do this seems to be PWM (please correct me if I'm wrong): effectively each LED has a duty cycle of 12.5% (1/8). One question: the frequency matters, right? Assuming I have 100 Hz frequency, I should get POV. This would imply every 10 us I go through a period. And in each 10 us period, every LED is on for 1.25 us. Or does this actually mean a 800 Hz frequency?
My understanding of dimming/brightness control: Say I want to have 50% brightness. This would imply a PWM duty cycle of 50%. Say I do this at 1 MHz. Then in every 1 us period, the LED is turned on for 50% of the time (0.5 us) and turned off for 50% of the time (0.5us). But if this is true, then shouldn't the LEDs in the shift register example above be at 12.5% brightness? Since in the shift register case, an LED is on for 1.25 us and then off for 8.75 us.
My question is really: what's the difference? It seems to me both shift registers/POV and dimming use the exact same principle: PWM. So how can you get LEDs that are 100% bright continuously while using PWM.
Or is it really an issue of frequence? Is it such that at very high frequencies, shift registers demonstrate 100% brightness because LEDs turn ON/OFF so fast. And then if you want to dim, you effectively reduce that frequency,due to PWM/AnalogWrite()?
Sorry for any confusion, I tried to make this as easy to understand as possible.
You said you are using shift registers to control your LED's, but what you describe is multiplexing.
These are not the same.
Then you're confused about doing multiplexing and PWM.
If you're multiplexing, you are lighting up LEDs one after the other.
You would want to use multiplexing if you need to control more LEDs than the number of pins available for your project, but always within a certain limit (dictated by the number of pins you do have available).
As you described it, this is done in a relatively slow rate.
The PWM is a bit faster than that.
If you like, you can combine these.
Indeed the multiplexing will have some effect to the total brightness.
But the PWM dim will do the most here.
As stated before, you're mixing up 3 different techniques.
A shift register (there are different types available) receives a train of bits, which are then activated at the very same moment.
So all outputs that you have set will be enabled at the same time.
If you then apply PWM to the return path, you are dimming these LEDs or outputs directly with the duty cycle set by your PWM.
All techniques are using the lazy human eyes and POV to do their trick.
To make things even more complicated, you could use a set of shift registers to do multiplexing and apply PWM to that as well to control brightness (you can come across this when controlling dot matrix displays).
But let's work on the understanding of each technique first before you're going to combine those.
The short answer to your question is: "No.".
PWM and multiplexing or shifting out data are not related, except maybe for some internal timer they might share.
Forgot to mention, and in case you didn't know: Shift registers are external components (chips).
They offer you a lot of outputs (you can daisy-chain them) and only take up a few pins for that.
Data can be shifted into the shift registers, and a separate PWM applied to the OE/ pin of the shift register for dimming control.
analogWrite(PWMpin, 0); will be full on, and
analogWrite(PWMpin, 255); will be full off