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

Re: chThdSleepUntil() ??

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

Code: Select all

static THD_FUNCTION(Thread1, arg) {
   timeT = ST2MS(chVTGetSystemTime());
    while (1)
    {      
       My_func();
       chThdSleepUntil(MS2ST(timeT) );
       timeT += ST2MS(9);
   }

}


la led clignote exactement chauque 1MS mais apres 3 minutes j'ai une un erreur de 0.40 Secondes .
c'est quoi le souci

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 3:14 pm

ok, can you share all your chibios project?
Then I'm going to do some test on my side!

We can communicate on the irc if you want tonight to have a live discution. I'will be connected at 20H30.

Thanks,

Theo

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 3:15 pm

You can also read this it can sove your problem:
http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:timing

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

Re: chThdSleepUntil() ??

Postby RTOSman » Tue Feb 09, 2016 3:36 pm

Je peux pas car, car c'est un projet pro, dans un cadre de R&D :) ya des fichier.h et .cpp que j'ai pas l'autorisation de les publié
jusye une question, tu sais comment faire un chronomètre. je veux chronométrer ma boucle while ??

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 3:53 pm

You have an exemple on how to make a real time tack on the demo directory. But for that you have to use for exemple ChibiOS_16.0.3
The demo is locate in ChibiOS_16.1.3\demos\AVR\RT-ARDUINOUNO

This demo blink the LED every second.

To mesure a time execution you can use 2 variables for exemple start, stop and the debuger to see the difference.

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

Re: chThdSleepUntil() ??

Postby RTOSman » Tue Feb 09, 2016 4:08 pm

ok thanks :)
so could you give write me a program that start evey 10MS exactely.
thanks

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 4:15 pm

Take a look at the exmple everything is done. ChibiOS_16.1.3\demos\AVR\RT-ARDUINOUNO/ in the main.c
You just need a little modification to reach your gaol.

Did you try this?

Code: Select all

static THD_FUNCTION(Thread1, arg) {
  (void)arg;
  chRegSetThreadName("Blinker");
  while (true) {
    palTogglePad(IOPORT2, PORTB_LED1);
    chThdSleepMilliseconds(10);
  }
}


cheers,

Theo.

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

Re: chThdSleepUntil() ??

Postby RTOSman » Tue Feb 09, 2016 4:56 pm

i told you i will not use sleepmilli function, i want my thread execute evey 10 ms, so i have to use sleepuntil :)
if my functiin take some microsecondes and i use sleep after the time incremente :) so we have to avoid sleep
my probleme is that i could'nt eliminate the errors

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: chThdSleepUntil() ??

Postby tfAteba » Tue Feb 09, 2016 5:36 pm

If you want to remove errors over the time, you have then to use absolute deadlines rather than fixed intervals as in my previous code.

you have an exemple here: http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:timing

You will then have the above code:

Code: Select all

msg_t my_thread(void *param) {
 
  systime_t time = chVTGetSystemTimeX(); // T0
  while (true) {
    time += MS2ST(10);  // Next deadline
    do_something();
    chThdSleepUntil(time);
  }
}

That what you want to do ;) .

cheers,

Theo.

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

Re: chThdSleepUntil() ??

Postby RTOSman » Tue Feb 09, 2016 5:44 pm

yes i did this but i still got errors :)
after 3 minutes


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 5 guests