Close

Groovy Circuit Explained...

A project log for Random Ridiculosities and Experiments

Sometimes yah's just gots tah try somethin', regardless of whether it'll become a full-fledged "project"...

eric-hertzEric Hertz 01/23/2016 at 14:220 Comments

Here's an explanation for the circuit in my last log...

First:

If you haven't seen it yet, check out this groovy circuit I came up with!

0->3.3V PWM (20-80% duty cycle) 
                V+
                ^
                |
                \
             R1 /
                \
                |  D2
                +--|>|----.
                |         |
                |       __|__| D3
                |      | / \   3.3V
                |       /___\  Zener
            C1  |  D1     |
0->3.3V >---||--+--|<|----+----->  >----.
                |         |             |
                \        === C2         \ Amp
             R2 /         |             / Input
                \         V             \ ~30k
                |        GND            |
                V                       V
               GND                     GND

OK, so I'm not 100% certain it does what I think it does... but it seems darn-close. Here's what I intended:

My audio-amp's input is biased at 0V... so a 0V input results in a 6V output. ~0.4V input results in 12V output. ~-0.4V results in a 0V output. Odd, yes... it is, in fact, a single-supply amplifier... Obviously, they were expecting AC-coupling.

This circuit serves several purposes. First: It converts PWM to a (roughly) linear voltage... kinda like an R/C filter / averaging-circuit. Second, and more importantly, it "shifts" that "average" down into a range for the input, such that e.g. 20% PWM Duty-Cycle results in -0.4V output to feed into the audio-amp's input so that its output will be 0V. Third, hopefully, the "linearizing" aspect is limited to a *single* PWM cycle, thus if the PWM duty-cycle changes dramatically suddenly, this should respond to that quickly, rather'n slowly rising to the change like would happen with an R/C filter.

Starting with the AC-Coupling capacitor C1...

0->3.3V >---||------>  >----.
            C1              |
                            \ Amp
                            / Input
                            \ ~30k
                            |
                            V
                           GND

Feeding a high-enough-frequency PWM signal through the AC-coupling-capacitor results in basically the same waveform fed into the amp-input, except shifted to be "centered" around GND...

At 50% duty-cycle, it's perfectly centered...

50% duty-cycle AC-coupled:

3.3V .-----.     .---    +1.65V  .-----.     .---
     |     |     |               |     |     |
     |     |     |   -->  0V - - | - - | - - | - -
     |     |     |               |     |     |
0V   '     '-----'       -1.65V  '     '-----'
As the duty-cycle is varied, the DC-component of the input-signal varies, but that DC-component is removed by the AC-coupling capacitor C1. The result is that the *peaks* (both negative and positive) of the waveform shift up and down. The *average* is kept at 0V, so then, basically, the *area* of the upper portion of the waveform and the area of the lower portion of the waveform are kept equal...
~10% duty-cycle AC-coupled:

3.3V .--.        .--.      2.9V  .--.        .--.
     |  |        |               |A1|  A2    |
     |  |        |   -->         |  |   |    |
     |  |        |          0V - | -|- -v- - | - - 
0V   '  '--------'       -0.4 V  '  '--------'
So, A1 ==A2, the waveform shifts up, but its amplitude is unchanged, 3.3V.

Well, this alone is fine for my motor-driving-purposes... -0.4V is still low enough to cause a 0V output during the low portions of the PWM cycle. And the amp's input seems perfectly OK with 2.9V, which is >>0.4V input necessary to output 12V. So, we have, roughly, PWM on the audio-amp's output, to drive the motor. Awesome.

Except, this audio-amp has a very slow slew-rate for my needs... A square 50% duty-cycle input at my 32kHz PWM frequency results in an almost perfectly triangular output.

That's fine, I was kinda interested in experimenting with *linear* voltage control of the motor, rather'n PWM, in the first place... So, now how do I linearize my microcontroller's PWM output...? Typically, an R/C filter, right...? Except, I need its output to go *negative* from a 0-3.3V rectangular-wave... hmm... And I don't have a negative voltage-supply to feed into a voltage-divider, or whatnot... And, de-facto, If I find the *average* of the AC-coupled signal, it'll always be 0V.

Also, it'd be ideal if the "averaging"/linearization circuit doesn't introduce any noticeable delay... E.G. if the PWM signal changes from 50% to 80% in a single cycle, it'd be awesome if that change is fed to the motor almost immediately, rather than slowly rising, as an "averager" would do... (This part is the part I'm not certain my circuit accomplishes...)

OK, so the output of the AC-coupled signal has portion of the PWM cycle that *goes negative*... and somehow I'd like to "average" *that negative value* and not the *entire* value...

So, then I thought: a peak-detector:

0->3.3V >---||-----|<|----+----->  >----.
            C1     D1     |             |
                         === C2         \ Amp
                          |             / Input
                          V             \ ~30k
                         GND            |
                                        V
                                       GND
Now, that signal drawn before is fed into the diode and C2 such that... if the voltage on C2 is greater than the signal (which goes down to -1.65V in the 50% duty-cycle case), the voltage on C2 will drop down to (roughly) the input-value of -1.65V. Excellent.

If C2 is large enough, it will maintain that value throughout the whole PWM cycle... So, its value will be (roughly) a constant -1.65V. Awesome, right...?

