hello, I have a few questions: 1. how to run DAC on F149 ?!? I found info, that I need to calibrate it with DAC12CALON or smth. but I dont know really what I need exactly to do. 2. I need to make that DAC output will be sinewave. how to tell to DAC to make him a sinewave? thanx for any help.

# DAC. sinewave.

Started by ●April 25, 2005

Reply by ●April 25, 20052005-04-25

```
The '149 has no DAC, you are thinking of the '169. Whether or not you
need to calibrate it depends largely upon your application, and just how
precise you need things. other than the description in the data sheets I
don't know what to tell you, it is a simple straight forward procedure.
You cannot instruct the DAC to generate a sine wave. a DAC cannot output
a sine wave. The best it can do is output an approximation of a sine
wave, there will always be stepping present on the waveform since the
DAC cannot output decimal bits. To get the best sine wave you can create
a table of sinusoidal values and scale these to the DAC. being a 12 bit
DAC the output range is from 0-4095 unsigned or from -2047 to +2048
signed. If you adopt a scaling value of 2047 then to calculate any table
entry there are 2Pi radians in 360 degrees, or Pi/2 radians in 90
degrees. Since a sine wave comprises 4 quadrants you can save storage by
only storing one quadrant. since 90 degrees is by definition 2047 you
then only need to decide how many points per quadrant you need to
calculate for. The more points the better the approximation to a sine
wave. lets simplify things and use just 8 points per quadrant:- those
points, in degrees are:-
0, 11.25, 22.5, 33.75, 45, 56.25, 67.5,78.75
the 9th point is exactly 90 degrees, or 1, and the first value is 0, so
we need only store 7 points. Now calculate the sine value of these and
multiply that by 2047, then store the nearest rounded value. Sine values
are:-
0, 399,783,1137, 1447, 1702, 1891, 2008 and of course the assumed 2047
at 90 degrees.
Now you can see that this is quite a crude sequence of numbers having
large steps. you will reach a point where more resolution achieves very
little indeed. I find 1 degree to be quite a useful increment. This
gives 89 = 2047 and 90 = 2047, but the largest step, from 0 to 1 degree
is just 36, or, to stay binary, you could use 130 steps, lose 0 and 90,
which then leaves you with just 128 values in the table.
tables work very nicely for outputting sinusoids of different
frequencies. the maximum frequency you can out put is limited by your
number of steps, however you don't have to use every step!.
lets say you want a high resolution sine wave, and you want to do other
processing as well, which means you generate the sine wave using a
timer. you do this:-
Assume a 1 degree table, with no space saving, so there are 360 table
entries. lets assume an 8MHz clock, and the fatsest allowed interrupt
frequency to be 100 clock cycles. Thus your highest frequency will be
8,000,000/36,000 Hz, or 222.22Hz. Not very high. But what if, for higher
frequencies, we only took every 8th table entry? now we end up being
able to generate waveforms up to 1777.778hz. Still not high enough?
well, theoreticvally we can, with an adequate external filter use just 2
points, but lets say we have only 10 entries in our table then our
maximum frequency becomes 8kHz. Of course even this may be too low for
some applications, but for interrupt driven generation it is probably as
fast as you dare risk. Here the trade off is between quality of the sine
wave, and maximum frequancy obtainable. In a low overhead system written
in asm you could possibly drop to a minimum ISR period of 50 clock
cycles, giving you an 8 entry sinusoid of 16kHz.
using the interrupts will result in some jitter, but gives a more
flexible system than a hardtimed one, and a suitable external filter
should remove the artifacts caused by both jitter and stepping. This
could be a s simple as an RC low pass filter, or could be an active filter.
remember we have used 2's complement to calculate the values, but they
should be returned to unsigned for the final tables.
The very fastest results can be obtained by hardcoding the timing. for
this I would use some binary length of table:_
SINE_TABLE:
DW 0, 399,783,1137, 1447, 1702, 1891, 2008
DO_SINE:
CLR R5
MOV #TABLELENGTH,R4
NEXTVAL:
MOV SINE_TABLE(R5),&DACPORT
INCD R5
AND.W R4,R5
JMP NEXTVAL
The above executes in 9 clock cycles, so the highest frequency at 8MHz
is 888,888.889Hz/tablelength.
The very highest frequency available for a crude 8 entry table is:_
DO_SINE:
MOV.W R4,&DACPORT
MOV.W R5,&DACPORT
MOV.W R6,&DACPORT
MOV.W R7,&DACPORT
MOV.W R8,&DACPORT
MOV.W R9,&DACPORT
MOV.W R10,&DACPORT
MOV.W R11,&DACPORT
JMP DO_SINE
34 CLOCK CYCLES. Or 235,294Hz
Hope that stirred upa few ideas. there are 100's (well lotsd) of other
ways to do this but these are a few simple ones for now.
Al
HEX.loader wrote:
>hello,
>
>
>I have a few questions:
>
>1. how to run DAC on F149 ?!? I found info, that I need to calibrate
>it with DAC12CALON or smth. but I dont know really what I need exactly
>to do.
>2. I need to make that DAC output will be sinewave. how to tell to DAC
>to make him a sinewave?
>
>
>thanx for any help.
>
>
>.
>
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
>
```

Reply by ●April 25, 20052005-04-25

```
<....>
> Hope that stirred upa few ideas. there are 100's
(well lotsd) of other
> ways to do this but these are a few simple ones for now.
>
thanx a lot. I'll try to do my best...later ill post here with some
new questions. but now I have one question: what output voltage (how
many volts) is of F169 DAC? is it positive or negative? like I
understand it's alternative but dont pass negative side, so its
positive. or smth is wrong here? Im not sure. and it would be nice if
somebody tell me what output voltage is.
thanx a lot.
```

Reply by ●April 25, 20052005-04-25

```
You can select the reference, just like the ADC. To do bipolar you will
need an opamp biased at Vdacref/2..
Al
HEX.loader wrote:
><....>
>
>
>>Hope that stirred upa few ideas. there are 100's (well lotsd) of other
>>ways to do this but these are a few simple ones for now.
>>
>>
>>
>
>thanx a lot. I'll try to do my best...later ill post here with some
>new questions. but now I have one question: what output voltage (how
>many volts) is of F169 DAC? is it positive or negative? like I
>understand it's alternative but dont pass negative side, so its
>positive. or smth is wrong here? Im not sure. and it would be nice if
>somebody tell me what output voltage is.
>
>thanx a lot.
>
>
>.
>
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
>
```