Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how this program work

Status
Not open for further replies.

Cyrus the Great

Member level 4
Joined
Oct 30, 2011
Messages
79
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
IRAN
Activity points
1,765
hi i have seen a project which is making a sin wave in these way.first calculate some number which show the sample which create the wave such thise
Code:
flash char sin16[256]={128,176,218,245,255,245,218,176,128,80,38,10,0,10,38,80,128,176,218,245,255,245,218,176,128,80,38,10,0....
.
.
.
PORTA=sin16[i];
        i++;
.
.
....
and after that during the programming put this number on PORTA and after that use R-2R DAC to convert them to analog.so I want to know how dose it work.I mean that for example when 128 is on port A whats happen and how DAC change it to analog?
15.jpg

Best regard
 

The numbers are the values of points along a sine wave, multiplied by 128 then with 128 added to them. It makes the range of sine values -1 to +1 into 0 to 256.

The way it works is the values are sent to the PORTA pins in sequence and the resistor network values are arranged so that each bit produces a voltage equivalent to it's bit value. For example, if bit 0 produced a voltage of 0.1V, bit 1 would produce 0.2V, bit 3 would produce 0.4V and so on. When the binary values from the sine table are put on the pins, the weighting of the resistor values re-creates the sine wave voltage. It's a crude DAC using only resistors, you could connect a DAC IC to PORTA and get more accurate results.

Brian.
 
Dear betwixt
you mean that when 128 is on PORT A pins , in fact we have the binary value of 128 (10000000),and the PINA.0=0, PINA.1=0, PINA.2=0, PINA.3=0, PINA.4=0,PINA.5=0 , PINA.6=0, PINA.7=1, and after that DAC convert it to analog? and my another request is to recommend me an article about the R-2R DAC which can help me to know how dose it work .
Best regard
 

Yes, you are correct and each of the numbers represents a point along once cycle of a sine wave so if you feed them to PORTA you produce a voltage which is proportional to the number and the sine wave voltage is produced. The frequency of the sine waveform depends on how quickly you read and output the values on the port.

I'm not sure of any articles that explain the R-2R theory but I'm sure a simple Internet search will give you more information. The basic idea is that just as each binary bit has a value twice that of the one before it, so do the resistors. You can get the same result if you used (example) 1K on bit 7, 2K on bit 6, 4K on bit 5, 8K on bit 4, 16K on bit 3, 32K on bit 2, 64K on bit 1 and 128K on bit 0. The problem with that is there are no standard resistor values like those. The way it is done in your schematic uses resistors which are all one value so a standard value can be used but more of them are needed.

Brian.
 
Explain a little bit about using dac to produce pure sine wave.
 

It's very simple. For every number you feed into the DAC, a voltage comes out of it. If you put 0x00 in, you get zero volts out and if you put 0xFF in, you get full voltage out. Any number between 0x00 and 0xFF will produce a voltage somewhere between zero and full voltage. To make a sine wave, you sequentially feed in the value of points along the sine curve, scaled so they lie between 0x00 and 0xFF. In the previous example the sine value for 0 degrees is (0 x 128) + 128 = 128 (0x80), the sine for 90 degrees is +1 so the value is (+1 x 128) + 128 = 255 (rounded down, 256 would overflow 8 bits).

You can create any wave shape you like by feeding samples of it into a DAC, this is basically how digital audio works as well. Note that it isn't possible to create a 'pure' sine wave using this method but it is possible to make one with very low distortion.

Brian.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top