Low Frequency Oscillator (LFO) 0.3 Hz to 20Hz

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey all!

 

I want to know the best way to produce an adjustable LFO sine waveform in the frequency range of 0.3 Hz to 20 Hz. The code will later be adapted to incorporating other waveforms (triangle, square...etc.), but sine will do for now. I've read multiple posts that suggest DDS for the waveform generation but since my waveform is at such a low frequency, is DDS even necessary or can I generate the wave by other means? I was using the waveform generation technique found in this link (https://github.com/hsabro/tap-tempo) but the problem is when you go to a lower frequency, the amplitude also gets reduced. 

 

Thanks for reading and I look forward to your suggestions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, and welcome to AVR Freaks!

 

The technique of choice is usually a DDS. It works especially well at low frequencies and is quite compact for code usage. It is also relatively simple. Hard to beat it.

 

Square wave can be done with timers, only, and is probably simpler than DDS. Triangles are pretty easy to generate by non-DDS techniques. BUT, for sine or for something that can generate a variety of waveforms, DDS is what I would recommend.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Mon. Oct 21, 2019 - 05:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the welcome, ka7ehk!

 

Is there any resources that you'd suggest for getting rolling with the adjustable LFO waveform? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is a now somewhat historic DDS implementation that is probably archived on this forum somewhere, but not sure where. I recall that it is a DTMF generator so it creates two tones simultaneously. It should be easy to trim out the second tone. So, I would start with a search, here, for DTMF. Don't remember the author's name, sorry!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Uggh, the author was Jesper and it was DDS rather than DTMF. Sorry for the false hint.

 

Jim

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No worries. I've already did some research on Jesper's method. It uses an R2R network, which I'm not really wanting to do. The previous link I shared generates an LFO using a waveform table and has a phase accumulator to advanced through the waveform's values, using a low-pass filter to remove the PWM signal. My problem with the link I shared is that as the frequency gets lower so does the amplitude. Is there anything I can do to fix this? I'd much rather prefer to have only the microcontroller and maybe a low-pass filter as hardware in this waveform generation design. Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you insist on filtered PWM, that is the cost you face. There is another scheme, however, that uses a sample/hold

 

https://www.edn.com/design/analo...

 

By the way, the conventional DDS algorithm can use any analog conversion structure. I would probably use a purchased DAC. I tried to look at the schematic at your github reference, and could find no reason for decreasing amplitude at low frequencies. Can you post the schematic that you are using?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Mon. Oct 21, 2019 - 06:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grandmascookies wrote:

 I've read multiple posts that suggest DDS for the waveform generation but since my waveform is at such a low frequency, is DDS even necessary or can I generate the wave by other means? 

DDS is well suited to this, because it allows direct define of frequency. It is not 'necessary' to use DDS, but it seems the simplest given you say "I'd much rather prefer to have only the microcontroller and maybe a low-pass filter as hardware in this waveform generation design."

 

 

grandmascookies wrote:

No worries. I've already did some research on Jesper's method. It uses an R2R network, which I'm not really wanting to do. The previous link I shared generates an LFO using a waveform table and has a phase accumulator to advanced through the waveform's values, using a low-pass filter to remove the PWM signal. My problem with the link I shared is that as the frequency gets lower so does the amplitude. Is there anything I can do to fix this? I'd much rather prefer to have only the microcontroller and maybe a low-pass filter as hardware in this waveform generation design. Thanks!

Your frequency is low enough, that you can DDS with PWM filter ok, or you could choose a MCU with a DAC included.

For the PWM design, you would choose some PWM frequency, eg Sysclk/128 or Sysclk/256 or Sysclk/1024 etc  and then you can run the DDS-Adder at that speed, on the PWM interrupt.

 

eg 16MHz with /512 and 20Hz gives 1536 x-Axis steps per sine cycle.  The ~31KHz PWM is easily filtered with a simple 2nd order low pass, as it is well above your 20Hz 

If your table is not 1536 in size, the DDS will either skip or read same as it cycles thru the table

Last Edited: Mon. Oct 21, 2019 - 09:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is what puzzles me. If it is a low-pass filter, the corner should be above 20Hz and there should not be much variation in amplitude.

 

However, now I realize, that when the frequency gets really low, a voltmeter, itself, will fail to respond properly. And, the lowpass filter will no longer function as it did at 20Hz. The original poster can try the experiment of increasing the size of the capacitor in the filter. It won't work as well at 20Hz but it should work better below 1Hz. If this is the case, then its stuck in the "basic physics of things". That is the cost of using PWM! The sample/hold scheme I linked above could be a solution.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grandmascookies wrote:
... in the frequency range of 0.3 Hz to 20 Hz.
Precision?

Accuracy?

SINAD?  (includes phase noise or, iow, jitter)

grandmascookies wrote:
... or can I generate the wave by other means?
Yes by generating a square wave that's low-pass filtered through a switched capacitor filter.

0.1% max distortion for 100Hz to 10KHz

Might reach 0.1Hz though the 1/f noise might not meet your requirement (jitter)

 

The Art of Electronics 3rd Edition | by Horowitz and Hill

[subject index, page 23, "oscillator, sine wave", pages 435-436, "A. Sine from square"]

LTC1069-1 Datasheet and Product Info | Analog Devices

Low Power, 8th Order Progressive Elliptic, Lowpass Filter

MAX294 8th-Order, Lowpass, Elliptic, Switched-Capacitor Filters - Maxim

MAX293 8th-Order, Lowpass, Elliptic, Switched-Capacitor Filters - Maxim

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grandmascookies wrote:
My problem with the link I shared is that as the frequency gets lower so does the amplitude.
Same issue with a Wien-bridge oscillator (first bridge half sets the frequency by RC, second bridge half for amplitude, 0.01% or less distortion, 0.001% distortion by four op amps instead of one)

The Wien-bridge oscillator amplitude issue has simple solutions (by incandescent lamp, nJFET, or opto-isolator)

My guess for making a Wien-bridge oscillator variable frequency is to replace the two equal R in the frequency control loop by a dual nJFET; the transconductance is inversely proportional to temperature so proportional control of the two Vgs by temperature (assumes low dT/dt, setting the operating point would need some thought)

 

2 equal R :

The Art of Electronics 3rd Edition | by Horowitz and Hill

