hi, i m facing one peculiar problem in timer 1 interrupt in Atmel 89c52. Using interrupt, I am generating a pulse at regular intervals. If I watch the pulses continuously in oscilloscope,sometimes pulse width is varying. Can anyone help me in this regards. I attached the code here. main() { /* Assume proper time settings here */ ---- ---- while(1) { P0=0; overflow_count=0; while(overflow_count <=4000); P0=1; overflow_count=0; while(overflow_count <=4000); } } void timer1 interrupt 3 { overflow_count++; } Assume no syntax error or logical errors in the code. regards, sara
Aside from latency, you have the problem that the ISR can increment overflow_count while main() is comparing or resetting it. In this case you would be better testing and resetting overflow_count and toggling the port pin in the ISR. You'll still get a little variation in pulse width (which will be worse if you have other interrupts of the same or higher priority active) but hopefully it'll be within your tolerance. Stefan