Menu

#867 Wrong GPT frequency

17.6.1
closed-duplicate
None
STM32-HAL
High
17.6.0
False
2017-08-22
2017-07-29
Simon
No

Problem encoutered with STM32F767 and latest GIT chibios version.
The GPT period setting omit the required -1 in the ARR register:
void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval) {
[...]
gptp->tim->ARR = (uint32t)(interval);
[...]
}

The PWM driver do it right:
void pwmlldstart(PWMDriver pwmp) {
[...]
pwmp->tim->ARR = pwmp->period - 1;
[...]
}

It leads the GPT to issue callback or trigger at the wrong frequency. The smaller the period is, the bigger the error will be. Context:

static PWMConfig pwmcfg =
{
100000, // Timer clock frequency = 100kHz
100, // PWM period = 100ticks = 1kHz
pwmpcb,
{
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
},
0,
0
};
pwmStart(&PWMD4, &pwmcfg);
pwmEnablePeriodicNotification(&PWMD4); // no frequency error here.

static const GPTConfig gpt5cfg1 =
{
.frequency = 100000, // Timer clock frequency = 100kHz
.callback = gpt5_cb,
.cr2 = 0,
.dier = 0U
};
gptStart(&GPTD5, &gpt5cfg1);
gptStartContinuous(&GPTD5, 100); // ~1% frequency error there.

Kind regards,
Simon

Discussion

  • Simon

    Simon - 2017-07-29

    If we modify this to generate the correct frequency, it cause a problem with
    gptStartContinuous(&GPTD5, 1);
    since ARR = 0;

    This is less important than having the wrong GPT frequency for all other value I guess

     

    Last edit: Simon 2017-07-29
  • Simon

    Simon - 2017-07-29

    This is related to https://sourceforge.net/p/chibios/bugs/843/
    http://www.chibios.com/forum/viewtopic.php?f=35&t=3923
    But keep in mind that in generate a wrong frequency, because in the documentation it says that:
    interval = period in ticks !
    All GPT examples provided with chibios are compliant with that statement.

     

    Last edit: Simon 2017-07-29
  • Giovanni Di Sirio

    • status: open --> closed-duplicate
    • assigned_to: Giovanni Di Sirio
     
  • Giovanni Di Sirio

    Duplicate of bug #843, already fixed.

     

Log in to post a comment.