Hi, I'm trying to do a frecuency counter with an 89s52. I've made a long program, but it doesn't work well. In order to find the mistake, I've made this little program. #include <stdio.h> #include <reg52.h> sbit SENSOR=P2^3; void externa1 (void) interrupt 2 {EA=0; SENSOR=~SENSOR; EA=1; } void main (void) {IT1=1; IE=0x84; while(1) {} } A known signal (with a known period) interrupt in the INT1 line. The irq for INT1 toggle the bit 2 of port 3. The frequency of the signal in P2^3 must be the input frequency X 2. And here the problem: With relative high frequencies (100-1Khz) I didn't have any problem, but with low frequencies it starts to oscillate. Does anybody knows the solution for some kind of problems? Thanx Santiago
Sorry, it's true. It's frequency / 2 or period X 2. An example of oscillation: With a square wave with a period of (for example) 54.8ms (using a function generator) the pin P2^3 became this value (read from an hp universal counter): 109.6 ms (correct value) 164.4 ms 219.3 ms When I increased the period of the input, the diference between the suposed correct output value is bigger. Hope you can help me! Thanx a lot Santiago