Very slow quadrature generator - Page 1
Forum section: electronics / projects

author: Didgitalpunk
author_rank: Contributor
timestamp: January 17, 2019, 06:11:04 am
content: 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!

author: hamster_nz
author_rank: Super Contributor
timestamp: January 17, 2019, 08:32:33 am
content: 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...

author: Ian.M
author_rank: Super Contributor
timestamp: January 17, 2019, 10:45:25 am
content: 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.

author: Dave
author_rank: Super Contributor
timestamp: January 17, 2019, 11:51:24 am
content: 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.

author: Didgitalpunk
author_rank: Contributor
timestamp: January 17, 2019, 12:35:03 pm
content: Quote from: hamster_nz on January 17, 2019, 08:32:33 amyes 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).Quote from: Dave on January 17, 2019, 11:51:24 amwhat's a DDS algorithm? some kind of lookup table?Quote from: Ian.M on January 17, 2019, 10:45:25 amI 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.

author: Kleinstein
author_rank: Super Contributor
timestamp: January 17, 2019, 01:13:15 pm
content: 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.

author: MasterT
author_rank: Frequent Contributor
timestamp: January 17, 2019, 01:16:20 pm
content: There is a projecthttp://interface.khm.de/index.php/lab/interfaces-advanced/arduino-dds-sinewave-generator/help you start with DDS. Adapting code to sin/ cos pair should be no more difficult than "copy-paste"

author: Ian.M
author_rank: Super Contributor
timestamp: January 17, 2019, 01:18:21 pm
content: 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 17, 2019, 03:12:29 pm
content: One of the simplest solutions is a quadrature oscillator such as the one attached.

author: mark03
author_rank: Frequent Contributor
timestamp: January 17, 2019, 04:18:38 pm
content: 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.

author: bd139
author_rank: Super Contributor
timestamp: January 17, 2019, 04:23:23 pm
content: 3Hz is pretty fast. Should be able to do this with a simple analogue quadrature oscillator. need decent quality, large film caps though.

author: Ian.M
author_rank: Super Contributor
timestamp: January 17, 2019, 07:07:17 pm
content: 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.

author: Wolfgang
author_rank: Super Contributor
timestamp: January 17, 2019, 07:09:20 pm
content: Use an 8-Pin PIC and do it via PWM.

author: Ian.M
author_rank: Super Contributor
timestamp: January 17, 2019, 07:17:15 pm
content: 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.

author: Wolfgang
author_rank: Super Contributor
timestamp: January 17, 2019, 07:29:14 pm
content: 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.

author: Domagoj T
author_rank: Frequent Contributor
timestamp: January 17, 2019, 08:02:04 pm
content: Two potentiometers being rotated back and forth by a small stepper motor?

author: Wolfgang
author_rank: Super Contributor
timestamp: January 17, 2019, 08:05:22 pm
content: Wont last long, but certainly looks cool.

author: Domagoj T
author_rank: Frequent Contributor
timestamp: January 17, 2019, 08:12:48 pm
content: https://www.vishay.com/docs/51056/p30l.pdfShould last 20+ years at max frequency with uptime of 8 hours per day.$65 at quantities of 1.Stepper motors are dirt cheap, so there's that, at least.

author: Wolfgang
author_rank: Super Contributor
timestamp: January 17, 2019, 08:22:32 pm
content: 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.

author: Domagoj T
author_rank: Frequent Contributor
timestamp: January 17, 2019, 08:36:16 pm
content: That was just the first search result for "long life potentiometer". There several in the P11L series (also by Vishay) that are in the $15 ballpark.Metal hardware is available on evil bay, for about $1 a pop.https://www.ebay.com/itm/Flexible-Shaft-Coupling-Joint-Stepper-Motor-Coupler-Connector-3-10mm-All-Size/153132080540?hash=item23a7621d9c:m:mf3Q6A8KUC9VoqJ-qHGx3Cw:rk:2:pf:1&frcectupt=trueStepper drivers, additional 1$ a pop.https://www.ebay.com/itm/1PCS-A4988-Stepper-Motor-Driver-Module-3D-Printer-Polulu-StepStick-RAMPS-RepRap/221921771119?epid=883626200&hash=item33ab917e6f:g:BpsAAOSwl9BWKyv1:rk:1:pf:1&frcectupt=trueFor controller there is Arduino, there are some awesome stepper libraries available.OP said power is not a problem.I'm still unsure of the final application, but imagine opening the enclosure and seeing a pair of googly eyes staring back at you while spinning around.Would it work though?

author: joeqsmith
author_rank: Super Contributor
timestamp: January 18, 2019, 01:53:02 am
content: 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.

author: BrianHG
author_rank: Super Contributor
timestamp: January 18, 2019, 02:15:57 am
content: 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...

author: SilverSolder
author_rank: Super Contributor
timestamp: January 18, 2019, 03:14:38 am
content: 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.

