Time problem

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

Moderator: tfAteba

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

Time problem

Post 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
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: Time problem

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time problem

Post 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
RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

Re: Time problem

Post 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 :)
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: Time problem

Post 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
RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

Re: Time problem

Post by RTOSman »

and should i change the CH_TIME_QUANTUM value ??
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: Time problem

Post by utzig »

Why would you?
RTOSman
Posts: 29
Joined: Mon Feb 01, 2016 6:11 pm

Re: Time problem

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time problem

Post by Giovanni »

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

Re: Time problem

Post 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 :)
Post Reply