2004-06-10 03:27 PM
strange problem! Does 256 bigger than 400 ?
2004-06-08 04:03 PM
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 ]2004-06-09 03:18 AM
2004-06-10 02:38 PM
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 ]2004-06-10 03:27 PM
_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!