raja.afiq
Newbie level 3
i using C to coding it. using mplab x and xc16 as complier. i make a coding to control pwm where i want to set it to 0% pwm. i don't know where is my wrong in my coding. can someone help me with this and tell me what is the problem so i can learn form this. i just new for this microcontroller.
Code:
#include <p33FJ64MC802.h>
_FOSCSEL(FNOSC_FRCPLL) //set clock for internal OSC with PLL
_FOSC(OSCIOFNC_OFF & POSCMD_NONE) //no clock output, external OSC disabled
_FWDT(FWDTEN_OFF) //disable the watchdog timer
_FICD(JTAGEN_OFF & ICS_PGD1); //disable JTAG, enable debugging on PGx1 pins
void initpwm(void){
P1TCON = 0x8000; //free running, time base on, fcy 1:1, run in cpu idle mode
PWM1CON1bits.PMOD1 = 1; //Select Independent Output PWM mode
PWM1CON1bits.PEN1H = 1; //PWM1H control by PWM module
PWM1CON1bits.PEN1L = 0; //PWM1L control as GPIO
PWM1CON2=0b0000000000000010;
P1DTCON1=0;
P1FLTACON=0;
P1TMR=0;
}
int main (void){
OSCCON=0x22E0;
CLKDIV=0;
// setup internal clock for 80MHz (Fosc)
// Fcy=Fosc/2 (Fcy = 40MHz)
// 7.37/2*43=158.455/2=79.2275MHz
CLKDIVbits.PLLPRE=0; // PLLPRE (N2) 0=/2
PLLFBD=41; // pll multiplier (M) = +2
CLKDIVbits.PLLPOST=0; // PLLPOST (N1) 0=/2
initpwm();
LATBbits.LATB14 = 0;
TRISBbits.TRISB14 = 0;
P1TPER=1599;
//PTPER = (Fcy/(Fpwm*prescaler))-1
//PTPER = (40M/(25k*1))-1
//Fpwm is desire freq for motor.
while (1){
P1DC1=0;
}
}