Page 1 of 1

PWM asserts invalid

Posted: Sat Feb 25, 2012 10:15 am
by DrunkenDonkey
Morning all,

I finally got board repaired to play with and need to hack a quick 32768 clock using pwm so I put:

Code: Select all

static const PWMConfig pwmcfg = {
   32768*2,
   2,
   NULL,
   {
      {PWM_OUTPUT_ACTIVE_HIGH, NULL},
      {PWM_OUTPUT_ACTIVE_LOW, NULL},
      {PWM_OUTPUT_ACTIVE_HIGH, NULL},
      {PWM_OUTPUT_ACTIVE_HIGH, NULL}
   },
   0,
};
pwmStart(&CRYSTAL_DRIVER, &pwmcfg);
pwmEnableChannel(&CRYSTAL_DRIVER, CRYSTAL_CHANNEL, PWM_PERCENTAGE_TO_WIDTH(&CRYSTAL_DRIVER, 5000));



And immediately hit a code in pwm_lld.c does not very much agree with me:

Code: Select all

chDbgAssert((psc <= 0xFFFF) &&
            ((psc + 1) * pwmp->config->frequency) == pwmp->clock,
            "pwm_lld_start(), #1", "invalid frequency");


What I find fun is if I comment out that assert then the signal is generated perfectly and the component requiring it works...

Re: PWM asserts invalid

Posted: Sat Feb 25, 2012 10:25 am
by Giovanni
Hi,

That assert is added to catch rounding errors (the second sub-expression), probably the input clock frequency is not divisible by the PWM frequency you selected.

You should select a PWM frequency that can be obtained by dividing the input clock by an integer number. If you don't care about rounding then ignore the assertion.

Giovanni