Code: Select all
static PWMConfig oneshot125cfg = {
10000, /* 10kHz PWM clock frequency. */
20, /* Prescalar ( /20 ) */
pwmpcb,
{
{PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL}
},
0,
0,
0
};
This give me a PWM frequency of 500Hz (2ms period). When i use a logic analyzer however I'm reading a frequency of 505Hz. The real issue though is when I'm trying to control the duty cycle. The output is only accurate for increments of 5 e.g. 10%, 15%, 20%, 25% and so on. Trying to set a duty cycle that isn't a multiple of 5 e.g. 43%, 87%, 52% etc. just rounds down to the nearest 5 multiple. E.g. setting 57% duty cycle, i measure 55% as output.
Code: Select all
pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 9500));
Why is this and how do I get a better resolution?
edit: When raising PWM clock frequency, the accuracy drops more. 57% is now measuring as 53%. Whats happening here?