[subject index, page 23 top middle, "oscillator, Wien bridge", page 437, "Figure 7.20 Wien-bridge low-distortion oscillators. ..."

 

One R :

AN-6604 JFET Circuit Applications (ON Semiconductor)

[page 6]

Figure 21. Wein Bridge Sine-Wave Oscillator

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is why I want to see an actual circuit schematic. If it is hardware, then there should be a way around it. If it is software, then there is something really wrong.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
There is another scheme, ...
PWM-input DAC though would consider its accuracy (edit : and noise)

ka7ehk wrote:
I would probably use a purchased DAC.
DAC are common in XMEGA with reduced precision DAC in some late model AVR.

Check the errata for these as there may be defects (excessive noise therefore LPF, temperature?)

 


PWM to Voltage Output D/A Converters | Analog Devices

ATxmega32E5 - 8-bit PIC Microcontrollers (DAC 12b)

ATMEGA4809 - 8-bit Microcontrollers (DACREF 8b to AC and ADC)

Digital to Analog Converters|Intelligent Analog|Peripherals|8-bit | Microchip Technology

via ATTINY3217 - 8-bit Microcontrollers (DAC 8b)

 

 

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Mon. Oct 21, 2019 - 09:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

ka7ehk wrote:
I would probably use a purchased DAC.
DAC are common in XMEGA with reduced precision DAC in some late model AVR.

Check the errata for these as there may be defects (excessive noise therefore LPF, temperature?)

 

Small MCUs with DACs can be cheaper than standalone DACs, such are the volumes these days....

 

SiLabs EFM8BB3 series have 2 x 12b DACs, for sub 60c/1k

If 8b DAC are good enough, the Tiny212/412/214/414 series have 1 x 8b D/A for sub 50c/1k

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How  "pure"  do you need you sinewave?  DDS & digital methods will inject a bit of noise & quantization of levels.   In that regards, some analog methods might be quieter.  However DDS is generally the method of choice these days.   

 

for $4 you can get an actual DDS chip:

https://www.newegg.com/p/2S7-01JK-02AB9?item=9SIABKS8X78902&source=region&nm_mc=knc-googlemkp-pc&cm_mmc=knc-googlemkp-pc-_-pla-new+ocean+tech-_-gadgets-_-9SIABKS8X78902&gclid=EAIaIQobChMI4-jegb2u5QIVrfbjBx36VAL1EAkYBiABEgI0LPD_BwE&gclsrc=aw.ds

 

Wonder what the lowest cost , low freq, one is?

 

Note also, that for real low freqs, you can/could calculate the values (each point), on-the-fly, as needed.  There are some simple fixed-point methods out there.   That saves  space (no big table), which might allow it to be in a chaepo 8-pin AVR talking to a cheapo dac. chip. if you had 5Hz & 720 points per cycle (1/2 degree) that would only be about 4000 points per second to figure out.  

Of course, that isn't DDS per se, unless you build it around a phase accumulator.

 interesting stuff:

https://www.coranac.com/2009/07/sines/

https://ccrma.stanford.edu/~juhan/pubs/jnam-emile05.pdf

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Mon. Oct 21, 2019 - 11:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

What is the frequency-resolution you need?
What is the sine-quality you need?
 

The XMega is best suited to do waveform output. Because of event system and DMA.
Maybe you can try to have two waveform tables in RAM. One for actual output and one for preparing new frequency/amplitude.
The output frequency depends on sample frequency divided by table length (one period).

Several MHz sample frequency should be possible. Frequency fine adjust is by table length.

Kaum macht man's richtig - und schon geht's!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whether you use a PWM signal or a SW DDS to R-2R ladder or to DAC, you typically still need a LPF to remove the higher frequency components in the signal from "step" waveform.

 

Building the filter with an op-amp also gives you a decent signal driver level for whatever the signal is feeding.

 

I'd suggest, (as above), an Xmega with its internal DAC, feeding an external LPF.

 

Not mentioned so far is yet another option, a (DDS) signal generator chip, controlled by a micro, (Analog Devices, etc.).

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At 20Hz, if you had 100 pints per cycle , that's only 2000 points/sec to spit out.  You can prob do that many fast sine calcs/sec & avoid a table altogether.  The  needed LP filter gives the smoothness (from DAC  or PWM).   Theoretically you only need 2 points/cycles (for a single freq component sin)...but those 40 samples/sec really would stretch the limit of any filter...usually having >double or triple min is desired.  In any case, other waveshapes have more/higher freq compontents...so  higher sampling is needed anyhow

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I recommend getting one or a few of these AD9833 module boards from eBay: https://www.ebay.com/itm/AD9833-...

 

  They will do in hardware easily the frequency range that you have specified.  It has the crystal oscillator and all the other resistor/capacitor support parts that you need. You can study the Arduino libraries available for this part to get it working.  Add an op-amp like the LM358 (which works on +5V-gnd voltage range) to adjust the amplitude of the low frequency waveform.

 

  I always recommend people using hardware instead of software solutions for quantities of 10 or less of your finished product.  Get the prototype working first, then focus on making it smaller, faster, cheaper, etc...   This board is only a few dollars and is quite possibly as cheap as the price of the parts (IC, crystal, PCB, and so on).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for the late reply on this one, I've been busy with some non-AVR stuff. I started venturing down the route of using a digital potentiometer (Microchip MCP41050) to do the waveform generation via SPI connection. I adjust the 8-bit potentiometer to match my 8-bit lookup tables and the results look great in the DC coupling mode of my oscilloscope. The range extends from 0v to 5V and the amplitude doesn't decrease based on my frequency, which was happening in my initial post. 

 

In order to get the digital potentiometer to match my needed frequencies (0.18Hz to 14Hz) and amplitude, I use timer 0, have it set to interrupt, and advance through the 8-bit table depending on the frequency. I've tried a sine, triangle, sawtooth, square, and I'm getting great results using the DC coupling mode on my oscilloscope, but the AC coupling mode doesn't have the peaks like DC.

 

I've attached the wiper of the digital pot to a unity-gain buffer, which has the input biased to 4.5V (standard biasing in guitar pedals). I've actually attached this to a phaser pedal and successfully got the effect to work using the LFO described.

 

Should I use the digital pot to generate the waveform or should I now venture into looking at a digital-to-analog converter that is 8-bits or more to generate the waveform for me? 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See Tip #1 for how to put the image in the post - so that we can see it in context:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Digtal pots are often rather lousy, or have horrible temperature coefficients  (like 10000ppm)...If used as a volume control, no one cares, they just turn it up more until the sound is pleasant.

Dacs started life as a more precision component--however, pots keep improving.  I'd still go with a dac.

At 20Hz tops, you could likely just use a pwm charging a 2-pole RC stage followed by a buffer....that would be good for an 8 pin app.

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the advice. I'm going to order an 8-bit DAC and try my method. Do you have any suggestions on a simple 8-bit SPI DAC? I've been looking and found a couple, but if there's one preferred more than others, I'll try that one.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

try this...get one with internal reference...

 

http://ww1.microchip.com/downloads/en/DeviceDoc/22244B.pdf

 

how about an AVR with the built-in dacs?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grandmascookies wrote:
Do you have any suggestions on a simple 8-bit SPI DAC?

I like the i2c DAC’s, like the mcp4706/4716/4726.

Either will work in your project.

 

jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Tue. Nov 5, 2019 - 07:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
Building the filter with an op-amp also gives you a decent signal driver level for whatever the signal is feeding.
In-lieu of the op amp :

Simple Circuit Turns PWM Into an Adjustable Precision Reference

by Rick Mally

Feb 10, 2012

The circuit uses the ubiquitous LM431 shunt regulator to implement a second-order Sallen-Key low pass filter together with a level shifter.

...

Compared to the traditional approach, it provides a far sharper roll-off along with a low-impedance output, bipolar output. 

...

The LM431 can be purchased for as low as 10 cents in single-unit quantities, well below that of any op amp.

...

via Ideas for Design: Vol. 1, No. 5 | Electronic Design

 

"Dare to be naïve." - Buckminster Fuller