December 26, 2012

Sine wave generating from PIC

Hello friends,

To do sinusoidal modulation you need sine wave which can be compared with high frequency carrier(triangular waves). And i was also about to generate Sine modulation so i needed to do this.

      You can generate by calculating sine values at run time also but that is time consuming and keeps your microcontroller busy with calculations only, so I suggest you to make a look up table  and recall the value at run time from there.

      So here is what I have done its a simple task just have a look at the code,....

#include "pic .h
#include "htc .h"
#define _XTAL_FREQ 4000000

const unsigned char wave[181] ={128,132,137,141,146,150,155,159,163,168,172,176,180,184,188,192,196,200,203,207,210

int main(void)
TRISD = 0x00;
unsigned char i;

for(i=0;i<181 ;i++) {
PORTD = wave[i];

return 0;


 But,here instead of using normal DAC to generate sine wave I have here used R-2R ladder(no specific reason).
Here is the schematic.

R-2R ladder in proteus generating sine wave for sine modulation

Here VSM Timer counter is used to measure the frequency generated by R-2R DAC. 

The output of the circuit is as shown below..

Sine wave and vsm counter in proteus

if you want to make frequency variable just keep a variable in delay and update it by any key..... 

For more Proteus projects  click here.


Post a Comment

Related Posts Plugin for WordPress, Blogger...