CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RTOS with PIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ilker07



Joined: 03 Jun 2022
Posts: 32

View user's profile Send private message

RTOS with PIC
PostPosted: Wed Apr 03, 2024 5:21 am     Reply with quote

Hello friends, I am trying to use rtos with pic, I got stuck somewhere.

#include <18F67K22.h>
#fuses NOMCLR, NOBROWNOUT, NOLVP, INTRC_IO
#use delay(internal=16000000)
#use rtos(timer = 0, minor_cycle = 50ms)
#task(rate = 250ms, max = 50ms) // 1st RTOS task
void t1(){
//t1 codes
}
#task(rate = 500ms, max = 50ms) // 2nd RTOS task (executed every 500ms)
void t2(){
//t2 codes
}
void main(){
setup_oscillator(OSC_16MHZ|OSC_PLL_ON); //64 mhz
rtos_run();
}

Now, here I want task t1 to repeat as continuously as possible (example 1us) and task t2 to run every 1000 ms. All operations of task t1 take approximately 10 ms, and all operations of task t2 take approximately 30 ms.
In this situation;
#use rtos(timer = 0, minor_cycle = 50ms)
#task(rate = 250ms, max = 50ms)
#task(rate = 500ms, max = 50ms)

What should the values in these 3 lines be? The rate value is the repetition time and the max value is the repetition time of the task. When I write these, a minor_cycle error occurs. What should I enter here?


Another question is ;Can I use any delay function like delay_us() in tasks?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 03, 2024 6:58 am     Reply with quote

re: I want task t1 to repeat as continuously as possible (example 1us) and ... All operations of task t1 take approximately 10 ms,

Maybe I'm reading this wrong but just HOW can T1 execute every 1us if it takes 10ms to run it's code ??
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Wed Apr 03, 2024 7:15 am     Reply with quote

You can't. You'd need a faster processor, so it can execute in less time than
the repeat time. Just can't be done. The processor can only do one thing
at a time. Also understand that when it is executing t2, t1 will stop.
The shortest minor cycle time you can specify is the worst case time of
the two functions. So if t2 takes no more than 30mSec, you can specify
the minor cycle as 30mSec. Then the shortest repeat interval you can give
is this time. So:
Code:

#include <18F67K22.h>
#fuses NOMCLR, NOBROWNOUT, INTRC_IO
#use delay(internal=16000000)
#use rtos(timer = 0, minor_cycle = 30ms)

#task(rate = 30ms, max = 10ms) // 1st RTOS task
void t1(){
    //t1 codes
    delay_ms(10); //so this rakes 10mSec
}
#task(rate = 990ms, max = 30ms) // 2nd RTOS task (executed every 500ms)
void t2(){
    //t2 codes
    delay_ms(30); //and this takes 30
}
void main(){
   setup_oscillator(OSC_16MHZ|OSC_PLL_ON); //64 mhz
   rtos_run();
}


This will execute t1 every 30mSec, except when t2 is running, where there
will be one cycle missed.
ilker07



Joined: 03 Jun 2022
Posts: 32

View user's profile Send private message

PostPosted: Wed Apr 03, 2024 8:06 am     Reply with quote

temtronic wrote:
re: I want task t1 to repeat as continuously as possible (example 1us) and ... All operations of task t1 take approximately 10 ms,

Maybe I'm reading this wrong but just HOW can T1 execute every 1us if it takes 10ms to run it's code ??


You are right.All I wanted to say how I can do that without any delay.
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Wed Apr 03, 2024 9:32 am     Reply with quote

Don't use the RTOS.
Just setup your own interrupt and counter to time the one second
needed for t2, and have t1 sitting looping as fast as it can,. either execute
t2 from the interrupt or have it just test for the timeout required for
t2 between each loop.
The RTOS is designed to allow multiple things to execute interleaved
with one another. Not what you want.
ilker07



Joined: 03 Jun 2022
Posts: 32

View user's profile Send private message

PostPosted: Thu Apr 04, 2024 3:01 am     Reply with quote

Ttelmah wrote:
Don't use the RTOS.
Just setup your own interrupt and counter to time the one second
needed for t2, and have t1 sitting looping as fast as it can,. either execute
t2 from the interrupt or have it just test for the timeout required for
t2 between each loop.
The RTOS is designed to allow multiple things to execute interleaved
with one another. Not what you want.


t1==>Read 2 adc values and do some stuff with these values
t2==>Print them to sd1306 screen

if I use interrupt for t2 ,it takes too much time anyway,when i use interrupt for t1,values on the screen is distorting.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 04, 2024 7:02 am     Reply with quote

I'm curious as to what analog signals you're reading, temperature ??

Also see the GLCD spec for 'update rate', or whatever they call the minimum time it takes to 'show a new screen'. If it's say 500ms, then you can't update it any faster than 2x a second. I use an external RTCEEP module to send an interrupt at 1Hz to the PIC, to trigger an LCD refresh/update/new screen..... It also triggers the remote temperature sensors to take new readings.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group