-
Very slow quadrature generator
Posted by
Didgitalpunk
on 17 Jan, 2019 06:11
-
Hi,
I'm trying to find a simple way to generate a sine wave and its quadrature.
The problem I'm running into is doing it at very low frequencies, up to 3Hz MAX.
The whole point of this is to draw a perfect (or as close as it can be) circle on a scope in X-Y mode, as part of a larger project.
I don't want to use a function generator (or my sound card, like I've seen suggested on some websites) to generate these signals. It has to be standalone.
Has anyone ever done something like this?
does anyone have any pointers?
Thanks in advance!
-
#1 Reply
Posted by
hamster_nz
on 17 Jan, 2019 08:32
-
So all you want is something to generate sin() and cos() outputs at 3Hz, at any easy voltage range and any price, as long as it is battery powered?
Me?, I would use the 12 bit ADCs on an $7 ESP32 module.. Would just need to tweak the example design's code a little...
-
#2 Reply
Posted by
Ian.M
on 17 Jan, 2019 10:45
-
Doing that without digital techniques and without mechanical moving part is *difficult* even at 3Hz and gets proportionally harder as you reduce the frequency. If you want to go down that road, you need to investigate the circuits and techniques used for trig function generation in electronic analog computers as it will be much easier to generate a slow linear ramp representing angle and calculate sine and cosine from it rather than trying to generate them directly to acceptable tolerances. However I should caution you that its fairly close to being a dead art, with most of the progress in the field being over half a century ago, so much of what is online is either from retro hobbyists or is behind academic paywalls.
Is there any reason you couldn't work at say 100Hz? That would make it possible to get good results from various OPAMP ring oscillator circuits.
-
#3 Reply
Posted by
Dave
on 17 Jan, 2019 11:51
-
A DDS algorithm would be simple enough to implement on pretty much any microcontroller, considering how low the frequency is. A pair of 12-bit DACs would be more than sufficient to draw a nice smooth line, whether it's an analog or digital oscilloscope.
-
-
So all you want is something to generate sin() and cos() outputs at 3Hz, at any easy voltage range and any price, as long as it is battery powered?
Me?, I would use the 12 bit ADCs on an $7 ESP32 module.. Would just need to tweak the example design's code a little...
yes this sums it up, although it doesn't have to be battery powered at all. The end project will be plugged in mains power anyways.
I've never used or programmed an ESP32 though, the only chips I know how to program are atmega328's via the arduino environment (yeah, it's sad, I'm aware).
A DDS algorithm would be simple enough to implement on pretty much any microcontroller
what's a DDS algorithm? some kind of lookup table?
Doing that without digital techniques and without mechanical moving part is *difficult* even at 3Hz[...]
Is there any reason you couldn't work at say 100Hz? That would make it possible to get good results from various OPAMP ring oscillator circuits.
I wouldn't mid mechanical moving parts to generate the two signals, but moving parts are probably more expensive than a sub 10 dollar micro and a handful of parts. I did try to use a resolver to get my two signals since there's a native 90deg phase shift due to the arrangement of the coils, it doesn't work at 3Hz.
I need it to be 3Hz because those two outputs will be modulated by a fast saw-tooth so that what appears on the scope screen is basically a sweeping line *not unlike a radar PPI scope*. If you go too fast, what you get is just a disc.
-
#5 Reply
Posted by
Kleinstein
on 17 Jan, 2019 13:13
-
If the frequency is fixed, one could use a phase shift based analog oscillator, or a separate oscillator (Wien bridge type) and phase shifter, It is not that accurate but a simple circuit.
There are quite some DDS projects also for the AVR like Mega328 (usually more like Mega8). Usually these are 8 Bits. It is using kind of a lookup table, but with a clever way to generate the addresses.
The DDS solution could be using a multiplying DAC, so that the >DAC reference could be used for the modulation.
-
#6 Reply
Posted by
MasterT
on 17 Jan, 2019 13:16
-
-
#7 Reply
Posted by
Ian.M
on 17 Jan, 2019 13:18
-
OK, that gives a better idea of the application. One electromechanical approach to the problem would be a uniform resistive sheet with a bias voltage across it applied by two full-width contacts along opposite edges carrying equal and opposite DC voltages, and a rotor, rotating at 180RPM carrying two moving contacts at 90 deg to each other, at the same radius on its face, picking up sine and cosine voltages from the resistive sheet, and transferring them to fixed contacts via slip rings. The amplitude could be altered by varying the DC bias voltage.
You could probably get there with no rotating contacts by using a rotating ring magnet and two analog hall sensors, with a suitable angular separation between them, but sinewave quality would be highly dependent on the pole pattern of the magnet and the exact positioning of the sensors.
However IMHO you'd be foolish to attempt an electromecanial solution, as its easily achievable with radial modulation using a MCU running software DDS, and a pair of 12 bit multiplying DACs to convert the digital DDS outputs to analog X and Y signals, modulated by your radial signal.
-
-
One of the simplest solutions is a quadrature oscillator such as the one attached.
-
#9 Reply
Posted by
mark03
on 17 Jan, 2019 16:18
-
At those frequencies, forget the DDS look-up tables. Just have your atmega calculate floating-point sin() and cos() directly using the C math library! The only reason look-up tables are used in a DDS is because the full-fledged sin/cos calculation (using taylor series or whatnot) is too slow at "normal" frequencies. If your part doesn't have two D/A converters you could use two PWM outputs instead and RC-filter the result, depending how accurate this needs to be.
-
#10 Reply
Posted by
bd139
on 17 Jan, 2019 16:23
-
3Hz is pretty fast. Should be able to do this with a simple analogue quadrature oscillator. need decent quality, large film caps though.
-
#11 Reply
Posted by
Ian.M
on 17 Jan, 2019 19:07
-
The problem with a 3Hz analog oscillator is amplitude stabilisation without clipping or excessive harmonic distortion, and the time it will take to initially stabilise. If other lower frequencies are required it becomes even harder. The various digital synthesis options will be stable almost immediately after power on. Also, for the radial (amplitude) modulation, its almost certainly going to be far easier to obtain a linear response with multiplying DACs , rather than analog multipliers.
-
#12 Reply
Posted by
Wolfgang
on 17 Jan, 2019 19:09
-
Use an 8-Pin PIC and do it via PWM.
-
#13 Reply
Posted by
Ian.M
on 17 Jan, 2019 19:17
-
Possible, but then you are back to needing analog multipliers for the modulation, as the max PWM frequency with adequate resolution is too low to make direct modulation of the PWM (via an analog SPDT switch per channel) before filtering viable at more than a few KHz.
-
#14 Reply
Posted by
Wolfgang
on 17 Jan, 2019 19:29
-
Depends on the filter and the PIC clock rate. And if you think of a scope screen (1% accuracy maximum) its not so challenging.
If you want something better you could use an 877 PIC and do an R2R-DDS on two output ports, plus filtering.
-
#15 Reply
Posted by
Domagoj T
on 17 Jan, 2019 20:02
-
Two potentiometers being rotated back and forth by a small stepper motor?
-
#16 Reply
Posted by
Wolfgang
on 17 Jan, 2019 20:05
-
Wont last long, but certainly looks cool.
-
#17 Reply
Posted by
Domagoj T
on 17 Jan, 2019 20:12
-
-
#18 Reply
Posted by
Wolfgang
on 17 Jan, 2019 20:22
-
OK, why not do it the hard way. 65$ per pot, some metal hardware, stepper controller, lot of power compared to PICs, but you can *see* it work. It does *not* have to make sense to be fun.
-
#19 Reply
Posted by
Domagoj T
on 17 Jan, 2019 20:36
-
-
#20 Reply
Posted by
joeqsmith
on 18 Jan, 2019 01:53
-
3Hz is the upper but what is the lower? What soft of frequency resolution is needed? Do you need to sweep, or is the frequency fixed for the most part after it is adjusted? Any idea how clean the signals need to be? Drive levels?
I wonder if a 2 channel Arb would be a better choice. Basically, this is the direction I would go. Two DACs, an FPGA, oscillator or tied to the GPS, maybe just some dip switches to set the frequency.
-
#21 Reply
Posted by
BrianHG
on 18 Jan, 2019 02:15
-
I would use a cheap voltage output audio I2S stereo 24 bit DAC with a small 16bit or 32bit DSPic, using the PICs ADC if you want to sync to an external source reference sine wave. Search on this forum, we have already discussed making a true perfect sine and cosine waveform using only integer math available in any microcontroller with a 16 bit adder and 16 bit multiplier with access to the top additional 16 bits. Using a 24 bit stereo audio DAC running at 96Khz, you have no excuse about synthesizing a waveform which should roast anything under the sun well in-between 1Hz and 3KHz with only 2 ICs, 3.3v supply, for less than 4$ in parts. The circuit should perform well up to 20KHz.
However, you need to be able to program for microcontrollers in 'C'.
Perfect sine generator example using all integer math: (It will need adjustments for 3Hz and 24 bit amplitude)
https://www.eevblog.com/forum/microcontrollers/code-used-for-sine-table/msg1108123/#msg1108123You wont need to store this table, just generate it on the fly...
-
-
An Arduino can easily do this - use two PWM channels and change the PWM duty cycle to slowly create the sine waves in the two channels.
Put a simple RC filter on each channel to smooth out the PWM to a nice, clean, slowly changing voltage to drive the scope.
-
-
At those frequencies, forget the DDS look-up tables. Just have your atmega calculate floating-point sin() and cos() directly using the C math library! The only reason look-up tables are used in a DDS is because the full-fledged sin/cos calculation (using taylor series or whatnot) is too slow at "normal" frequencies. If your part doesn't have two D/A converters you could use two PWM outputs instead and RC-filter the result, depending how accurate this needs to be.
I... I don't know why I didn't think of this myself! I did just that with a simple RC filter (with R = 2.2k and C= 6.8F, beefy little foil cap!) and behold! a pretty good looking circle! I'll have to improve the signal a bit more, but it's good enough for now. Might try with a proper DAC, or an active filter.
Now, the point of all this.
I've been the proud owner since my granpa passed away a couple years ago of quite a bit of old gear, including and old heathkit O-12 oscilloscope lookalike (no heathkit markings on the PCBs and the metalwork looks like it was done by hand) which happens to have a long persistence 6" round CRT in it. After turning the lights in the room it's stored in, the tube continues to glow for a good 10 minutes.
since that 0-12 clone is missing more than a few parts, and doesn't have a case, I figured I had to make something with that CRT, and I though that making a radar PPI display lookalike was more than appropriate. and here we are.
The first step was generating a circle, the next is modulating it with a fast saw tooth to make a line rotate instead of just a point, and after that it's making the whole support circuitry for the CRT.
-
#24 Reply
Posted by
Ian.M
on 18 Jan, 2019 13:35
-
A PPI display isn't much use unless you have something to plot on it, and most worthwhile data sources on the internet (e.g. weather radar) have already been converted to a rasterised format. Building a rotary scan radar or sonar system from scratch, is almost certainly well outside your capabilities, or you wouldn't be here asking about generating low Hz frequency quadrature sinewaves
OTOH if you take a fast enough MCU board with three reasonably fast DACs (min 8 bits for X, Y and 6 for intensity) you could build a very nice vector graphics terminal.
Another scope CRT based project that's well worth building is a semiconductor curve tracer. Depending on the tube persistence, you may be able to display more than the usual eight curves for the stepped parameter.