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

Tracking Time using RTOS.

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



Joined: 19 May 2012
Posts: 26
Location: Pakistan

View user's profile Send private message

Tracking Time using RTOS.
PostPosted: Sat May 19, 2012 7:02 am     Reply with quote

Controller: PIC18f452

I am writing a program for LDU _ Leakage Detection Unit.
There are two Pressure Sensors and Two Gas Valves in a pipe 1,2 meters apart. Gas is allowed to enter from Valve_1 but Valve_2 is still closed. After 10 seconds Valve_1 is also closed. The Gas gets trapped in between the two valves. Now, Check for 2nd Pressure Sensor and if Pressure falls down, it means there is some leakage. If not, then it is fine. This is how, LDU works.

So, Timing is important.

I used a Task with rate =1s and introduced a variable timer9 and incremented it in the task. Every time the task runs timer9 gets incremented. So, after 10 seconds, timer9 =10.

Here is the code:


Code:

task (rate=1s,max=50ms)
void LDU()
{
rtos_awaits(state==0);                 // waits for the state =0
if (input(LDU)==Low)                   // LDU Disabled
   {
   LDU_Disable();
   state=1;
   }   
else
   {
   if (cs_ldu==0){dt_lcd_clear_screen();cs_ldu=1;}
   LDU_Enable();
   if (timer9==0)
      {
      dt_lcd_gotoxy(0,4);printf(dt_lcd_printchar,"GAS PRESSURE VALVE_1");
      dt_lcd_gotoxy(70,6);printf(dt_lcd_printchar,"OK     ");
      delay_ms(1500);
      }
   dt_lcd_gotoxy(0,3);
   output_High(Main_1);
   printf(dt_lcd_printchar,"VALVE_1   :  OPEN         ");
   dt_lcd_gotoxy(35,6);
   printf(dt_lcd_printchar,"%02d      ",timer9);
   timer9++;   
   if (timer9>10 && timer9<30)
      {
      output_low(Main_1);
      dt_lcd_gotoxy(0,3);printf(dt_lcd_printchar,"VALVE_1   :  CLOSE        ");
      }
   if (timer9>=13 && timer9<31)
      {
      dt_lcd_gotoxy(0,5);printf(dt_lcd_printchar,"TESTING .. .     ");
      }
   if (input(GP_SW2)==High && timer9>=30)       // Gas Pressure Valve 2 OK
      {
      Valve_Proving_Ok();
      dt_lcd_gotoxy(35,6);printf(dt_lcd_printchar,"%02d",timer9-30);
      output_high(Main_2);
      if (timer9==35)
         {
         output_low(GP_SW2);
         dt_lcd_gotoxy(0,4);printf(dt_lcd_printchar,"VALVE_2   :  CLOSE       ");
         delay_ms(300);
         state=1;
         }
      }
   }              // LDU High/ Else Closed
}                 // LDU Closed


I just want to make sure that if this time tracking strategy is accurate?
Are there other methods to track time?[/code]
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat May 19, 2012 9:37 am     Reply with quote

The timing _won't_ be terribly accurate.
First key is to understand that the RTOS, is like the multi-tasking on Windows, when we had things like W95, with the tasks only being called when the time requirements are met, _and_ the code returns control to the RTOS core. Just as in the early Windows OS's, if some application (one of the RTOS tasks), takes a long time to return, then the execution of other things is delayed. So the RTOS task may well be delayed, depending on what else is happening...

This is the fundamental difference between 'cooperative multi-tasking', and 'preemptive multi-tasking' (where the task _will_ be called at a reasonably exact time.

Second thing is that the timer itself won't give really accurate times. The code used has to load the timer with a constant to give the supposed 'tick', and there are errors associated with this (a search here will find lots of discussions about this). How acceptable this error will be will depend on just how accurate the timings need to be.

Going back to issue '1', your task is 'budgeted' to take a maximum of 50mSec, yet contain 300mSec, and 1500mSec delays. The RTOS times _will_ be screwed by this....
Read this from the #TASK manual entry:
"a programmer must be careful with how much processor time a task uses for execution."

If your other tasks also do things like this (take longer than they are budgeted for), then timing will be atrocious....

Other methods:
Run your own tick task using timer2. Check this when the RTOS task is called.
Run an external RTC, with an alarm output - either use this to trigger an interrupt, or poll this in the RTOS task.

Best Wishes
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