Page 1 of 1

gptPolledDelay()

Posted: Mon Oct 03, 2016 11:04 am
by Jack666
Hi everybody.

I'm quite new to ChibiOS and i have a question about gptPolledDelay().
I want to make small delay (between 20 and 200 micro seconds). According to this blog, the best way is to use gptPolledDelay().

I tested my code with an olimex P103 board and ChibiOS 16.1.5. I take the demo code from the chibios example and modified it to test gptPolledDelay().
I set and reset an output and see with an oscilloscope the output.
Here's the code:

Code: Select all

static const GPTConfig gpt4cfg = {
    1000000,
    NULL,
    0,
    0
};
int main(void)
{
    /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
    halInit();
    chSysInit();

     gptStart(&GPTD4, &gpt4cfg);

    palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL);

    while (true) {
        palClearPad(GPIOC, 0);
        gptPolledDelay(&GPTD4, 50);
        palSetPad(GPIOC, 0);
        chThdSleepMilliseconds(100);
    }
}


I expected a delay of 50µs, but all i get is a delay of 600 nanoseconds! Moreover no matter which value i put for the frequency of the timer in GPTConfig, it always give me a 600 nanoseconds delay.

Then i tested with a one shot timer with a callback, instead of the polled delay, and it succesfully give me the delay expected (well more or less some micro seconds).

I need an accurate delay, that's why i need gptPolledDelay().

I must add two things:
- i've tested the code with another board (very similar to olimex one) and same problem.
- Osc configuration is good, chThdSleeMiliseconds() give me the expected result.

Thanks for your help

Re: gptPolledDelay()

Posted: Mon Oct 03, 2016 11:06 am
by Jack666
Sorry, i've double clicked the "submit" button, and created two threads. Oups...

Re: gptPolledDelay()

Posted: Mon Oct 03, 2016 12:16 pm
by Giovanni
Hi,

It is a known bug: https://sourceforge.net/p/chibios/bugs/775/

Already fixed in repository, will be fixed in next release.

Giovanni

Re: gptPolledDelay()

Posted: Mon Oct 03, 2016 1:19 pm
by Jack666
Thank you!