I WANT TO KNOW HOW TO GENERATE sinusoidal wave using mikroc thanks forward.
Timer and a lookup table.I WANT TO KNOW HOW TO GENERATE sinusoidal wave using mikroc thanks forward.

/******************************************************************************
PWMsine1840
Program PWM Sine Wave using a PIC12F1840
//
*** This software Is offered strictly as-is with no warranties whatsoever.
Use it at your own risk. ***
MPLAB X IDE V.4.05
XC-8 V.1.45
******************************************************************************/
#include <xc.h>
// set config bits
#pragma config FOSC=INTOSC, PLLEN=OFF, WDTE=OFF, MCLRE=ON,
#pragma config CLKOUTEN=OFF, IESO=OFF, FCMEN=OFF,CP=OFF, CPD=OFF,BOREN=OFF
#pragma config WRT=OFF,STVREN=ON,BORV=LO,LVP=OFF
#define _XTAL_FREQ 16000000 // used by the __delay_ms(xx) and __delay_us(xx)
//-------------------------
// globals
volatile unsigned char Dcount =0;
/* These are the duty cycle percentages for the sine wave
50, 58, 65, 73, 79, 85, 90, 95, 98, 99,
100, 99, 98, 95, 90, 85, 79, 73, 65, 58,
50, 42, 35, 27, 21, 15, 10, 5, 2, 1,
0, 1, 2, 5, 10, 15, 21, 27, 35, 42 */
// 8 most significant bits of duty cycle
const unsigned char DCThigh[40]=
{
128,148,166,186,202,217,230,242,250,252,
255,252,250,242,230,217,202,186,166,148,
128,107, 89, 69, 54, 38, 26, 13, 5, 2,
0, 2, 5, 13, 26, 38, 54, 69, 89,107
};
// 2 least significant bits of duty cycle
const unsigned char DCTlow[40]=
{
2,0,3,1,2,3,2,1,0,2,
0,2,0,1,2,3,2,1,3,0,
2,0,1,3,2,1,2,3,0,2,
0,2,0,3,2,1,2,3,1,0
};
//-------------------------
void main(){
OSCCON = 0x7A; // 16 MHz with internal oscillator
__delay_us(100);
PR2 = 0xfe; // PWM period register for 40 kHz
T2CON = 0x4; // prescaler=1 / timer on
CCP1CONbits.CCP1M=0x0C; // select PWM mode for CCP module
CCP1CONbits.P1M=0x00; // select single output on CCP1 pin (RA2) PIN 5
// load 0 length duty cycle
CCPR1L=0;
CCP1CONbits.DC1B=0;
PIE1bits.TMR2IE =1; // enable Timer2 interrupt
INTCON =0xC0; // enable Global interrupt, peripheral interrupt
TRISA=0x00;
__delay_us(10);
// load starting duty cycle which will be latched after first overflow
// that overflow will also be handled by the ISR which will load
// the next duty cycle value to be latched
CCPR1L=DCThigh[Dcount];
CCP1CONbits.DC1B=DCTlow[Dcount];
//
// In this example we stay in a do-nothing loop, but additional
// code could be used
here: goto here; // we are done so just stay put
}
//-------------------------
// ISR for Timer 2
void interrupt Timer2_ISR(void)
{
if (TMR2IF) {
++Dcount;
if(Dcount == 40) { // Increment counter and rollover if needed
Dcount = 0;
}
// load the new duty cycle to latch on next overflow
CCPR1L=DCThigh[Dcount];
CCP1CONbits.DC1B=DCTlow[Dcount];
TMR2IF = 0;
}
}
//-------------------------