So, the output of the negative-peak-detector circuit above is always negative, since it's detecting negative peaks. I figured, why not feed that guy's output into a voltage-divider to pull its, say, ~-3V to ~0V output up to something more like -1V to +1V...

                          V+
                          ^
                          |
                          \
                          /<------------.
                          \             |
                          |             |
0->3.3V >---||-----|<|----+             |
            C1     D1     |             |
                         === C2         \ Amp
                          |             / Input
                          V             \ ~30k
                         GND            |
                                        V
                                       GND

But, now there's

more loading on that capacitor... I've got to think about R/C

constants a bit more, etc... I dunno exactly, it just didn't quite

sit right with me, and I didn't even bother building it... At some

point it occurred to me, wait, I could bias *before* the diode! Then

any loading caused by the biasing-circuit would be handled by the the

signal's *source* rather than by my detector-circuit, right...?

                V+
                ^
                |     / Bias somewhere
                \    /  'round 1.65V-0.4V...?
             R1 /   /
                \  /
            C1  | / D1     
0->3.3V >---||--+--|<|----+----->  >----.
                |         |             |
                \        === C2         \ Amp
             R2 /         |             / Input
                \         V             \ ~30k
                |        GND            |
                V                       V
               GND                     GND
FAIL!

And not because of my hokey estimation of the bias-point. That's easily adjusted into reason with an input-signal, 'scope, and using a potentiometer for R1 and R2. Just adjust the potentiometer (R1 and R2) so a 50% duty-cycle input results in a 0V output at C2.

No, the problem is the diode is never *on* when the lower portion of the PWM cycle is *positive* (after the AC-coupling capacitor). Which, of course, it intentionally does now when the duty-cycle is above 50%... So it's basically a negative-voltage-only-peak-detector, completely destroying the purpose of the biasing in the first place...

So, then, a pull-up resistor at C2... right? Duh... same problem as the biasing on C2, have to think about those R/C constants and whatnot... How many PWM cycles would it take to rise to a change in Duty-Cycle...?

And what when C2 has too large a value, and the PWM duty-cycle decreases to 10%? The "negative peak" is now -0.4V, much higher than -1.65V on the capacitor... The diode remains "switched off" and the capacitor's only means of reaching that -0.4V is to deplete its charge through the audio-amp's input... This takes some time. The microcontroller is telling that motor to stop ASAP, but it's not stopping until that capacitor depletes!

I tried a few things, came up with a few ideas, but nothing really seemed to do the job. Kinda gave up on the idea of accomplishing the task of a *linear* output for the motor... At least, without a negative voltage supply. Maybe I should just stick with PWM *output* and lower that PWM frequency so the triangular edges are roughly unnoticeable (which would *definitely* be within the audible range).

A bit later it occurred to me... The PWM signal coming out of the microcontroller (as well as that on the output of the AC-coupling capacitor) always maintains a constant amplitude... 3.3V. When the duty-cycle decreases, in the case described earlier, the *positive* peak voltage, on the output of the AC-coupler, increases as well. Hmmm... maybe I can use that increasing *positive* peak to pull up the *negative* peak-detector. Thus the introduction of D2 and D3...

                   D2
                .--|>|----.
                |         |
                |       __|__| D3
                |      | / \   3.3V
                |       /___\  Zener
            C1  |  D1     |
0->3.3V >---||--+--|<|----+----->  >----.
                          |             |
                         === C2         \ Amp
                          |             / Input
                          V             \ ~30k
                         GND            |
                                        V
                                       GND

The idea, again, being that when the *positive* peak voltage (after C1) increases, it will pull up the voltage on the negative peak detector's C2. In hopes, then, that the "linearized" output will respond almost immediately to changes in the input PWM signal.

And... with this arrangement, those biasing resistors *can* be placed before D1/D2, which hopefully results in their having negligible effect on the charge/voltage stored on C2, so plausibly C2's value needn't really be calculated, just throw in a value and let the source provide the extra current necessary by the loading of the bias resistors.

Now, here's where I'm not *certain* it does *exactly* what I planned, increasing C2 to a really large value does seem to delay changes... so I guess I just lucked-out that the random values I chose seemed to do the job quite well.

So, for the past week or so, I've been working on a new circuit for my PWM source... This guy will handle up to 5 separate axes (the audio-amp chip can handle four). But the key-factor, for now, is that it will have easily-adjustable settings for experimenting with different motor-driver chips/techniques. E.G., with this system we've got to use locked-antiphase (there's only one input). And, since it's AC-coupled, the PWM value should never be allowed to reach 100% or 0%, or the output from the AC-coupling capacitor will go to 0. A few other settings would be handy to experiment with, as well.

So we have the display for adjusting settings, to the right of that is my microcontroller, the breadboard has the "peak detector" circuit. The red board between the breadboard and the 'scope is the audio-amp. The scope is showing the output of the AC-coupling capacitor and the output of the circuit.

This was the first chance I've had to connect the motor since it'd been waiting on this new microcontroller-circuit. With the brief testing I've done so far, the system (the "groovy circuit" in particular) seems to meet my goals darn-near perfectly. Yeah, it's not perfect, but it's doing the job.

Discussions