Page 1 of 1

OS_Delay()

PostPosted: Sat Apr 29, 2006 10:29 am
by Code_Nerd
This is just a quick little program I whipped up to test that my delay times were correct?
However I cannot simulate it correctly with MPLAB? I put break point on OSSched and each of the mainR assignments in the Lights task, but it never gets into the Lights task? Am I doing something wrong here...

Thankyou

code:
#include <salvo.h>
#include <timers.h>

#define TASK_LIGHT_P OSTCBP(1)

#define mainR PORTCbits.RC0
#define TMR0IE INTCONbits.TMR0IE
#define TMR0IF INTCONbits.TMR0IF

#pragma interrupt ISR

void Light(void)
{
OpenTimer0(TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_1);
while(1)
{
OS_Delay(50, lights1);
mainR = 1;
OS_Delay(50, lights2);
mainR = 0;
}
}

void main(void)
{
OSInit();
OSCreateTask(Light, TASK_LIGHT_P, 1);
TRISC = 0x00;
PORTC = 0x00;
while(1)
{
OSSched();
}
}

void ISR(void)
{
static int t = 490;

if((TMR0IE == 1) && (TMR0IF == 1))
{
TMR0IF = 0;
--t;

if(t == 0)
{
t = 490;
OSTimer();
}
}
}



Re: OS_Delay()

PostPosted: Mon May 01, 2006 3:14 am
by Code_Nerd
Thankyou for your reply..
I changed the declaration of t to a Global (my lecturers notes have it the previous way and I do not know how it is working like this).

The program is still not simulating as it should, it never jumps into the Lights Task?

Is there something else I am missing?

Thanks


Re: OS_Delay()

PostPosted: Mon May 01, 2006 3:23 am
by aek
Well, what happens when you put a breakpoint on the call to OSTimer()?

Add OStimerTicks to your watch window.

You should be able to break on the call to OSTimer() 50 times, and then break on inside the task ...

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


Re: OS_Delay()

PostPosted: Mon May 01, 2006 3:37 am
by Code_Nerd
OK, for the purposes of simulation I altered the figures and it seems to working fine?

However when I try to simulate it in Proteus ISIS (Not sure if your familiar with that?) Nothing happens..

code:
#include <salvo.h>
#include <timers.h>

#define TASK_LIGHT_P OSTCBP(1)

#define mainR PORTDbits.RD0
#define TMR0IE INTCONbits.TMR0IE
#define TMR0IF INTCONbits.TMR0IF
#define GIE INTCONbits.GIE

static int t = 5;

#pragma interrupt ISR


void Light(void)
{
PORTD = 0x00;
TMR0IF = 0;
OpenTimer0(TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_1);
while(1)
{
OS_Delay(1, lights1);
mainR = 1;
OS_Delay(1, lights2);
mainR = 0;
}
}

void main(void)
{
OSInit();
OSCreateTask(Light, TASK_LIGHT_P, 1);
TRISD = 0x00;
GIE = 1;
while(1)
{
OSSched();
}
}

void ISR(void)
{

if((TMR0IE == 1) && (TMR0IF == 1))
{
TMR0IF = 0;
--t;

if(t == 0)
{
t = 5;
OSTimer();
}
}
}

#pragma code IntVectorHigh = 0x08
void IntVectorHigh(void)
{
_asm
goto ISR
_endasm
}



Re: OS_Delay()

PostPosted: Mon May 01, 2006 4:00 am
by aek
quote:
Proteus ISIS (Not sure if your familiar with that?)
No idea what that is ... we simulate strictly in MPLAB.

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


Re: OS_Delay()

PostPosted: Mon May 01, 2006 4:19 am
by Code_Nerd
Well unfortunately it seems as though Proteus is buggy..

I just tested the little Delay program on my board and it works fine!

Proteus is good because you can usually simulate all your components without wiring them up etc.. You can see it here http://www.labcenter.co.uk/index_uk.htm

Thanks again for your help Aek..


Re: OS_Delay()

PostPosted: Mon May 01, 2006 8:49 am
by aek
t is declared incorrectly -- you need to declare it outside of the ISR. Right now it's redefined to 490 each time the ISR occurs, which means you never call OSTimer().

MPLAB is very nice for testing this sort of thing --- open the Stopwatch window and you can count cycles between breakpoints, etc.

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