PWM asserts invalid

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
DrunkenDonkey
Posts: 124
Joined: Sun Aug 28, 2011 5:16 pm

PWM asserts invalid

Post 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...
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM asserts invalid

Post 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
Post Reply