| Author |
Message |
|
|
Posted: Mar 11, 2010 - 09:15 AM |
|

Joined: Mar 11, 2010
Posts: 6
|
|
So what might be the simplest way to create sine from uC (except DDS IC). Frequency scale: few kHz to over 100 kHz. Low output voltage (mV). What kind of limitations are related to uC PWM output to sine considering this case (frequency?). How about triangular wave to sine, limitations?.
Thanks already! |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 09:26 AM |
|


Joined: Dec 31, 2005
Posts: 632
|
|
| Use a phase accumulator (adder) and a sine table and output PWM. |
_________________ RES - http://www.attiny.com
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 09:34 AM |
|

Joined: Dec 15, 2005
Posts: 532
Location: Bristol, UK
|
|
| (that's sound like PWM, not a sine wave) |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 09:56 AM |
|

Joined: Nov 20, 2008
Posts: 333
Location: Cambridge, UK
|
|
|
MartinM57 wrote:
(that's sound like PWM, not a sine wave)
Pass PWM generated like that through a low-pass filter (eg a resistor and capacitor) and you'll get a reasonable approximation to a sine wave. However, it strikes me that 100kHz is pushing it a bit for an AVR using this method. Might be possible if you're not doing much else with the AVR.
There's a simple DDS signal generator project based on an AVR around these parts somewhere which should show you just what you need to do.
CH
== |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 09:59 AM |
|


Joined: Jul 18, 2005
Posts: 33138
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
(that's sound like PWM, not a sine wave)
What makes PWM and sine mutually exclusive then?
 |
_________________
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 10:10 AM |
|

Joined: Dec 15, 2005
Posts: 532
Location: Bristol, UK
|
|
It's OK CL, I'm completely with you
RES omitted the somewhat important aspect of passing the PWM into a LPF, which given the OP's apparent knowledge would seem important to add - as well as seeming to claim that it would be good for the required frequency range, whereas it might be a struggle at the top end... |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 10:14 AM |
|


Joined: Jul 18, 2005
Posts: 33138
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
passing the PWM into a LPF
As always I'd recommend AVR335 as a starting point for folks to understand about how to do analogue generation with a CPU that doesn't have an accessible DAC. That explains how the LPF converts the varying width digital to an analogue waveform.
Or, as an alternative, it's always worth mentioning building an external DAC with an R-2R:
http://www.myplace.nu/avr/minidds/index.htm
Oh but these days I guess the Xmega's are worth a mention too as they have 12-bit DACs built in.
(there's one or two of the tiny/megas that have DAC too - I think they the "lighting" devices?) |
_________________
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 10:21 AM |
|

Joined: Aug 07, 2007
Posts: 517
Location: Czech
|
|
|
Quote:
How about triangular wave to sine, limitations?.
There are methods to adjust triangular to sinus using several diodes or low signal mosfet.
The plus is that you can get higher frequencies (say 1 MHz).
The minus is a greater distortion. |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 10:57 AM |
|

Joined: Mar 11, 2010
Posts: 6
|
|
| Thanks everyone! uC+10 bit serial DAC+filter seems interesting at this point. How about the code, is it going to be heavy? I suppose 100k freq for uC PWM output to sine method wound be too high? I have to look more closely that triangular to sine more closely. If that works, I guess the code wound be lighter. Anymore suggestions? |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 11:09 AM |
|

Joined: Nov 20, 2008
Posts: 333
Location: Cambridge, UK
|
|
|
Makerdoer wrote:
Thanks everyone! uC+10 bit serial DAC+filter seems interesting at this point. How about the code, is it going to be heavy? I suppose 100k freq for uC PWM output to sine method wound be too high? I have to look more closely that triangular to sine more closely. If that works, I guess the code wound be lighter. Anymore suggestions?
I think the limiting factor is going to be how fast you can shovel data out to the DAC.
The project Cliff pointed out is the one I was thinking of. This uses 9 cycles per iteration to update an accumulator, lookup an 8-bit value from a 256-point lookup table, and output the value to a port.
You can probably count on needing 12-15 cycles per iteration if you're going to send 10-bit data to a serial DAC. If you use a 20MHz AVR that gives a sample rate of a bit over 1MHz. You should be able to get reasonable sinewaves up to 100kHz using this method with fairly simple filters.
The waveform doesn't make much difference to the computation required, since you just read the waveform values out of a lookup table, but getting a good-looking squarewave at 100kHz is much more of a challenge than a sinewave at the same frequency, because of the sharp edges.
Basically, the design looks OK if you don't want to do anything else much with the AVR.
CH
== |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 02:05 PM |
|


Joined: Jul 27, 2001
Posts: 5142
Location: St. Leonards-on-Sea (UK)
|
|
|
|
|
|
|
Posted: Mar 11, 2010 - 03:43 PM |
|

Joined: Oct 07, 2002
Posts: 978
Location: Skørping Denmark
|
|
If you need it you can speed the software DDS up so it only take 6 CLK (7 for same resolution).
Max freq at 20 MHz will then be 1.6 MHz but to call it a sine wave you need about 20 updates pr. periode so 167 KHz so you can make your 100 KHz this way. |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 05:15 PM |
|


Joined: Dec 30, 2005
Posts: 2041
Location: Longmont, CO USA
|
|
|
sparrow2 wrote:
Max freq at 20 MHz will then be 1.6 MHz but to call it a sine wave you need about 20 updates pr. periode so 167 KHz so you can make your 100 KHz this way.
And, apparently, not much else!
As long as this is the only task your AVR is doing, this is a pretty slick solution.
Stu |
_________________ Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.
(My boss always chooses Cheap. Twice.)
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 06:05 PM |
|

Joined: Mar 11, 2010
Posts: 6
|
|
| So in practise serial DAC is out of question for 100kHz sine and higher? How about parallel DAC or R-2R ladder then, takes one whole port but should be ok. I suppose it is easy to change sine freq by using this DAC method, eh. What about that tri wave to sine, any comment? Limitations? Btw. nice projects, miniDDS etc. |
Last edited by Makerdoer on Mar 11, 2010 - 06:13 PM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 06:13 PM |
|


Joined: Feb 19, 2001
Posts: 18830
Location: Wisconsin USA
|
|
|
Quote:
So in practise serial DAC is out of question for 100kHz sine and higher?
Quote:
(except DDS IC)
??? If you are going add an external chip, why the prejudice against a DDS? |
|
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 07:58 PM |
|


Joined: Sep 04, 2002
Posts: 13373
Location: Orlando Florida
|
|
| If the freq doesnt have to change, just output a square wave at whatever freq you want, add an RC lp filter and an RC hp filter, see if looks 'good enough'. (You cant see less than a couple percent distortion on a scope). If not, I bet an LC filter will make it look perfect. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Mar 11, 2010 - 08:12 PM |
|

Joined: Mar 11, 2010
Posts: 6
|
|
| I need few frequencies. Sine frequencies like 5kHz, 50kHz and 100kHz (or higher). So frequency has to be selectable. |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2010 - 12:55 AM |
|


Joined: Mar 12, 2003
Posts: 620
Location: Portland, Oregon USA
|
|
Are you trying to make a 'function generator' that will give you control of the amplitude and the frequency of the sine wave? This is probably impossible to do with an AVR alone. If this is the goal then use the AVR to control the parameters of a MAX038 or an XR2206 chip.
I believe, (but I haven't done it) that the pulse width modulation method that AVRs use to make a DC voltage level can be used instead of the resistors that control the frequency and amplitude on the function generator chips.
I have had some success controlling the frequencies of the old Texas Instruments SN94281 complex sound generator chip that Radio Shack sold long ago. I used Maxim serial DACs with an AVR on the digital side and the DAC output (with a small resistor) on the 94281's SLF and VCO resistor inputs.
If you only need a good sine wave at one specific frequency then do PWM on the AVR and adjust the AVR clock speed. Or use a 74HC4046 VCO to make the AVR system clock and use a pot on the 74HC4046 VCO input control. |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2010 - 02:44 AM |
|


Joined: Sep 04, 2002
Posts: 13373
Location: Orlando Florida
|
|
| If you have an 8 bit parallel dac, you can probably feed it in a 1 or 2 usec loop using a 16 or 20 mhz avr. Lets say 1 usec... 20 instructions or so.... A 10 step sin wave will look steppy in front of the filter, but it should look pretty good after it, at about 100khz. You can get 6db per bit attenuation amplitude control by shifting right just before stuffing the sample in the dac. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Mar 12, 2010 - 04:10 PM |
|


Joined: Mar 12, 2003
Posts: 620
Location: Portland, Oregon USA
|
|
If you only need three or four selectable frequencies in the range of 5KHz, 50KHz, and 100KHz, then a microprocessor shouldn't be the foundation of your circuit. It would be better to use op-amps, resistors, capacitors, and a flashlight bulb to make an old-fashioned radio-style oscillator circuit. One circuit for each frequency. Or, if I may repeat my suggestion from a previous post, use a function-generator chip like the MAX038 or XR2206 with a fixed resistor/capacitor combination for each frequency needed.
This frequency range is too slow to use specialized digital RF signal generators and too fast to be generated by microcontrollers. The cost of a serial DAC would be the same for an XR2206 and you still have to write, debug, and document all the code to get it to work.
Best of luck. |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2010 - 06:26 PM |
|

Joined: Mar 11, 2010
Posts: 6
|
|
| How about attiny26? It has fast PWM included. Could this be used for 100kHz sine formation? ...and yes certain measurements are done at the same time. |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2010 - 06:44 PM |
|


Joined: Jul 27, 2001
Posts: 5142
Location: St. Leonards-on-Sea (UK)
|
|
| A software DDS can easily cope with those frequencies. |
_________________ Leon Heller
G1HSM
leon355@btinternet.com
|
| |
|
|
|
|
|
Posted: Mar 12, 2010 - 06:56 PM |
|

Joined: Mar 11, 2010
Posts: 6
|
|
| Yea, i know. But i'm looking for other options now. |
|
|
| |
|
|
|
|
|
Posted: Mar 12, 2010 - 07:41 PM |
|


Joined: Dec 31, 2005
Posts: 632
|
|
|
|
|
|
|
Posted: Mar 12, 2010 - 08:07 PM |
|


Joined: Jun 16, 2006
Posts: 229
Location: Palmetto, FL
|
|
|
Simonetta wrote:
use a function-generator chip like the MAX038 or XR2206
The MAX038 has been obsolete for a long time, I used to like this part.
The XR2206 only goes to 1MHz, which should be fine for the OP. Another solution is using an XMEGA which has an integrated DAC. I have implemented an arbitrary waveform generator using an XMEGA. You can look at the code and see some videos if interested:
http://www.gabotronics.com/development-boards/xmega-xmultikit.htm
The great thing about it is that it uses the DMA, so once you set it, up it just runs in the background without CPU intervention, unlike the DDS. |
_________________ www.gabotronics.com
|
| |
|
|
|
|
|