Page 1 of 1

GPT Issue

Posted: Wed Mar 01, 2017 6:16 am
by Tabulous
Target F411

Code: Select all

/*
 * GPT3 configuration.
 */
static const GPTConfig gpt3cfg = {
    10000,            /*  Timer clock.*/
    gpt3Callback, /* Timer callback.*/
    0,
    0
};

/* callback */
static void gpt3Callback( GPTDriver *gptp )
{


    (void)gptp;
    palTogglePad( GPIOE, GPIOE_AMB_LED );
}

/* Timer Started by calling */
gptStart( &GPTD3, &gpt3cfg );
gptStartContinuous( &GPTD3, 100 );



Issue is the expected frequency of the callback is not correct. I'm expecting it to be 100Hz, but it is around 101/102Hz.

Ive also tried this in a thread and i get the same error, the led toggles at 101/102Hz.

Code: Select all

    while( TRUE )
    {
        chThdSleepMilliseconds( 10 );
        palTogglePad( GPIOE, GPIOE_AMB_LED );
     }


Register settings for Timer 3
Untitled.jpg

Re: GPT Issue

Posted: Wed Mar 01, 2017 8:40 am
by Giovanni
Hi,

Is 100hz actually obtainable using the 16 bits input prescaler? it is an integer divider, the driver does nothing except setting up the register.

If the answer to the previous question is yes then I would check clocks.

Giovanni

Re: GPT Issue

Posted: Wed Mar 01, 2017 10:43 am
by Tabulous
mmmm main clock is at 96Mhz as i need this for USB(/2).
TIM3 is 16bit, but if i switch to TIM5 which is 32bit the error is still the same.


The weird thing is the same code on STM32F030 works ok, exactly 100Hz.


So there must be something not quite right with the setup on the F4

Re: GPT Issue

Posted: Wed Mar 01, 2017 1:02 pm
by Tabulous
Little update,
if i run the code and pause the debugger and then manually change using EmbSys the following timer registers
TIM3_ARR = FCFF
TIM3_PSC = E

Everything is good the timer callback is called every 10ms/100Hz exactly, so achieving the correct result.

Re: GPT Issue

Posted: Wed Mar 01, 2017 3:59 pm
by Tabulous
Example update event period
The update event period is calculated as follows:
Update_event = TIM_CLK/((PSC + 1)*(ARR + 1)*(RCR + 1))

TIM_CLK = 72 MHz
Prescaler = 1
Auto reload = 65535
No repetition counter RCR = 0
Update_event = 72*(10^6)/((1 + 1)*(65535 + 1)*(0 + 1))
Update_event = 549.3 Hz

So working it for what i need
/*
* GPT3 configuration.
*/
static const GPTConfig gpt3cfg = {
10000, /* Timer clock.*/
gpt3Callback, /* Timer callback.*/
0,
0
};

gptStartContinuous( &GPTD3, 100 );

TIM_CLK = 96 MHz
Prescaler = 9599(this is what lld writes to PSC reg, (96000000/10000)-1)
Auto reload = 99(this is what lld write to AAR reg, (100)-1)
No repetition counter RCR = 0
Update_event = 96*(10^6)/((9599 + 1)*(99 + 1)*(0 + 1))
Update_event = 100.00 Hz


But in practice the output is not what is calculated.

To get the correct output i have to change the lld to remove the -1 on the psc and the -1 on the interval.

Re: GPT Issue

Posted: Wed Mar 01, 2017 4:16 pm
by Giovanni
Strange, that would affect also your F030.

giovanni

Re: GPT Issue

Posted: Wed Mar 01, 2017 4:42 pm
by Tabulous
Giovanni wrote:Strange, that would affect also your F030.

giovanni


Yep they both use the same lld......