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

PIC18F26k40 problem with RTOS

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



Joined: 24 May 2019
Posts: 5

View user's profile Send private message AIM Address

PIC18F26k40 problem with RTOS
PostPosted: Wed Jun 19, 2019 9:34 pm     Reply with quote

Hello, I have a compiler v5.076 in several PICs. I have successfully used the RTOS but this time I am using the PIC18F26k40 for the first time, and nothing related to the RTOS works for me. I will surely be doing something wrong, for which I am testing with a basic code like the next one and it does not work either.
On the contrary if instead of flashing the LED with RTOS I do it inside the main loop works correctly discarding connection problems. Does anyone have experience with RTOS and this PIC model?
The code compiles and loads without warnings.
Since very grateful Jose.
Code:

#include <18F26k40.h>

#FUSES NOEXTOSC                 //External Oscillator not enabled
#FUSES RSTOSC_HFINTRC_4MHZ   
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWDT


#use delay(internal=4000000)
#use rtos(timer=0,minor_cycle=1ms)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#use FIXED_IO( C_outputs=PIN_C1,PIN_C0 )

//$pins

#define LED_RED        PIN_C0//DEO
#define LED_YELLOW    PIN_C1//DEO

//$tasks
#task(rate=1000ms,max=1ms)
void pruebaTask1();

#task(rate=500ms,max=1ms)
void pruebaTask2();

//$main
void main() {
   
    rtos_run();
}


//$task

void pruebaTask1(void){
    output_toggle(LED_RED);
    rtos_yield();
}

void pruebaTask2(void){
    output_toggle(LED_YELLOW);
    rtos_yield();
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 20, 2019 1:25 am     Reply with quote

Why not start with the CCS example:
Quote:
ex_rtos_demo_1_tasks.c

Get rid of the #use fixed_io(), use the same task rates and maximum
task durations as shown in the CCS example, get rid of the rtos_yield()
calls, etc. And use the same 20 MHz clock speed. Once you have the
example working, then experiment with your changes.
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Thu Jun 20, 2019 1:45 am     Reply with quote

Use a different timer.

You'll find it'll work with timer1 for example.
The problem is that the timer0 settings on this chip are different from
the PIC 'standard', that the RTOS code assumes. Report it to CCS and
they'll probably fix this for the next release.
It defaults to setting the timer to run off the secondary oscillator (SOSC),
which you don't have available, so the timer doesn't run...
The T0CON register on this chip has radically different options to 99% of
other PIC's.
joseperri



Joined: 24 May 2019
Posts: 5

View user's profile Send private message AIM Address

PostPosted: Thu Jun 20, 2019 8:18 am     Reply with quote

First of all thank you very much for the answers. I tell you the result of the suggestions given.
Load the program ex_rtos_demo_1_tasks to which only the part of the USART changes for the LEDS since I have the PIC welded on a PCB without access to the USART (See code below) although the code compiles and loads correctly, with the TIMER0 not it works, however if I change to TIMER1 as they have suggested it works but does not respect the specified 1000ms rate but the LEDs are much slower.
I copy the code in case you have any other suggestions, again thanks Jose

/////////////////////////////////////////////////////////////////////////
//// ex_rtos_demo1_tasks.C ////

++++++++++++++++++++
Code deleted.
Reason: CCS forum rule #10:
10. Don't post the CCS example code or drivers,
or ask for such code and drivers.

Forum rules:
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

- Forum Moderator
++++++++++++++++++++
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Thu Jun 20, 2019 8:48 am     Reply with quote

Er. How is your chip going to be running at 20MHz?.
You are not specifying a crystal, and the internal clock cannot give 20MHz.
It's probably going to be running at 4, 8 or 16MHz. In all cases not 20Mhz.
Result timings will be wrong.
joseperri



Joined: 24 May 2019
Posts: 5

View user's profile Send private message AIM Address

PostPosted: Thu Jun 20, 2019 9:16 am     Reply with quote

You are right that was the problem. Having correctly defined the oscillator, the defined rate is respected. But since you said it only works with the TIMER1 not with the TIMER0, that query will be transferred to CCS support.
I copy the code that works.
Thank you
José
Code:

#include <18F26k40.h>

#FUSES NOEXTOSC                 //External Oscillator not enabled
#FUSES RSTOSC_HFINTRC_64MHZ 
#FUSES NOCKS                    //Clock Switching Disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWDT


#use delay(internal=32000000)

//#use delay(clock=20000000)
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#use standard_io(C)
#define LED_RED       PIN_C0//DEO
#define LED_YELLOW    PIN_C1//DEO
// this tells the compiler that the rtos functionality will be needed, that
// timer0 will be used as the timing device, and that the minor cycle for
// all tasks will be 100 miliseconds
#use rtos(timer=1,minor_cycle=1ms)

// each function that is to be an operating system task must have the #task
// preprocessor directive located above it.
// in this case, the task will run every second, its maximum time to run must
// be less than or equal to the minor cycle, and there is no need for a
// queue at this point, so no memory will be reserved.
#task(rate=2000ms,max=1ms)
// the function can be called anything that a standard function can be called
void The_first_rtos_task ( )
{
   output_toggle(LED_RED);
}

#task(rate=500ms,max=1ms)
void The_second_rtos_task ( )
{
   output_toggle(LED_YELLOW);
}

//#task(rate=100ms,max=100ms)
//void The_third_rtos_task ( )
//{
//   output_toggle(LED_RED);
//}

// main is still the entry point for the program
void main ( )
{
   // rtos_run begins the loop which will call the task functions above at the
   // schedualed time
   rtos_run ( );
}
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