Hi,
I am trying to generate PWM with the PIC12F1571. Somehow my code just doesn't work. I know, I am new to C and PIC MCU so I appreciate if someone can help me.
#include <stdio.h>
#include <stdlib.h>
#include "Config.h"
#include <xc.h>
#include <PIC12F1571.h>
void PWM1_Initialize(void)
{
//Turn the PWM on the in RA0
APFCONbits.P1SEL = 0;
//PS Divide_clock_src_by_2; CS FOSC;
PWM1CLKCON = 0x10;
//PWM1DCH 0;
PWM1DCH = 0x00;
//PWM1DCL 3;
PWM1DCL = 0x03;
//PWM1PRH 0;
PWM1PRH = 0x00;
//PWM1PRL 6;
PWM1PRL = 0x06;
//PWM1OFH 1;
PWM1OFH = 0x01;
//PWM1OFL 244;
PWM1OFL = 0xF4;
//PWM1TMRL 0;
PWM1TMRL = 0x00;
//MODE standard_PWM; POL active_hi; OE(Output Enable) enabled; EN(Module Enable bit)enabled;
PWM1CON = 0xC0;
}
void PWM1_Start(void)
{
PWM1CONbits.EN = 1;
}
void PWM1_Stop(void)
{
PWM1CONbits.EN = 0;
}
int main()
{
//PORTAbits.RA1 = 0;
TRISAbits.TRISA1 = 0;
ANSELAbits.ANSA1 = 0;
LATAbits.LATA1 = 0;
PWM1_Initialize();
while(1)
{
PWM1_Start();
}}
I am trying to generate PWM with the PIC12F1571. Somehow my code just doesn't work. I know, I am new to C and PIC MCU so I appreciate if someone can help me.
#include <stdio.h>
#include <stdlib.h>
#include "Config.h"
#include <xc.h>
#include <PIC12F1571.h>
void PWM1_Initialize(void)
{
//Turn the PWM on the in RA0
APFCONbits.P1SEL = 0;
//PS Divide_clock_src_by_2; CS FOSC;
PWM1CLKCON = 0x10;
//PWM1DCH 0;
PWM1DCH = 0x00;
//PWM1DCL 3;
PWM1DCL = 0x03;
//PWM1PRH 0;
PWM1PRH = 0x00;
//PWM1PRL 6;
PWM1PRL = 0x06;
//PWM1OFH 1;
PWM1OFH = 0x01;
//PWM1OFL 244;
PWM1OFL = 0xF4;
//PWM1TMRL 0;
PWM1TMRL = 0x00;
//MODE standard_PWM; POL active_hi; OE(Output Enable) enabled; EN(Module Enable bit)enabled;
PWM1CON = 0xC0;
}
void PWM1_Start(void)
{
PWM1CONbits.EN = 1;
}
void PWM1_Stop(void)
{
PWM1CONbits.EN = 0;
}
int main()
{
//PORTAbits.RA1 = 0;
TRISAbits.TRISA1 = 0;
ANSELAbits.ANSA1 = 0;
LATAbits.LATA1 = 0;
PWM1_Initialize();
while(1)
{
PWM1_Start();
}}