Author Topic: Very slow quadrature generator  (Read 3741 times)

0 Members and 1 Guest are viewing this topic.

Offline DidgitalpunkTopic starter

  • Contributor
  • Posts: 24
  • Country: fr
Very slow quadrature generator
« on: January 17, 2019, 06:11:04 am »
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!
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Very slow quadrature generator
« Reply #1 on: January 17, 2019, 08:32:33 am »
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...
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 
The following users thanked this post: Didgitalpunk

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Very slow quadrature generator
« Reply #2 on: January 17, 2019, 10:45:25 am »
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.   
« Last Edit: January 17, 2019, 10:53:10 am by Ian.M »
 
The following users thanked this post: Didgitalpunk

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1352
  • Country: si
  • I like to measure things.
Re: Very slow quadrature generator
« Reply #3 on: January 17, 2019, 11:51:24 am »
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.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 
The following users thanked this post: Didgitalpunk

Offline DidgitalpunkTopic starter

  • Contributor
  • Posts: 24
  • Country: fr
Re: Very slow quadrature generator
« Reply #4 on: January 17, 2019, 12:35:03 pm »
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. |O

« Last Edit: January 17, 2019, 12:39:46 pm by Didgitalpunk »
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14206
  • Country: de
Re: Very slow quadrature generator
« Reply #5 on: January 17, 2019, 01:13:15 pm »
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.
 
The following users thanked this post: Didgitalpunk

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: Very slow quadrature generator
« Reply #6 on: January 17, 2019, 01:16:20 pm »
There is a project http://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"
 
The following users thanked this post: Didgitalpunk

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Very slow quadrature generator
« Reply #7 on: January 17, 2019, 01:18:21 pm »
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.
 
The following users thanked this post: Didgitalpunk

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14478
  • Country: fr
Re: Very slow quadrature generator
« Reply #8 on: January 17, 2019, 03:12:29 pm »
One of the simplest solutions is a quadrature oscillator such as the one attached.
 
The following users thanked this post: Didgitalpunk

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 711
  • Country: us
Re: Very slow quadrature generator
« Reply #9 on: January 17, 2019, 04:18:38 pm »
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.
 
The following users thanked this post: EmmanuelFaure, Didgitalpunk

Online bd139

  • Super Contributor
  • ***
  • Posts: 23026
  • Country: gb
Re: Very slow quadrature generator
« Reply #10 on: January 17, 2019, 04:23:23 pm »
3Hz is pretty fast. Should be able to do this with a simple analogue quadrature oscillator. need decent quality, large film caps though.
 
The following users thanked this post: Didgitalpunk

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Very slow quadrature generator
« Reply #11 on: January 17, 2019, 07:07:17 pm »
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.
 
The following users thanked this post: Didgitalpunk

Offline Wolfgang

  • Super Contributor
  • ***
  • Posts: 1775
  • Country: de
  • Its great if it finally works !
    • Electronic Projects for Fun
Re: Very slow quadrature generator
« Reply #12 on: January 17, 2019, 07:09:20 pm »
Use an 8-Pin PIC and do it via PWM.
 
The following users thanked this post: Didgitalpunk

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Very slow quadrature generator
« Reply #13 on: January 17, 2019, 07:17:15 pm »
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.
 
The following users thanked this post: Didgitalpunk

Offline Wolfgang

  • Super Contributor
  • ***
  • Posts: 1775
  • Country: de
  • Its great if it finally works !
    • Electronic Projects for Fun
Re: Very slow quadrature generator
« Reply #14 on: January 17, 2019, 07:29:14 pm »
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.
 
The following users thanked this post: Didgitalpunk

Offline Domagoj T

  • Frequent Contributor
  • **
  • Posts: 505
  • Country: hr
Re: Very slow quadrature generator
« Reply #15 on: January 17, 2019, 08:02:04 pm »
Two potentiometers being rotated back and forth by a small stepper motor?
 
The following users thanked this post: Didgitalpunk

Offline Wolfgang

  • Super Contributor
  • ***
  • Posts: 1775
  • Country: de
  • Its great if it finally works !
    • Electronic Projects for Fun
Re: Very slow quadrature generator
« Reply #16 on: January 17, 2019, 08:05:22 pm »
Wont last long, but certainly looks cool.  :-DD
 
The following users thanked this post: Didgitalpunk

Offline Domagoj T

  • Frequent Contributor
  • **
  • Posts: 505
  • Country: hr
Re: Very slow quadrature generator
« Reply #17 on: January 17, 2019, 08:12:48 pm »
https://www.vishay.com/docs/51056/p30l.pdf
Should 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.
 
The following users thanked this post: Didgitalpunk

Offline Wolfgang

  • Super Contributor
  • ***
  • Posts: 1775
  • Country: de
  • Its great if it finally works !
    • Electronic Projects for Fun
Re: Very slow quadrature generator
« Reply #18 on: January 17, 2019, 08:22:32 pm »
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.  >:D
 
The following users thanked this post: Didgitalpunk

Offline Domagoj T

  • Frequent Contributor
  • **
  • Posts: 505
  • Country: hr
Re: Very slow quadrature generator
« Reply #19 on: January 17, 2019, 08:36:16 pm »
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=true
Stepper 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=true
For 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?
 
The following users thanked this post: Didgitalpunk

Offline joeqsmith

  • Super Contributor
  • ***
  • Posts: 11747
  • Country: us
Re: Very slow quadrature generator
« Reply #20 on: January 18, 2019, 01:53:02 am »
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. 
 
The following users thanked this post: Didgitalpunk

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7739
  • Country: ca
Re: Very slow quadrature generator
« Reply #21 on: January 18, 2019, 02:15:57 am »
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/#msg1108123
You wont need to store this table, just generate it on the fly...
« Last Edit: January 18, 2019, 02:30:23 am by BrianHG »
 
The following users thanked this post: Didgitalpunk

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: Very slow quadrature generator
« Reply #22 on: January 18, 2019, 03:14:38 am »

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.
 
The following users thanked this post: Didgitalpunk

Offline DidgitalpunkTopic starter

  • Contributor
  • Posts: 24
  • Country: fr
Re: Very slow quadrature generator
« Reply #23 on: January 18, 2019, 12:20:34 pm »
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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Very slow quadrature generator
« Reply #24 on: January 18, 2019, 01:35:59 pm »
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.
« Last Edit: January 18, 2019, 01:37:34 pm by Ian.M »
 
The following users thanked this post: Yansi, Didgitalpunk


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf