Try increasing the 50ms value and check the output, you might detect something happening over a certain value.
Also, if BIT15 interrupt is triggered by any change in the bit 15, you might be triggering it when loading the counter.
Try disabling T16 interrupt after it's done, and re-enabling it after loading the timer, clearing the interrupt flag first.
Something else might be waking it up, check that, also try using a timer flag, ex. T16_busy.
BYTE T16_busy = 0; // To detect if timer is done
BYTE Other_interrupt= 0; // To detect if interrupt was triggered by something else
void T16_wait(){
Intrq.T16 = 0;
$ INTEN T16;
T16_busy=1;
while(T16_busy){ // Sleep until T16 is over, even if waken up
stopexe;
}
$ INTDIS T16;
}
void main(){
while(1){ // Toggle Led1 50ms, 3.6s low
$ outLED1 High, Out;
stt16 TIME50MS;
T16_wait();
$ outLED1 Low, Out;
stt16 TIME36S;
T16_wait();
if(Other_interrupt){ // other interrupt detected, enable both leds as a warning signal and stop execution
$ outLED1 High, Out;
$ outLED2 High, Out;
while(1);
}
}
}
void Interrupt(void){
pushaf;
if (Intrq.T16){
Intrq.T16 = 0;
T16_busy = 0;
}
else{ // Something else caused the interrupt
Other_interrupt= 1;
}
popaf;
}
That way, even if it wakes up, it'll inmediately enter sleep again, unless the Timer is done.
If this works, then check other interrupts sources you might have missed.
If it does the same, it suggests that effectively something is wrong with the timer.
Be careful with compiler optimizations, I have no idea how Padauk's works, T16_busy needs to be declared as volatile if any optimization is used.
Also check MISC Register, has a bit to adjust the wake speed between 2048 or 32 clocks, you should adjust your counting value to compensate this.