cancel
Showing results for 
Search instead for 
Did you mean: 

strange problem! Does 256 bigger than 400 ?

perryliu
Associate II
Posted on June 11, 2004 at 00:27

strange problem! Does 256 bigger than 400 ?

4 REPLIES 4
perryliu
Associate II
Posted on June 09, 2004 at 01:03

Below is my program. I want to do something every 400ms.

So I use Timebase 1 interrupt(1ms) and increase a flag

variable by 1 in ISR. When the variable exceeds 400 then

do something. But sometimes IF judgement also success

when the variable's value is 256. And, if you want to

get 600 you may get 512, and so on. I have no idea why

it happens. Does anybody could help me ?

#include ''IO7FLIT1.h''

#define LITE1_enableINT (LTCSR1 = 0x10)

#define LITE1_disableINT (LTCSR1 = 0x00)

int iSoftMCount = 1;

void main()

{

volatile unsigned char RCCR0 @0xffde;

unsigned char ucStep = 0;

RCCR = RCCR0;

PADDR = 0x9f;

PAOR = 0xff;

PADR = 0x00;

PBDDR = 0xff;

PBOR = 0xff;

PBDR = 0x00;

LTCSR1 &= 0xf7;

LITE1_enableINT;

_asm(''rim'');

while(1)

{

if(iSoftMCount>=400)

{

if(ucStep==0)

{

PBDR |= 0x40;

ucStep = 1;

PBDR &= 0xdf;

}

else if(ucStep==1)

{

PBDR &= 0xbf;

PBDR |= 0x20;

ucStep = 0;

}

iSoftMCount = 0;

}

} // end while

} // end main

@interrupt void LITE1_RPM_ISR()

{

iSoftMCount++;

LTCSR1 &= 0xf7;

}

[ This message was edited by: Perry on 09-06-2004 04:53 ]
luca239955_st
Associate III
Posted on June 09, 2004 at 12:18

Hi,

I'm not sure there is a direct connection to your problem, but:

- globals modified in the interrupt and in the main flow shoud be declared as volatile (http://www.cosmic.fr/newsite/faq/faq9.php)

- when testing a multibyte variable (int) that is modified in an interrupt routine you should disable interrupts, otherwise you could have the variable incremented in beween the test of the high and low byte, with wrong results.

Hope this helps.

Luca

perryliu
Associate II
Posted on June 10, 2004 at 23:38

Problem still remains ! But the waveform becomes more regular.

It is supposed to be:

PB5 400(low) 400(high) 400(low) 400(high) 400(low) 400(high) ...

PB6 400(high)400(low) 400(high)400(low) 400(high)400(low) ...

Now it appears:

PB5 400(low) 256(high) 400(low) 256(high) 400(low) 256(high) ...

PB6 400(high)256(low) 400(high)256(low) 400(high)256(low) ...

I can't work it out.

[ This message was edited by: Perry on 11-06-2004 03:34 ]

perryliu
Associate II
Posted on June 11, 2004 at 00:27

_luca, thanks, I had had my problem solved.

''- when testing a multibyte variable (int) that is modified in an interrupt routine you should disable interrupts, otherwise you could have the variable incremented in beween the test of the high and low byte, with wrong results''

That's the key!