Pumpkin, Inc.

Pumpkin User Forums

task not run after OS_Delay

If you can't make Salvo do what you want it to do, post it here.

task not run after OS_Delay

Postby sunny » Mon Mar 31, 2003 1:10 am

Hi,

I find a problem when I want to delay my ADC sampling task using OS_Delay

code:
void interrupt_at_high_vector( void )
{
if( PIR1bits.TMR1IF )
{
PIR1bits.TMR1IF = 0;
WriteTimer1( -1000 ); // set timer1 100uS
INTCONbits.GIEH = 1; // re-enable the GIEH
OSTimer();
}
}

void TaskSampling( void )
{
/* do some init first */

for(;;)
{
//OS_WaitSem( SAMPLE_EN_P, 1, TaskSampling_1);
/* ConverADC() */
/* move ADC data 2 ram */
LATBbits.LATB6 = !LATBbits.LATB6;
OS_Delay( 20, TaskSampling_2 );
}
}


The ISR period occurs at ever 100us but after update the OSTimer(), the OSSched() don't try to swith the context after 20 ck tick (sitting at OSIdlingHook all the time).

How can I correct this (relate to salvocfg.h?) and how can I know the task statue using MPLAB SIM debugger?

here is the salvocfg.h

code:
#define OSENABLE_IDLING_HOOK				TRUE
#define OSENABLE_SEMAPHORES TRUE
#define OSEVENTS 1
#define OSTASKS 1

#define OSBYTES_OF_DELAYS 2
#define OSBYTES_OF_TICKS 2


Is there any quick command manual to download?

[This message has been edited by aek (edited March 31, 2003).]

sunny
 
Posts: 7
Joined: Mon Mar 24, 2003 12:00 am
Location: hong kong

Re: task not run after OS_Delay

Postby aek » Mon Mar 31, 2003 5:45 am

Hi Sunny.

1) Are you using Salvo Lite, LE or Pro? The salvocfg.h you list will only work in a source-code build with Salvo Pro.

2)

code:
void interrupt_at_high_vector( void )
{
if( PIR1bits.TMR1IF )
{
PIR1bits.TMR1IF = 0;
WriteTimer1( -1000 ); // set timer1 100uS
INTCONbits.GIEH = 1; // re-enable the GIEH
OSTimer();
}
}

You have an error in your code --
code:
INTCONbits.GIEH = 1;

You must not re-enable GIEH inside your ISR, as this can lead to nested interrupts, which really don't work on the PIC. Remove this line -- your compiler will automatically restore the GIEH bit at the end of the ISR.

3) What is your clock speed? As I recall, you're running at 4MHz. A system tick period of only 100us is much too fast. You are only giving the system 100 cycles between system ticks, i.e. between interrupts! This will break your system, because there is not enough time to complete longer operations in the RTOS between interrupts.

You should pick a system period of around 2,000-10,000 instructions, i.e. 2-10ms at 4MHz on a PIC16. Then OS_Delay() should work fine.

3)

quote:
How can I know the task statue using MPLAB SIM debugger?
Unfortunately that's not so simple, as there is no DLL for MPLAB to be able to parse out the fields in the task control blocks.

You can "peek" at the various task states by viewing memory, finding the tcbs in OStcbArea[] (look in the .map file for their address), and reviewing the struct tcb in salvo.h to figure out where the task status (3 bits) is located for each task. However, very few Salvo users do this, as once they get the system running it becomes unnecessary.

4)

quote:
Is there any quick command manual to download?
The Salvo user manual is the main manual for you to use. Pay careful attention to Chapter 5 - Configuration and which configuration options can be used with which types of projects (e.g. with library builds, source-code builds, etc.).

Regards,

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: task not run after OS_Delay

Postby aek » Mon Mar 31, 2003 5:49 am

Hi Sunny.

Actually, looking at your code, it looks like your system tick period is 1000 cycles, or 1ms. That is probably OK. But 2-10ms would be better.

The rest of your code looks fine (except for the problem with GIEH, of course). Did you verify that your call to OSCreateTask(TaskSampling, ...) returns OSNOERR (i.e. 0)?

Regards,

------------------

[This message has been edited by aek (edited March 31, 2003).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: task not run after OS_Delay

Postby sunny » Wed Apr 02, 2003 7:05 am

Thanks for help!

Thanks for point out the misstake. The program is corrected.

Now the PIC run at 40MHz and tick is set at 2000 clock (=200uS). I use such a fast clock tick is for signal sampling ONLY!, after sampling, the clock tick will reduce.

Question about OS_WaitSem and OSNO_TIMEOUT.
The MPLAB SIM show me the task is wait sem forever with OSNO_TIMEOUT. The real chip tell difference story that OS_WatiSem only let the task wait 80mS (400 tick).

What is the reson for that?

Thanks for help again :P

Sunny

code:
void main( void )
{
int i;

startup_init ();
OSInit();

OSCreateTask( TaskSampling, OSTCBP(1), 1 );
LATBbits.LATB7 = 0;
LATBbits.LATB7 = 1;

OSCreateSem( SAMPLE_EN_P, 9); //create no. of semaphore = 10
OSSignalSem( SAMPLE_EN_P ); //signal all the semaphore

for (;;)
OSSched();
}

void TaskSampling( void )
{
/* do some init first */

for(;;)
{
LATBbits.LATB6 = 0;
OS_WaitSem( SAMPLE_EN_P, OSNO_TIMEOUT, TaskSampling_1);
LATBbits.LATB6 = 1;
OS_Delay( 2, TaskSampling_2 );
/* ConverADC() */
LATBbits.LATB7 = !LATBbits.LATB7;
}
}


[This message has been edited by aek (edited April 02, 2003).]

sunny
 
Posts: 7
Joined: Mon Mar 24, 2003 12:00 am
Location: hong kong

Re: task not run after OS_Delay

Postby aek » Wed Apr 02, 2003 7:20 am

Hi SUnny.
quote:
Now the PIC run at 40MHz and tick is set at 2000 clock (=200uS). I use such a fast clock tick is for signal sampling ONLY!, after sampling, the clock tick will reduce.
Are you using Salvo Lite, LE or Pro? With Pro, you can use OSTIMER_PRESCALAR to slow down the system ticks from within an ISR that is very fast. You can also do this yourself, something like
code:

if ( --prescalar == 0 )
{
prescalar = PRESCALAR_RELOAD;
OSTimer();
}

quote:
Question about OS_WaitSem and OSNO_TIMEOUT.
The MPLAB SIM show me the task is wait sem forever with OSNO_TIMEOUT. The real chip tell difference story that OS_WatiSem only let the task wait 80mS (400 tick).

What is the reson for that?


I suspect something may be wrong in your configuration, or elsewhere in your code. Can you post your complete salvocfg.h? And which library are you using? And which files are in your project. If possible, .zip everything and email it to support@pumpkininc.com and we'll create a project here (MPLAB v5.5x) and test it here.

Regards,

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: task not run after OS_Delay

Postby sunny » Wed Apr 02, 2003 9:26 am

I already solve the problem.

Adding OSENABLE_TIMEOUTS TRUE in salvocfg.h.

The program works!

Thanks!

sunny
 
Posts: 7
Joined: Mon Mar 24, 2003 12:00 am
Location: hong kong

Re: task not run after OS_Delay

Postby aek » Thu Apr 03, 2003 9:31 am

Hi Sunny.

Great!

I overlooked the fact that you had included your salvocfg.h at the beginning of this thread -- sorry!

Regards,

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron