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.

sinusoidal pulse width modulation using PIC18F4431 and ccs compiler

Status
Not open for further replies.

snjugunachege

Newbie level 1
Joined
Jul 9, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
hi all out there...am an electronics student and doing my project. i am using pic 18f4431 microcontroller to produce two sinusoidal pulse width modulated signals that i will use to control my H bridge so that i can construct a simple inverter. i have written some code using ccs but on simulating on proteus i am not getting the required output. the code that i have written is shown here. i need your expert advice if you can i will greatly appreciate. i am new to PICs.
#if defined(__PCM__) // preprocessor directive that chooses the compiler
#include <18F4431.h> // preprocessor directive that selects the chip PIC16F4431
#fuses HS,NOWDT,NOPROTECT,NOLVP // preprocessor directive that defines fuses for the chip
#use delay(clock=40000000) // preprocessor directive that specifies the clock speed
#elif defined(__PCH__) // same as above but for the PCH compiler and PIC18F4431
#include <18F4431.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)
#endif
#int_TIMER0//This function is called when timer 0 overflows
void clock_isr()
{
int index=0;
char wavetable[]={0x7F,0x95,0xAB,0xBF,0xD1,0xE1,0xED,0xF7,0xFD,0xFF,0xFD,0xF7,
0xED,0xE1,0xD1,0xBF,0xAB,0x95,0x7F,0x69,0x53,0x3F,0x2D,0x1D,
0x11,0x07,0x01,0x00,0x01,0x07,0x11,0x1D,0x2D,0x3F,0x53,0x69,0x7F
};
set_pwm1_duty(50*wavetable[index]);
index++;
if(index>37)
index=0;
}
void main()
{ // main function
setup_ccp1(CCP_PWM); //CONFIGURE CCP1 AS A PWM

setup_power_pwm(PWM_CLOCK_DIV_64| PWM_FREE_RUN |PWM_DEAD_CLOCK_DIV_8|PWM_UPDATE_ENABLE,
1,65569,1020,0,0,50);//SETTING UP THE POWER PWM MODULE
setup_timer_2(T2_DIV_BY_1,200,1);
set_timer2(0);

setup_power_pwm_pins(PWM_COMPLEMENTARY,PWM_OFF,PWM_OFF,PWM_OFF); //CONFIGURING THE PWM OUTPUT PINS
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|RTCC_8_BIT);
set_timer0(44);
enable_interrupts(GLOBAL);
while (TRUE);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top