prem123
Newbie level 5
problem in assigning the duty cycle values of 18f4431
usually according to the data sheet, the highest PDCn value should be PTPER register value. but when assigning duty cycles,largest duty cycle comes when PDCn=127.
why is that???
when we assign 128 the output stays in ON state.
bellow is the mikroc code..
void main()
{
PDC0L=0;
PDC1L=0;
PDC2L=0;
OVDCONS=0;
PTCON1=0;
PTCON0=0;
PTCON0=252; //Free running mode, Input clock is 1:64, Postscale is 1:16
PTCON1.PTEN=1; // Starts the generation of signals
PTPERH=137>>8; //storing the value 137 in PTPER
PTPERL=137; // which generates a PWM signal of 18 KHz
PWMCON0=80; //ALL PWM ARE INDEPENDENT, ONLY 0,1,2AND 3 IS ACTIVATED
PWMCON1=1; //Output overrides via the OVDCON register are synchronized to the PWM time base
DTCON=69; //dead time assignment
OVDCOND=255; //Output on PWM I/O pin is controlled by the value in the Duty Cycle register and the PWM time base
FLTCONFIG=0;
SEVTCMPH=0;
SEVTCMPL=0;
PWMCON1.UDIS=0;
while (1)
{
PDC0H=127>>6;
PDC1H=35>>6;
PDC2H=56>>6;
PDC0L=127;
PDC1L=35;
PDC2L=56;
delay_ms(5000) ;
PDC0H=70>>6;
PDC1H=56>>6;
PDC2H=42>>6;
PDC0L=70;
PDC1L=56;
PDC2L=42;
delay_ms(5000) ;
}
}
usually according to the data sheet, the highest PDCn value should be PTPER register value. but when assigning duty cycles,largest duty cycle comes when PDCn=127.
why is that???
when we assign 128 the output stays in ON state.
bellow is the mikroc code..
void main()
{
PDC0L=0;
PDC1L=0;
PDC2L=0;
OVDCONS=0;
PTCON1=0;
PTCON0=0;
PTCON0=252; //Free running mode, Input clock is 1:64, Postscale is 1:16
PTCON1.PTEN=1; // Starts the generation of signals
PTPERH=137>>8; //storing the value 137 in PTPER
PTPERL=137; // which generates a PWM signal of 18 KHz
PWMCON0=80; //ALL PWM ARE INDEPENDENT, ONLY 0,1,2AND 3 IS ACTIVATED
PWMCON1=1; //Output overrides via the OVDCON register are synchronized to the PWM time base
DTCON=69; //dead time assignment
OVDCOND=255; //Output on PWM I/O pin is controlled by the value in the Duty Cycle register and the PWM time base
FLTCONFIG=0;
SEVTCMPH=0;
SEVTCMPL=0;
PWMCON1.UDIS=0;
while (1)
{
PDC0H=127>>6;
PDC1H=35>>6;
PDC2H=56>>6;
PDC0L=127;
PDC1L=35;
PDC2L=56;
delay_ms(5000) ;
PDC0H=70>>6;
PDC1H=56>>6;
PDC2H=42>>6;
PDC0L=70;
PDC1L=56;
PDC2L=42;
delay_ms(5000) ;
}
}
Last edited: