FrustratedEngineer
Newbie level 6
I have to simply o/p PWM (50% duty cycle; any frequency will do as of now) on RA2 of the PIC12F1572.
I have generated the code using MCC. But, when I tried observing the o/p at RA2 by connecting LED, I dont see LED turning on.
I have tried debugging the code, but PWM isr is never hit.
Any suggestions will be appreciated.
I have generated the code using MCC. But, when I tried observing the o/p at RA2 by connecting LED, I dont see LED turning on.
I have tried debugging the code, but PWM isr is never hit.
Any suggestions will be appreciated.
Code:
void PWM3_Initialize(void)
{
// set the PWM3 to the options selected in the User Interface
//PHIE disabled; DCIE disabled; OFIE disabled; PRIE disabled;
PWM3INTE = 0x00;
//PHIF cleared; OFIF cleared; DCIF cleared; PRIF cleared;
PWM3INTF = 0x00;
//PS No_Prescalar; CS FOSC;
PWM3CLKCON = 0x00;
//LDS reserved; LDT disabled; LDA do_not_load;
PWM3LDCON = 0x00;
//OFM independent_run; OFS reserved; OFO match_incrementing;
PWM3OFCON = 0x00;
//PWM3PHH 0;
PWM3PHH = 0x00;
//PWM3PHL 0;
PWM3PHL = 0x00;
//PWM3DCH 3;
PWM3DCH = 0x03;
//PWM3DCL 32;
PWM3DCL = 0x20;
//PWM3PRH 6;
PWM3PRH = 0x06;
//PWM3PRL 63;
PWM3PRL = 0x3F;
//PWM3OFH 0;
PWM3OFH = 0x00;
//PWM3OFL 1;
PWM3OFL = 0x01;
//PWM3TMRH 0;
PWM3TMRH = 0x00;
//PWM3TMRL 0;
PWM3TMRL = 0x00;
//MODE standard_PWM; POL active_hi; OE enabled; EN enabled;
PWM3CON = 0xC0;
// Clear the PWM3 interrupt flag
PIR3bits.PWM3IF = 0;
// Enabling PWM3 interrupt.
PIE3bits.PWM3IE = 1;
PWM3_DutyCycleSet(1000);
PWM3_Start();
}
void PWM3_Start(void)
{
PWM3CONbits.EN = 1;
}
void PWM3_Stop(void)
{
PWM3CONbits.EN = 0;
}
bool PWM3_CheckOutputStatus(void)
{
return (PWM3CONbits.OUT);
}
void PWM3_LoadBufferSet(void)
{
PWM3LDCONbits.LDA = 1;
}
void PWM3_PhaseSet(uint16_t phaseCount)
{
PWM3PHH = (phaseCount>>8); //writing 8 MSBs to PWMPHH register
PWM3PHL = (phaseCount); //writing 8 LSBs to PWMPHL register
}
void PWM3_DutyCycleSet(uint16_t dutyCycleCount)
{
PWM3DCH = (dutyCycleCount>>8); //writing 8 MSBs to PWMDCH register
PWM3DCL = (dutyCycleCount); //writing 8 LSBs to PWMDCL register
}
void PWM3_PeriodSet(uint16_t periodCount)
{
PWM3PRH = (periodCount>>8); //writing 8 MSBs to PWMPRH register
PWM3PRL = (periodCount); //writing 8 LSBs to PWMPRL register
}
void PWM3_OffsetSet(uint16_t offsetCount)
{
PWM3OFH = (offsetCount>>8); //writing 8 MSBs to PWMOFH register
PWM3OFL = (offsetCount); //writing 8 LSBs to PWMOFL register
}
uint16_t PWM3_TimerCountGet(void)
{
return ((uint16_t)((PWM3TMRH<<8) | PWM3TMRL));
}
bool PWM3_IsOffsetMatchOccured(void)
{
return (PWM3INTFbits.OFIF);
}
bool PWM3_IsPhaseMatchOccured(void)
{
return (PWM3INTFbits.PHIF);
}
bool PWM3_IsDutyCycleMatchOccured(void)
{
return (PWM3INTFbits.DCIF);
}
bool PWM3_IsPeriodMatchOccured(void)
{
return (PWM3INTFbits.PRIF);
}
void PWM3_ISR(void)
{
PIR3bits.PWM3IF = 0;
}
void PIN_MANAGER_Initialize(void)
{
/**
LATx registers
*/
LATA = 0x00;
/**
TRISx registers
*/
TRISA = 0x3B;
/**
ANSELx registers
*/
ANSELA = 0x17;
/**
WPUx registers
*/
WPUA = 0x3F;
OPTION_REGbits.nWPUEN = 0;
/**
ODx registers
*/
ODCONA = 0x00;
/**
APFCONx registers
*/
APFCON = 0x00;
}