I had read previously question which post during march 2016, and it don't help me much
As this is a new PIC to me, I went to test on the 16Bit PWM which previously I never work with(previously I do CCP only). The output is connected to a MOSFET as class D amp switch a LED.
CONFIG words work fine, delay work fine.
:blah: :blah: :blah: :blah: config setting
void InitPWM(void)
{
TRISA1 = 0; //output
LATA1 = 0; //Clear output
APFCONbits.P1SEL = 0; //pin RA1
PWM1CON = 0b11000000; //Enable PWM, enable output
PWM1CLKCON = 0b00000001;//no prescaler, HFINTOSC
PWM1TMR = 0xFFFF; //Max 65535 ,PWMxTMR is = to PWMxTMRH:PWMxTMRL
PWM1PR = 0xFFFF; //max 65535, PWMxPR is = to PWMxPRH:PWMxPRL
PWM1DC = 0x3FF; //set 10 bits, PWMxDC is = to PWMxDCH:PWMxDCL
return; //JIC it stuck here
}
void main(void)
{
OSCCON = 0b11110000;
InitPWM();
while(1)
{
for(unsigned int a = 0 ; a < 1024 ; a++)
{
PWM1PH = a; //PWMxPH is = to PWMxPHH:PWMxPHL
__delay_us(20);
}
}
}
base on the code, im expecting the LED will slowly fall in brightness and cycle each time around 1-2 seconds.
however, the led stuck at certain duty cycle
I swear I read carefully the PWM standard mode operation on the datasheet before I wrote my code and follow the graph that shown
so im expecting, setting the PWMxPH is determine the falling state of the PWM.