During the last days I did some research because I'm about to order several parts needed for upcoming posts. But now this is done and I'm ready to share further findings.
After exploring PWM-signals I thought about how to control pulse width by using Raspberry Pis gpio-pins. At the very first moment it seemed easy: Take four pins and set any binary value controlled by software (0-15 means 6.66% for each step which is sufficient for my needs). A circuit will manage the current flow through resistors which values match the binary bit each gpio-pin represents. But studying the PWM-circuit shown in my previous post discloses that electric current has to flow in both directions through my resistors and using the potentiometer the value of the resistor on the way back is complementary to the value of the one the way there. This is what builds the typical PWM-signal. Building a circuit based on gpio-input behaving in this way seems to be pretty complicated. There has to be a better way to do this.
After a little bit of searching the web I found this page: http://www.spaennare.se/pwmdig.html#chap6. The guy who shared this information (his name is Stefan) is pretty smart and found an indeed elegant way to solve this problem:
The cycle of a PWM-signal can be divided into units which number is defined by the resolution at which we want to control the output current. I my case this is 15 because I want to use four gpio-pins (2^4=16 stages and 15 units between them). Stefan has chosen 100 stages so his circuit is a little bit more complicated as mine will be (but more precise). Each unit can now be at current (called high) or off current (called low). So for example if we want 13.33% output we have to keep the first two units of one PWM-cycle at high and the remaining 13 units at low.
So how could Stefan achieve this pattern? He COUNTED from zero to 100 and COMPARED each value to the requested (and inverted) level of current. If the second value is greater then it is high otherwise low. And this is periodically repeated. If the counter reaches 100 it starts at 0 again. COUNTING is done by the IC 4510 and COMPARISON by the IC 4585. The output of IC 4585 is exactly the PWM-pattern we need.
But his approach has three downsides which I want to get rid of:
First disadvantage is that he uses decimal units (100) which is not a numeric system supported by computers well. Computers use binary numbers because they only know high and low (a bit). You can use 7 bits to represent numbers up to 127 or 6 bit for numbers up to 63. 7 bits wastes some space and 6 bits is to small. So using any potential of two for the number of steps will fit better to Raspberry Pis gpio-pins. So I will use the IC 4029 which is a binary counter instead of the IC 4510 which is a decimal counter.
The second downside is that his circuit needs an inverted input-signal for working properly. Inverting the signal is not hard to do (Stefan gives an example circuit) especially if it is provided by a computer: simply invert the number by software before setting the gpio-pins. But inverting is not necessary as you will see.
The third downside is that Stefan uses 100 stages from 0% (motor does not rotate) to 99% (motor rotates at almost maximum of speed). This missing step to get 100% of speed is not a problem at all. But if you use 4 bits (as I do) every missing step is 6.25% and a maximum speed of 93.75% is a problem!
So what have I done:
In my descriptions above I said that each step is 6.66%. This is because I use 16 stages which represent values from 0% to 100%. Common binary counters (as IC 4029) use four bits and allow cascading for counting bigger numbers than 15 (they start at 0). As we use four gpio-pins we do not need to cascade (as Stefan needed to count up to 100) what simplifies the circuit.
Next is that I do not invert the input signal. So I also have to choose another output pin (in fact two of them: = and >) of the IC 4585 to get a proper PWM-signal.
The last action is to preset the counter at 1. This reduces to number of units by 1 but raises the output of the input-signal "1111" to 100%.
In my descriptions above I said that each step is 6.66%. This is because I use 16 stages which represent values from 0% to 100%. Common binary counters (as IC 4029) use four bits and allow cascading for counting bigger numbers than 15 (they start at 0). As we use four gpio-pins we do not need to cascade (as Stefan needed to count up to 100) what simplifies the circuit.
Next is that I do not invert the input signal. So I also have to choose another output pin (in fact two of them: = and >) of the IC 4585 to get a proper PWM-signal.
The last action is to preset the counter at 1. This reduces to number of units by 1 but raises the output of the input-signal "1111" to 100%.
So at the moment I'm waiting for receiving the parts I ordered (including ICs 4029 and 4585). As soon as they arrive I will test my theory and update this post by appending the circuit and pictures. So stay tuned!
UPDATE: I added another post ("Control motors - Part 3: Digital PWM - Part 2") to comment what happened during building the circuit.
UPDATE: I added another post ("Control motors - Part 3: Digital PWM - Part 2") to comment what happened during building the circuit.
Keine Kommentare:
Kommentar veröffentlichen