Page 2 of 4

Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 12:07 am
by aek
Hi Lucian.

I got your files. Which version of MPLAB are you running?

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


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 12:08 am
by lucicop2001
Hi Andrew,

I have MPLAB 7.10.

------------------
Lucian

[This message has been edited by lucicop2001 (edited June 07, 2005).]


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 9:25 am
by lucicop2001
Hi again, after a new session of testing.

In fact today some days have passed since I try to make this part of the code work. It seems it is taking me a lot of time to make Salvo work as expected...

I will post all the relevant code, exactly as it is, maybe someone of you can spot the error. Here it goes, task Siren, called when an input is in alarm state:

code:
void Siren_Active (void) {
static OStypeTick ticks;
static Byte counts;
static DWord i = 0;

for (;; ) {
OS_WaitSem (SEM_SIREN, OSNO_TIMEOUT, SirenLabel);

//TODO: code when the siren is activated
counts = Parameters.PulseCount;

while (counts > 0) {
ticks = OSGetTicks() + (Parameters.BigLoudPeriod * MIN) -
Parameters.SmallSilentPeriod * SEC - Parameters.SmallLoudPeriod * SEC;

while (OSGetTicks() < ticks) {
SIREN = ON;

i = Parameters.SmallLoudPeriod;
do {
OS_Delay (100, SirenLabel1); // OS_Delay(100) gives a one second delay
}
while (i--);

SIREN = OFF;

i = Parameters.SmallSilentPeriod;
do {
OS_Delay (100, SirenLabel2);
}
while (i--);
}

SIREN = OFF;
counts --;

if (counts) {
i = Parameters.BigSilentPeriod * 60;
do {
OS_Delay (100, SirenLabel3);
}
while (i--);
}
}


Parameters.SysState = MONITORING;
}
}



The timer is configured here:
code:
	T0CON = 0b11000111;		//8 bit timer, with 1:256 prescaler

TMR0IE = 1;
TMR0 = TMR0_RELOAD;


, with TRM0_RELOAD calculated as follows:
code:

#define CPU_CLOCK 20000000L

#define INSTR_CLOCK CPU_CLOCK / 4L
#define TENMSEC INSTR_CLOCK / 100L
#define TMR0_RELOAD (TENMSEC / 256L)



The interrupt routine is:
code:
	if (T0IF) {
T0IF = 0;
TMR0 -= TMR0_RELOAD;
OSTimer ();
}

I cannot see anything wrong in that ! :(

Please help.

Best regards,

------------------
Lucian

[This message has been edited by lucicop2001 (edited June 07, 2005).]

[This message has been edited by aek (edited June 08, 2005).]


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 9:48 am
by aek
Hi Lucian.

And what is the observed failure?

Also, recall my previous comment that OStimerTicks wraps, and so you ticks calculation will (eventually) fail.

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


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 9:51 am
by aek
Also, are the parenthesis for the ticks calc in the right place?

If BigLoudPeriod = 0, while (OSGetTicks() < ticks) will always be false ...

And are the other units in the ticks calc in units of 1/100s?

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


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 9:51 am
by lucicop2001
Hi Andrew, and thank you again for the reply. I wonder when you have the time to do it all and whether your time runs twice as slower as ours

The failure is that the siren keeps pulsing, but not for 3s/2s as intended, but rather 4s (sometimes 6s)/2s, and not for the big period of 3 minutes, but forever. This happens in it's good times, because I have situations when it starts and never stops...

It seems to me that there is some problem with Salvo libraries or something.

Regards,

------------------
Lucian


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 9:52 am
by lucicop2001
The defines for MIN and SEC are:

code:
// Defines for timing
#define SEC 100 //system ticks - one each 10ms
#define HSEC 50
#define QSEC 25
#define HMSEC 10
#define MIN 60 * SEC

------------------
Lucian


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 9:56 am
by lucicop2001
Parameters.BigLoudPeriod is initialised with 3, but I tried with a constant value of 1. The siren sounds, but doesn't want to stop.

Interesting is that, in ISR I commented the code which made the semaphore for the siren to be signaled, so now it isn't signaled anymore, but I see that the initialisation task is not anymore executed either. I have at first created Siren_Init, which initialises the Parameters variable, then self modifies into Siren_Active. I cannot see the program entering into Siren_Init...

PS: Sorry for my English...
------------------
Lucian

[This message has been edited by lucicop2001 (edited June 07, 2005).]


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 9:57 am
by lucicop2001
I've had problems like that before, when I was using some other libraries, and the task weren't created... Could you confirm that for a 18F452, with 16bit ROM pointers, it is always correct to use slp86lta.lib library ?

------------------
Lucian


Re: Problems with libraries and delays

PostPosted: Tue Jun 07, 2005 10:00 am
by aek
quote:
ISR I commented the code which made the semaphore for the siren to be signaled
STOP! We both missed something ...

When you use an a-variant library, you have to manually control interrupts around every Salvo service that might also be called from an ISR.

E.g. if you call OSSignalBinSem() from an ISR, you must also call OSProtect() and OSUnprotect() around any similar call in mainline code. This is all because the PICC-18 compiler is not reentrant. See our RM-PICC18.PDF for more information ...

While that doesn't seem to be a problem here, it will cause problems if you forget to do this elsewhere ...

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

[This message has been edited by aek (edited June 07, 2005).]