View previous topic :: View next topic |
Author |
Message |
ilker07
Joined: 03 Jun 2022 Posts: 32
|
RTOS with PIC |
Posted: Wed Apr 03, 2024 5:21 am |
|
|
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: 9232 Location: Greensville,Ontario
|
|
Posted: Wed Apr 03, 2024 6:58 am |
|
|
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: 19529
|
|
Posted: Wed Apr 03, 2024 7:15 am |
|
|
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
|
|
Posted: Wed Apr 03, 2024 8:06 am |
|
|
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: 19529
|
|
Posted: Wed Apr 03, 2024 9:32 am |
|
|
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
|
|
Posted: Thu Apr 04, 2024 3:01 am |
|
|
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: 9232 Location: Greensville,Ontario
|
|
Posted: Thu Apr 04, 2024 7:02 am |
|
|
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. |
|
|
|