chThdSleepUntil() ??

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

chThdSleepUntil() ??

Postby RTOSman » Sat Feb 06, 2016 10:41 am

Hello there,

i used this function chThdSleepUntil() instead chThdSleepMilliseconds(). my question is what is the value we use in chThdSleepUntil(). system tick or milliseconde??
and who tell the chThdSleepUntil() to begin to count ???
Thanks

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: chThdSleepUntil() ??

Postby tfAteba » Mon Feb 08, 2016 12:57 am

Hello RTOSman,

my question is what is the value we use in chThdSleepUntil(). system tick or milliseconde??

The value use for this function is tick. But if you want to use milliseconds as your reférence, then you have to make a conversion from (ms) to (tick) by using for exemple MS2ST() function.

and who tell the chThdSleepUntil() to begin to count ???

I think, that the count begin at the moment you call your function, so you don't need to do anything else.

Theo.

RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

Re: chThdSleepUntil() ??

Postby RTOSman » Mon Feb 08, 2016 9:35 pm

Thanks, and how about chVTGetSystemTime()) it return ticks or miliseconds ??

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: chThdSleepUntil() ??

Postby tfAteba » Mon Feb 08, 2016 9:55 pm

Hi,

chVTGetSystemTime() return the system ticks.

The function prototype is static systime_t chVTGetSystemTime (void) and you can find all those informations on the ChibiOS/RT Manual http://chibios.sourceforge.net/docs3/rt/group__time.html#ga9abde73a5b3e779d86bdec83ca57f028

It is well documented I think, so read that and if you have any other questions you are welcome.

Theo.

RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

Re: chThdSleepUntil() ??

Postby RTOSman » Mon Feb 08, 2016 11:08 pm

Hello i read all the manual, but i still learning :). i have a problem with time i still can't master the time.

i have a thread i a high priority, it did this function

Code: Select all

static THD_FUNCTION(Thread1, arg) {
   timeT = ST2MS(chVTGetSystemTime());
    while (1)
    {
    ps_tel();//blink led suqar wave
    chThdSleepUntil(MS2ST(timeT));
    timeT += ST2MS(9);
      
   }
}

over time my blink does'nt blink every 1 seconde !! why ?

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 7:56 am

Hi RTOSman,

You did a little mistake.
You want to blink your led every 1 second, so why did you add ST2MS(9)?
Want your thread to run every 1000ms, so :
- Just add 1000ms to timeT variable, not ST2MS(9)
- Then call chThdSleepUntil(MS2ST(timeT));

As a result:

Code: Select all

static THD_FUNCTION(Thread1, arg) {
    timeT = ST2MS(chVTGetSystemTime());
    while (1)
    {
        ps_tel();//blink led suqar wave
         timeT += 1000;
         chThdSleepUntil(MS2ST(timeT));
    }
}


And I don't understand why you convert and reconvert system time to ms and so on?
Take a look at this http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:timing
I think it is much simpler :) .

Theo

RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

Re: chThdSleepUntil() ??

Postby RTOSman » Tue Feb 09, 2016 10:33 am

Hello :) it's veery complicated to explain you my project, if you want i hava e function that i took every sample in 10 MS this is in matlab simulink. after code generation.
and i did 9 because the time between the wakup of thread and my function is 1
so to do the 10 ms calculation, i did 9 so 9+1=10 and here a did my simulink modele. and mt led blink exactely everry 1 ms just over time ihave errors. after 3 minute i have errors of 40 MS.

Du coup tu parles français ?

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 1:19 pm

Hi,

Yes has my location suggest I speack french ;)

why? you want to discust in french?

Ok, i'm understand, wich chibios and board do you use for your project?

RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

Re: chThdSleepUntil() ??

Postby RTOSman » Tue Feb 09, 2016 2:10 pm

Bonjour, enfaîte j'au une arduino uno. j'ai la bibliothèque chibio 3.0.3.
je voudrais faire des test pour maîtriser le temps. donc j'ai intégré une fonction qui génère un signale carré de fréquence de 1. le problème c'est que au fil du temps la fréquence augmente un peux, quand je dépasse 3 minutes par exemple la j'ai un retarde de 40 MS. je sais pas comment faire pour éliminer ce retard ?
Vous avez des solutions a me proposer ?

vous pouvez me donnez un algo pour bien exécuter une tache chaque 10 MS !!
Merci d'avance

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 2:32 pm

Hi,

How do you mesure the time?

My solution would be to fucus together on the code you did to resolve the problem.

cheers, Theo


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 2 guests