author: Didgitalpunk
author_rank: Contributor
timestamp: January 18, 2019, 12:20:34 pm
content: Quote from: mark03 on January 17, 2019, 04:18:38 pmI... 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.

author: Ian.M
author_rank: Super Contributor
timestamp: January 18, 2019, 01:35:59 pm
content: 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 sinewavesOTOH 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.

author: Didgitalpunk
author_rank: Contributor
timestamp: January 18, 2019, 03:51:07 pm
content: Quote from: Ian.M on January 18, 2019, 01:35:59 pmIndeed, the entire radar setup is WAAAAAY out of my reach. For now it's more of a project to learn to work with high voltages (~10kV for the crt acceleration) and have a "cool looking" thing in my room. The curve tracer is a good idea, I'm gonna be building what amounts to a basic scope anyways to drive the CRT, so I would only have to make the actual curve tracer after that.

author: Wolfgang
author_rank: Super Contributor
timestamp: January 18, 2019, 04:32:30 pm
content: Have you seen the curve tracers from ChangPuak ?https://www.changpuak.ch/electronics/Curve_Tracer_advanced.php

author: BrianHG
author_rank: Super Contributor
timestamp: January 18, 2019, 05:27:59 pm
content: Quote from: BrianHG on January 18, 2019, 02:15:57 amJust 1 note, is you only need 3Hz, just use the simple floating point Sin() and Cos(), the MCUs are plenty fast today if you are only generating 2 sines with a minimum 32khz sample rate.As for the Audio DACs, a stereo thru 8 channels I2S DAC from TI is only around 4$ today, and it internally up-samples as low as 32k source audio samples to 384k meaning less MCU processing clock cycles and no output filters.With 24 bits, you plenty room to run a 10 to 16 bit sine with another 8-14 bits for digitally controlled deflection position alignment and amplitude. With this depth, you can also add a look-up table to correct linearity in your display/electronics.Though, with some larger MCUs which can drive 1080p panels / or HDMI, add a 24bit ADC and you can make an all digital display curve tracer with on screen display.

author: Bud
author_rank: Super Contributor
timestamp: January 18, 2019, 05:53:55 pm
content: Digital phase splitterhttps://goo.gl/images/8fNnRYFollowed by a 4Hz LPF on each shoulder to remove the harmonics

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 18, 2019, 06:25:08 pm
content: Quote from: SilverSolder on January 18, 2019, 03:14:38 amGood point, I don't know what kind of specs the op requires though in terms of distortion.I suggested an op-amp-based quadrature oscillator as a simple solution (and that gives an opportunity to learn for those that didn't know this topology), but if the requirements are not too stringent and the OP is familiar with MCUs, PWM would indeed be a very decent solution and pretty low-cost too. For signals up to a few Hz, you could use PWM at a few tens of kHz while still keeping a good resolution and requiring only simple RC filtering. Would be a lot more flexible than the above analog solution as well.Note: If you're feeling adventurous and would like lower distortion than what you'd get with simple PWM, you may also implement a sigma-delta modulator. For signals up to a few Hz, even a modest MCU can do this if this is its only task.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: January 20, 2019, 03:40:48 am
content: I didn't read all posts, but I'm with Dave, the "super conductor" in one of the first handfull of posts.Use a uC."Arduino" folks could probably luse PWM and filtering on such low frequencies but a uC with 2 hardware DAC's or with an external DAC is much more convenient for a few bucks / peseta's / pegels / whatever.Something like the combined channels of a MCP4922 can reach 20 bit or so and would be plenty for smooth curves, but using the 2 channels of a single MCP4922 for X and Y is very probably good enough.

author: rhb
author_rank: Super Contributor
timestamp: January 20, 2019, 02:33:02 pm
content: The quadrature part is easy. That's just a precision analog integrator which is a stock data sheet circuit.The sine wave is harder to do with an analog circuit. I don't know if you could get a Wein Bridge oscillator to go that low. You should read "Max Wein, Mr. Hewlett and a Rainy Sunday Afternoon" by Jim Williams if you want to use an analog circuit.But any number of digital approaches are quite simple to implement.

author: Ian.M
author_rank: Super Contributor
timestamp: January 20, 2019, 03:58:17 pm
content: Quote from: rhb on January 20, 2019, 02:33:02 pmSee chapter 7 of“Analog Circuit Design”by Jim Williams.

author: EmmanuelFaure
author_rank: Regular Contributor
timestamp: January 21, 2019, 06:37:31 pm
content: Another way without a DAC, using a delta-sigma technique. Requires only a µC with a digital output, a analog input, and a cheap RC circuit acting as an integrator.Pseudo code :while(1) {if(voltage < sin(2.pi.3Hz)) {output = 1;}else {output = 0}delay(); <- Not mandatory. The sin() computing delay should be enough to delay the loop (On an arduino ~100µs).}In attached file : A simulation of the output signal done with excel.