kmilo17pet / QuarkTS

An open-source OS for embedded applications that supports prioritized cooperative scheduling, time control, inter-task communications primitives, hierarchical state machines and CoRoutines.
MIT License
218 stars 35 forks source link

timing #2

Closed billiumb closed 4 years ago

billiumb commented 4 years ago

Hello J. Camilo Gómez C.

Firstly thank you very much for this work, I am playing around with it now and find it very useful.

I was creating a pulse generator on the current version on a STM32F103 (blue pill) using a timer task set at every 10ms. The system tick is 1ms and is accurate.

If I use my 10ms task to increment a counter and set an o/p if odd or clear if even the pulse length is 9ms not 10ms!

Can give you more details if you want, but here is a little: In main.c

qSchedulerAdd_Task(&tmsTask, tms_cb, qLowest_Priority, 0.01, qPeriodic, qEnabled, "tms");

In qotasks.c

void tms_cb(qEvent_t event)
{
   static int cntr = 0;
.
.
. 
    cntr++;
    if(cntr & 1)
        GPIOA->BSRR = X_EN;
    else
        GPIOA->BSRR = X_EN << 16;
}

It toggles at 9ms

Thanks

Billy

kmilo17pet commented 4 years ago

Hi Billy, yes, it's a precision problem of the float data-type. I will fixed right now. The kernel allow float notation by default for timing definitions, however, I recomend to avoid float operations by setting Q_SETUP_TIME_CANONICAL to (1) in the qconfig.h file. When enabled, the kernel asumes the timing Base to 1mS(1KHz) and all the time specifications for tasks and STimers must be set in mS, this will improve the memory usage in systems without FPU, in your particular case, for the STM32F103 will be the best parameter.