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.

PIC with DAC : need for generate sine wave in 100Hz

Status
Not open for further replies.

sureshkanna

Junior Member level 1
Joined
Mar 31, 2012
Messages
19
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,470
Hi friends ...
i need to generate sine wave in 100Hz . i don't known how to generate and how to interface with PIC.
I am using,
*PIC16f877A controller
*16Hz crystal
* MPLab Compiler .
*0808 DAC
so try to give sample code and hardware circuit for sine wave generation. i am expecting for your valuable reply.
 

have a look at this website. it is built using Atmel uc's, but you can very easily modify for microchip, the design is so simple.

**broken link removed**
 

If you are not required to use a PIC, I would recommend using a DDS chip. 100Hz would be no problem even for the cheapest part from Analog Devices. If you are required to use a PIC, then I still recommend looking at Analog Devices to get the theory of operation for their DDS parts. It will give you a clue on how to implement a DDS like function with your PIC. It's basically a sine wave look up table going to a D/A converter. The DDS has added functions for phase, etc. but the basic operation is stepping through a series of voltage settings at a specified rate to get the correct wave shape and frequency.
 

100Hz is easy with one pin and PWM. Set a sutable PWM rate and send values from a sine look-up table to set the pulse width. One external resistor and capacitor will give a sine wave as good as a DAC can produce with a fraction of the cost.

If you really have to use a DAC, use a sine table scaled to +/- 127, add 127 to the result so you get values 0 to 254 then output them on a port connected to the DAC data input.

Brian.
 

i have to use DAC ya...herewith i enclosed my proteus design and program. still i have doubt in,how to generate sine wave in different frequencies ... like 100Hz,,500Hz,100KHz,500KKzView attachment Eda DAC.rar

- - - Updated - - -

i've to use PIC and DAC ....
 

have a look at this website. it is built using Atmel uc's, but you can very easily modify for microchip, the design is so simple.

**broken link removed**

i have to use DAC ya...herewith i enclosed my proteus design and program. still i have doubt in,how to generate sine wave in different frequencies ... like 100Hz,,500Hz,100KHz,500KKzView attachment 85411
i've to use PIC and DAC ....


As in the first post (#2) i repeat - look up or google Jespers miniDDS. If you have any capability in understanding AVR uC code, then you will be able to translate it to PIC. Also you can replace the R-2R with a DAC, if you know how to do it.

Or are you looking for a complete ready-made schematic pre-coded source and hex made available to you ?
 

I don't use Proteus so I haven't read you files but the principle is to build the points along the sine curve by sending a number representing each point to the DAC.

To start you need a sine look-up table, it is possible to calculate sine values in real time but a pre-built table of values would be much faster and easier. To get maximum output voltage in the sine wave you want the lowest point to be 0V and the highest to be VDD (usually 5V) and the range of numbers in the table must go from 0 at the bottom to 255 (0xFF) at the top. Next you have to decide how many points along the sine curve you want to plot. The more points you use the more accurate the sine will be but also the slower it becomes to produce it. I would suggest a good starting place would be 256 points because it's easiest in software.

So you want a table with 255 entries, each representing 360/256 = 1.4 degrees. Calculate the sine value for 0, 1.4, 2.8.... steps until you have value for each of the 256 points.
Sine values are between -1 and 1 which is of no use to send to a DAC so they need to be scaled to between 0 and 255. The easiest way to do this is to add 1 so the values are moved to between 0 and 2 then multiply the result by 127. this will give results between 0 and 254, you will have to ignore the value for 255 because it can't be used without fractional calculations which would be much more complicated. The final numeric step is to round the sine values to the nearest integer so they can be put in the table. It will lose a small amount of accuracy but not too much.

At this stage, if you sent each value in the table, from start to finish, to the DAC it's output would be one cycle of sine wave.

To produce different frequencies you have to repeat the cycles at different rates so the table values have to be read at different intervals. As there are 256 entries in the table you have to read them at 256 * Fsin where Fsin is the the frequency you want to produce. You can set the interval between table reads and writing to the DAC in a software delay or by using one of the PIC timers.

If you want to be more adventurous, you can rely on the symetry of a sine wave to make the DAC output more accurate but it will take some extra effort to write the software. For example, the rise and fall of the first half cycle are mirror images of each other so you could plot only the first quadrant then reverse the direction you read the table to get the second quadrant. Similarly, you could produce an output to cause a circuit after the DAC to invert the signal to produce the third and fourth quadrants.

Brian.
 

...To produce different frequencies you have to repeat the cycles at different rates so the table values have to be read at different intervals. As there are 256 entries in the table you have to read them at 256 * Fsin where Fsin is the the frequency you want to produce. You can set the interval between table reads and writing to the DAC in a software delay or by using one of the PIC timers....

this is the obvious way to obtain a frequency, but the downside is that varying the frequency this way is harder to do. The better method is to step through the sine table by using a 'phase offset', and hence get different frequencies with a single loop timing. This is actually quite easy to do even with simple 8-bit uCs and is the basic technique used in even the most sophisticated DDS chips.
 

Agreed Kripacharya, but I get the impression this is school homework and Sureshkanna isn't yet up to speed on such things as DDS. The question originally only stated 100Hz, the other ones came late in the postings.

Brian.
 

... but I get the impression this is school homework and Sureshkanna isn't yet up to speed on such things as DDS....

LoL !! good point. when designing a solution, one must take into consideration all factors
 

I'm looking to do something similar, though I need very low frequencies. I'm trying to develop 3 separate signals to send to driver boards which move motors. I need the following signals:

0.1Hz, 3Vp-p, 2.5Vdc offset
0.03Hz, 2.2Vp-p, 2.0Vdc offset
0.01Hz, 2.2Vp-p, 2.0Vdc offset

Is it possible to build these three signals, preferably simultaneously or close to it, and have them output from a pic/arduino/some other software method? I've been doing a lot of reading over the last few days about hardware and software solutions, but have found nothing that mentions signals this slow or if it is even possible. I do have the ability to use signal generators, but those are far more expensive than using simple software/hardware methods. I'm not so much worried about the amplitudes of my signals here either as I can dress those up as I need with filtering and amplifiers after they are generated. The three signals also don't need to be in phase with each other as they are all just going to separate driver boards.

Is it possible to account for the DC offset of the signals by setting my sine wave zero at 2.5V (or 2.0V) instead of zero volts? I know the rails on the outputs are usually around 5V, but that could usually be changed with a higher reference voltage right? That would save one step, and keep from needing separate components.
 

The problem sounds quite easy to solve. Given that you have three separate outputs it would be easiest to use external DACs and parallel their inputs except for an enable (latch) signal so they can be written to individually.
Such low frequncies are easy to generate using PIC timers or software delays and the points along the waveform for each signal calculated and then written to the appropriate DAC.

Offsetting the voltage so Sin(0) = 2.5V is easy, assuming 8-bit accuracy is sufficient and the supply is 5V, just center the sin(0) entry on 127 so the output goes form 0 to 254 with 127 (=2.5V) in the middle.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top