Time problem

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

Time problem

Postby RTOSman » Mon Feb 01, 2016 6:43 pm

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: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: Time problem

Postby utzig » Mon Feb 01, 2016 9:20 pm

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: 13008
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 742 times
Been thanked: 620 times
Contact:

Re: Time problem

Postby Giovanni » Mon Feb 01, 2016 11:03 pm

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

Postby RTOSman » Tue Feb 02, 2016 11:06 pm

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: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: Time problem

Postby utzig » Wed Feb 03, 2016 1:46 am

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

Postby RTOSman » Thu Feb 04, 2016 8:20 pm

and should i change the CH_TIME_QUANTUM value ??

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: Time problem

Postby utzig » Thu Feb 04, 2016 11:13 pm

Why would you?

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

Re: Time problem

Postby RTOSman » Fri Feb 05, 2016 12:31 am

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: 13008
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 742 times
Been thanked: 620 times
Contact:

Re: Time problem

Postby Giovanni » Fri Feb 05, 2016 9:18 am


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

Re: Time problem

Postby RTOSman » Fri Feb 05, 2016 11:20 am

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


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 1 guest