Electronics > Projects, Designs, and Technical Stuff

Generating a clean 10kHz sine wave from PWM

(1/10) > >>

robca:
(not sure if this belongs here or in Beginners)

I'm quite familiar with digital logic and microprocessors, get lost in the analog part...

I'm working with a prototype sensor that changes impedance when environmental conditions change (sorry, can't provide too many details on the sensor itself).

Currently the sensor is read by generating a 10kHz sine wave, and measuring the phase difference using two fast comparators and a digital 12 bit counter with a 2MHz clock. The comparators generate a pulse on zero crossing, one starting and one stopping the counter. The sensor value is read as a 12 bit value from the counter. I did not work on that circuit

I'm now trying to use a microprocessor to, as much as possible, duplicate the entire functionality. Everything runs at 1.8V. I can generate a PWM sine wave at 10kHz (albeit with only 40 values, and 40 steps to define the wave). I plan to use an active lowpass filter to generate as clean a sine signal as possible, 0.9V centered (1.8V Vpp). Then the sine wave is used to excite the sensor, which behaves like a variable inductance, and the excitation signal is fed into the microprocessor differential comparator 1, using 0.9V as a reference to detect zero crossing. That event will automatically start a 16MHz timer, no software needed.

The other end of the sensor is fed into another differential comparator, and the zero crossing there will stop the timer and generate an interrupt so that I can read the value in my code. The timer value is directly proportional to the phase difference, which is directly proportional to the sensor value, in turn reflecting an environmental value.

I tried using a basic lowpass RC filter to clean up my sine, with poor results and a very low Vpp as a result of the filtering. Please note that I don't really need a super-clean sine in the top and bottom part, which from everything I know it's the hardest to achieve. I need the cleanest possible signal at zero crossing, where the curve slope is almost linear and should be the easiest to achieve with a lowpass filter.

I've tried to explain my idea in the drawing below. I used a "mystery opamp filter", because I think that an active filter will help me achieve the best results, and help get a sine as close to 1.8V as possible. I can use up to 3 individual opamps and as many passives as needed, but keeping to BOM simple is a nice to have. One of the opamps in the quad opamp is needed to create a 0.9V reference for the sine wave/sensor. I might need to amplify further the sensor signal, if the sensor/resistor results in a too small signal. If not, probably I could use a dual opamp, not a quad one.

Please note that I'm aware that there is a logical circuit simplification: since I'm controlling the PWM signal, in theory I don't need the first comparator. I could start the timer for the phase difference when the PWM signal generator starts the wave from the 0 point. But I know that filters add a phase offset, so I plan to build the circuit, use the first comparator to get a reading of the offset, and use that in the future to calculate the actual phase difference due to the sensor. So the final circuit will only have one comparator. I designed it with two, to clarify better.

In any case, a clean 10kHz sine wave is a requirement. Can you please help me figure out a good active filter and help pick the passive values for my frequency? A single PWM pulse is 16MHz, and I use 40 pulses to represent values 0 to 40. So the PWM frequency is 400kHz. I have a 40 items LUT, to build the sine

Any type of input is appreciated

[attachimg=1]

mawyatt:
Interesting concept.

Just a question, could you just use a squarewave and measure the edge shift?

If you require an active LPF then and simple Sallen Key might be in order. You have 40 samples per waveform period so the sampling harmonic content should be far out frequency wise. Maybe a 2nd, 3rd order Butterworth SK might suffice. Watch out for the SK LP feedthru since these unwanted waveform artifacts will be relatively high frequency, and maybe high enough for considering a passive LC filter, or hybrid (active & passive).

SK LP feedthru is when the input couples thru the feedback capacitor since the op-amp output impedance isn't low enough. There are several ways to deal with this, use an op-amp with very high GBW product relative to the desired waveform frequency, bleed current from the output or add an output buffer to the op-amp to lower the output impedance, or use a topology where the input "sees" an RC lowpass before the feedback cap (3rd order).

Anyway, hope this helps.

Best,

Someone:

--- Quote from: robca on June 30, 2022, 12:01:44 am ---I plan to use an active lowpass filter to generate as clean a sine signal as possible, 0.9V centered (1.8V Vpp).
--- End quote ---
How many orders/stages/poles were you planning? Whats the PWM counter frequency and length/range options?

You are probably fine to just generate a 10kHz square wave and round it off with the active filter (5th order lowpass is cheap enough)

robca:

--- Quote from: Someone on June 30, 2022, 01:00:10 am ---
--- Quote from: robca on June 30, 2022, 12:01:44 am ---I plan to use an active lowpass filter to generate as clean a sine signal as possible, 0.9V centered (1.8V Vpp).
--- End quote ---
How many orders/stages/poles were you planning? Whats the PWM counter frequency and length/range options?

You are probably fine to just generate a 10kHz square wave and round it off with the active filter (5th order lowpass is cheap enough)

--- End quote ---
Well, how many poles is kind of the question :) That's what I'm trying to figure out. The simplest circuit that gets me a good enough slope to measure phase offset

As I mentioned the fastest PWM pulse frequency is 16MHz. I determined that using 40 possible pulses to represent 0-40 and 40 LUT points to define the values of the sine is the best compromise. That results in a 400kHz PWM frequency with 40 possible values. Using 40 points LUT, results in a neat 10kHz sine

From my point of view, the "cost" of using PWM or a square wave is the same. Once I program the microprocessor registers with the right values, the generation uses no CPU cycle. So I assumed that to get a clean sine, starting from a PWM sine would be better than a square wave. But that's an area I know very little

robca:

--- Quote from: mawyatt on June 30, 2022, 12:44:54 am ---Interesting concept.

Just a question, could you just use a squarewave and measure the edge shift?

--- End quote ---
In speaking with the sensor developer, he thinks that a sine wave is the best, given that we are dealing with an organic polymer that might not like the steep voltages in a square wave. Not sure I understood the chemical explanation, but intuitively it makes sense to me. And I'm also trying to approximate the existing circuit as much as possible, as least as a starting point (to avoid adding even more variables)

Thanks for all your other comments. If I may ask: I'm not sure I understand what frequency I should target for my lowpass filter. I'm sure it's a silly question, but that's one of the areas  I get lost. In playing with the passive RC lowpass, a filter frequency of 5kHz seemed to work better than a 10kHz one. Given the passive filter slope, it kinda makes sense, but I still can't figure out what I should be shooting for, without trying a lot of values, if you had to filter a 400kHz signal with 16MHz pulses in order to get a clean 10kHz sine, what filter frequency would you start from?

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version