hi....i have also same kind of problem. while using uart while using PWM. as when uart is inactive i.e.
U1MODE:L
bit 15 UARTEN:UARTx Enable bit
1= Enable UARTx; UARTx pins are controlled by UARTx module
0= Disable UARTx; UARTx pins are controlled by I/O Port control registers
when this bit is disabled pwm works fine. but as soon as i enable uart pwm signals are vanished.
I tried to find out conflicts with other functions on pin like PGD/PGC and PWM4H/4L. but no clues for the same. I tried out FCLCON also . but no effect
here is my code
#include "p30f2020.h"
/* Configuration Bit Settings */
/*
_FOSCSEL(FRC_PLL)
_FOSC(PRIOSC_OFF & CSW_FSCM_OFF & FRC_HI_RANGE & OSC2_IO)
_FPOR(PWRT_128)*/
_FOSCSEL(PRIOSC_PLL)
_FOSC(HS & OSC2_CLKO & CSW_FSCM_OFF) //OSC2 PIN HAS clk FUNCTION,HS selected
_FPOR(PWRT_128)
/*****************************************************************************/
/* STANDARD PWM INITIALIZATION CODE */
/*****************************************************************************/
void init_PWM()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~ PWM Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PTPER = 1920;
PDC1 = 1000;
PDC2 = 960;
DTR1 = 64; // 67.2 nsec dead time
DTR2 = 64; // 67.2 nsec dead time
ALTDTR1 = 64; // 67.2 nsec dead time
ALTDTR2 = 64; // 67.2 nsec dead time
IOCON1bits.PENH = 1; // PWM1 outputs controlled by PWM module
IOCON1bits.PMOD = 0b01;
IOCON1bits.PENL = 1;
IOCON2bits.PENH = 1; // PWM2 outputs controlled by PWM module
IOCON2bits.PMOD = 0b01;
IOCON2bits.PENL = 1;
IOCON4bits.PENH = 1;
IOCON4bits.PENL = 1;
PWMCON1bits.IUE = 1; //update from pdc immediate
PWMCON2bits.IUE = 1;
PTCONbits.PTEN = 1; // Turn ON PWM module
//~~~~~~~~~~~~~~~~~~~~~~ End PWM Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
/******************************************************************************/
/* MAIN ROUTINE */
/******************************************************************************/
int main()
{
/* Wait for PLL to lock */
while(OSCCONbits.LOCK!=1) {};
/*Configure Oscillator to operate the device at 40MIPS*/
//TRISB = 0b1111111111110000; //set B0-B3 to output
//TRISA = 0b00000; //set A0-A4 as ouput
OSCCONbits.COSC = 0b011;
FCLCON1bits.CLMODE = 0; // current-limit function disabled
FCLCON1bits.FLTMOD = 3; // fault input disabled
FCLCON2bits.CLMODE = 0; // current-limit function disabled
FCLCON2bits.FLTMOD = 3; // fault input disabled
FCLCON3bits.CLMODE = 0; // current-limit function disabled
FCLCON3bits.FLTMOD = 3; // fault input disabled
FCLCON4bits.CLMODE = 0; // current-limit function disabled
FCLCON4bits.FLTMOD = 3; // fault input disabled
/* Set Up UART */
U1BRG=156; /* 9600Baud for 24MHz UxBRG = (Fcy/16.Baud_rate)-1 Fcy=24MHz*/
/* Change U1BRG to suit your clock frequency */
U1MODE=0b0000000000000000; /*Enable,8data,no parity,1 stop,use alternate pins for uart */
U1STA =0x8400; /* Interrupt generated when a character is transferred to
* the Transmit Shift register and the transmit buffer
* becomes empty*/
INTCON1bits.NSTDIS=1; //interrupt nesting is disabled
INTCON2 = 0b0000000000000111; //set all three interrupts int0,int1.int2 are set as negative edge detector
IEC0 = 0b0110111100000001; //int0 enable bit,uart,i2c,adc,spi interrupts are enabled
IEC1 = 0b0000000000000011; //int2 and int1 enable bit
IEC2 = 0b0000011111100000; //adc0 to adc5 pairs conversions complete interrupts
IPC0 = 0b0000000000000111; //SETTING INTO AS 7TH (highest priority)
IPC1 = 0b0000000000000110; //SETTING INT1 AS 6TH (2nd highest priority)
IPC2 = 0b0000000001010000; //SETTING INT2 AS 5TH (3rd highest priority)
/* Disable Watch Dog Timer */
RCONbits.SWDTEN=0;
/* Set Up UART */
U1BRG=194; /* 9600Baud for 16MIP (See FRM Tables) *///103
/* Change U1BRG to suit your clock frequency */
U1MODE=0x8000; /* Enable, 8data, no parity, 1 stop */
U1STA =0x8400; /* Enable TX */
init_PWM();
while(1); //controller should be in active executable mode
}