Page 1 of 2

Time problem

Posted: Mon Feb 01, 2016 6:43 pm
by RTOSman
Hello there, i did an arduino program with the chibios library.
I create 2 theade the first thread is high priority+1
static THD_FUNCTION(Thread1, arg) {

while (1) {

while (1) {
my_function();
chThdSleepMicroseconds(10);

}
}

the Second thread high priority-1
static THD_FUNCTION(Thread2, arg) {
while (1) {
Serial.print(result);
chThdSleepMicroseconds(1);
}}

My problem is that i'm not sure that my first thread start every 10 MS
sconde problem, i want the first thread start one time every 10 MS is there other function without chThdSleepMicroseconds();
thanks

Re: Time problem

Posted: Mon Feb 01, 2016 9:20 pm
by utzig
It should be chThdSleepMilliseconds instead of chThdSleepMicroseconds! Also in your first thread, having two nested infinite loops:

Code: Select all

while (1) {
  while (1) {
    ...
  }
}


doesn't seem very useful...

Fabio Utzig

Re: Time problem

Posted: Mon Feb 01, 2016 11:03 pm
by Giovanni
Also note that times are rounded up to the clock tick period, if your system tick is 100Hz then the resolution is 1/100 of second.

Giovanni

Re: Time problem

Posted: Tue Feb 02, 2016 11:06 pm
by RTOSman
Hello, thanks for your answer.

@utzig yes i did milisecond and just one while(1), i typed wrong message ^^.

@GiovanniBut how do i know the resolution of my system ??
i have arduino uno. could you tell me what's the resolution please :)
and could you explain me "times are rounded up to the clock tick period" i am fan of CHIBIOS i love this RTOS
Thanks :)

Re: Time problem

Posted: Wed Feb 03, 2016 1:46 am
by utzig
If your crystal is 16MHz and you're using the library from this repo https://github.com/greiman/ChibiOS-Arduino, your tick will be 1/976 which is around 1ms. The minimum sleep time is than 1ms. More info on this thread: viewtopic.php?f=21&t=2647

Re: Time problem

Posted: Thu Feb 04, 2016 8:20 pm
by RTOSman
and should i change the CH_TIME_QUANTUM value ??

Re: Time problem

Posted: Thu Feb 04, 2016 11:13 pm
by utzig
Why would you?

Re: Time problem

Posted: Fri Feb 05, 2016 12:31 am
by RTOSman
The poste that you gave me. i read that some one modify the value CH_TIME_QUANTUM.
what ever, i have a question. for exemple i have a function in my thread, i want my function doesn't exceed 10 Ms. or i want my function execute every 10MS. how do i program that ?
Thanks

Re: Time problem

Posted: Fri Feb 05, 2016 9:18 am
by Giovanni

Re: Time problem

Posted: Fri Feb 05, 2016 11:20 am
by RTOSman
Thanks for the replay, but what is the difference between this

Code: Select all

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


and this

Code: Select all

static THD_FUNCTION(Thread1, arg) {
     systime_t time = chTimeNow();     // T0
  while (true) {
    time += MS2ST(1000);            // Next deadline
    do_something();
    chThdSleepUntil(time);
  }
}


and i have a difficulte to understand the the system tick period ?? could you explain me what is it please :)