gptPolledDelay() Topic is solved

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Jack666
Posts: 5
Joined: Mon Oct 03, 2016 10:38 am
Been thanked: 1 time

gptPolledDelay()  Topic is solved

Postby Jack666 » Mon Oct 03, 2016 11:04 am

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

Jack666
Posts: 5
Joined: Mon Oct 03, 2016 10:38 am
Been thanked: 1 time

Re: gptPolledDelay()

Postby Jack666 » Mon Oct 03, 2016 11:06 am

Sorry, i've double clicked the "submit" button, and created two threads. Oups...

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: gptPolledDelay()

Postby Giovanni » Mon Oct 03, 2016 12:16 pm

Hi,

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

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

Giovanni

Jack666
Posts: 5
Joined: Mon Oct 03, 2016 10:38 am
Been thanked: 1 time

Re: gptPolledDelay()

Postby Jack666 » Mon Oct 03, 2016 1:19 pm

Thank you!


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 26 guests