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

CCS RTOS problem please help me

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







CCS RTOS problem please help me
PostPosted: Thu Oct 04, 2007 2:07 pm     Reply with quote

I have the following problem, I am trying to use RTOS to receive characters via software uart and it works fine, simultaneously I use a simple task to toggle a LED every 0.5 seconds, there is where I have a problem. When I set the LED task RATE higher than 30ms the LED task works erratically, but if I set the RATE to 30 ms it works perfectly, of course the led toggle too fast.

What I am doing wrong?

Thanks



Here is the code: I am using CCS V4


#include <18F452.h>
#fuses H4,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=40000000)
#use RS232(baud=38400,xmit=PIN_C1,rcv=PIN_C2,bits=8,parity=N,stream=debug,errors)

#use rtos(timer=0, minor_cycle=250us )

#define LED pin_c4

// Variables
#zero_ram
int8 buffer_232[20];

#task (rate=250us) // check for incoming bytes and when buffer reachs 8, send them to PC
void get_rs232(void){
static int8 rcvd=0;

while (!kbhit(debug))
rtos_yield();

buffer_232[rcvd]=getc(debug);
rcvd++;

if (rcvd >=8){
fprintf(debug,"%s",buffer_232);
rcvd=0;
}
}

#task (rate=500ms) // every 0.5 sec toggle LED
void toogle_led(void){
static int1 aux=0;
aux=!aux;
if (aux==1)
output_high(led);
else
output_low(led);
}

void main(void){

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);

disable_interrupts(GLOBAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0 (RTCC_DIV_2|RTCC_INTERNAL|RTCC_8_BIT);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

set_tris_a ( 0b00001000 );
set_tris_b ( 0b11111111 ); //All Inputs
set_tris_c ( 0b10000010 ); //All Outputs
set_tris_d ( 0b00000000 ); //All Outputs
set_tris_e ( 0b00000111 ); //All Inputs

output_high(LED);

rtos_run(); // Run RTOS Tasks
}
Guest








PostPosted: Thu Oct 04, 2007 6:08 pm     Reply with quote

I have the following problem, I am trying to use RTOS to receive
characters via software uart and it works fine, simultaneously I use a
simple task to toggle a LED every 0.5 seconds, there is where I have a
problem. When I set the LED task RATE higher than 30ms the LED task
works erratically, but if I set the RATE to 30 ms it works perfectly, of
course the led toggle too fast.

What I am doing wrong?

Thanks


PD: sorry I didnt know how to post code now it is corrected.

I contiue testing the code and when I change #USE RTOS minor_cycle
value to something really small like 10us or less, all the task RATES must
be no higher than 2 ms or else the code will fail, I dunno why.


Code:


#include <18F452.h>
#fuses H4,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=40000000)
#use RS232(baud=38400,xmit=PIN_C6,rcv=PIN_C7,bits=8,parity=N,stream=debug,errors)

#use rtos(timer=0, minor_cycle=250us )

#define LED pin_c4

// Variables
#zero_ram
int8 buffer_232[20];

#task (rate=250us)         // check for incoming bytes and when buffer reachs 8, send them to PC
void get_rs232(void){
   static int8 rcvd=0;

   while (!kbhit(debug))
      rtos_yield();
     
   buffer_232[rcvd]=getc(debug);
   rcvd++;

   if (rcvd >=8){
      fprintf(debug,"%s",buffer_232);
      rcvd=0;
   }     


#task (rate=500ms)         // every 0.5 sec toggle LED
void toogle_led(void){
   static int1 aux=0;
   aux=!aux;
   if (aux==1)
      output_high(led);
   else     
      output_low(led); 
}

void main(void){
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   
   disable_interrupts(GLOBAL);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0 (RTCC_DIV_2|RTCC_INTERNAL|RTCC_8_BIT);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   set_tris_a ( 0b00001000 );
   set_tris_b ( 0b11111111 ); //All Inputs
   set_tris_c ( 0b10000010 ); //All Outputs
   set_tris_d ( 0b00000000 ); //All Outputs
   set_tris_e ( 0b00000111 ); //All Inputs

   output_high(LED);
 
   rtos_run();       // Run RTOS Tasks
}
bwhiten



Joined: 26 Nov 2003
Posts: 151
Location: Grayson, GA

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 7:49 pm     Reply with quote

I believe your settings for Timer0 may not allow for a 500ms time out at your clock setting of 40MHz.
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