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