Page 1 of 1

Timers accuracy

Posted: Tue Mar 10, 2015 2:16 pm
by MySOL
Hello! I never checked the accuracy of the "Sleeps" functions, but today there was one problem , when I wrote PWM programm

Code: Select all

Confgi funcion is:

static PWMConfig pwmcfg = {
  10000,                                    /* 10kHz PWM clock frequency.   */
  1000,                                    /* Initial PWM period 100 ms.       */
  pwmpcb,
  {
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_ACTIVE_LOW, pwmc1cb},            // 3nd channel // PA1
   {PWM_OUTPUT_DISABLED, NULL}
  },
  0,
  0
};

And "Enable function" is

pwmEnableChannel(&PWMD2, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 5000));
chThdSleepMilliseconds(2000);
pwmDisableChannel(&PWMD2,2);


The main problem is that in my understand "chThdSleepMilliseconds(2000);" - its a 2 seconds delay, but in real it was around 1.2 second. Hence the question: its mistake in my code or understanding or poor accuracy in this function? Thx

Re: Timers accuracy

Posted: Tue Mar 10, 2015 2:43 pm
by Giovanni
That function is as accurate as the system clock is. If you try any provided demo you can see it is accurate. There must be a problem in your setup.

Giovanni

Re: Timers accuracy

Posted: Thu Mar 12, 2015 7:48 pm
by MySOL
Giovanni wrote:That function is as accurate as the system clock is. If you try any provided demo you can see it is accurate. There must be a problem in your setup.

Giovanni


Thank you!

Re: Timers accuracy

Posted: Thu Mar 12, 2015 7:52 pm
by Giovanni
A possible reason could be your board having a different crystal frequency from the board used by the example you used as source.

Are you using some kind of custom board? if so some parameters in mcuconf.h should be adjusted depending of the crystal frequency.

Giovanni