This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Intterupt not working...

Hi,

I'm using a timer and external interrupt to detect the pulse, i can set the timer to run for 5 secs and loop back. But the program cannot vector to the external interrupt. This is my interrupt configurations and routine.

;********************************************
;-----------INTERRUPTS CONFIGURATIONS--------
;********************************************
MOV IE,#8CH
MOV SWCINT,#000H
MOV EIE1,#000H
MOV EIE2,#000H
MOV EIP1,#000H
MOV EIP2,#000H
MOV IP,#08H

;****************************
;-Timer 1 Overflow Interrupt-
;****************************
T1_INT:    CLR TF1        ; Clear overflow flag
          MOV TH1,#0D0H
          MOV TL1,#0A0H
          RETI

;**********************
;-External Interrupt 1-
;**********************
EX_INT:    INC 40H         ; Increment 40H
          RETI

Does the input to the external interrupt need to be digital? Any advice would be nice... Thanks in advance.

  • "Does the input to the external interrupt need to be digital?"

    Yes, of course it does - see the Datasheet

  • In theory, you could use an analog signal (as long as the signal is within the allowed voltage range).

    However, you do not want to use an analog signal.

    Reason 1: If the interrupt input doesn't have a hysterese (with enough window size for the used signal) you may get a large number of interrupts for an input signal that floats between the defined high and low detect levels.

    Reason 2: Quite a number of digital inputs have problems when the signal is held between the specified high and low detect levels. The input gates can get in a state where they starts to draw a lot of power. The inputs are designed to see signals that reasonably rapidly moves between logic low and logic high, and one of the reasons why unused inputs should not be left open.

  • Another thing. When measuring the pulse, you do not want to count # of heart beats in a fixed time interval. You want to measure the time between a fixed number of heart beats.

    If you measure for 5 seconds, the start of the measurement period can start directly after a heart beat, but it can just as well start just before a heart beat.

    In the same way, the 5 seconds can end just before or just after a heart beat.

    This gives an error of +/- 1 heart beat during your 5 seconds, or a pulse error of +/- 12 bpm. Not too impressive, I would think.

    This is the reason why a doctor who manually checks the pulse have to use a long time interval. You, on the other hand, have a high-quality clock available and can measure the exact number of milliseconds for a specific number of beat intervals.

    But that requires you to start (or reset) the timer at a heart beat, and to stop (or read out) the timer after n more heart beats have been received.

  • I see... But how do i change the signal to digital? I already use ADC for the detection of peak value. Also, i read in the tutorial in 8052 about interrupts, it states that i need to protect SFR register, using push and pop. If i use push and pop, how can i display after the program return from interrupt?

  • I know what you are talking about. I can start the timer at the 1st peak, but i do not know how to stop the timer at the 2nd peak. Also the value in TH1 and TL1 are 8-bit each. How do i combine them together when the timer stops?

    Let me think... hmm...
    Lets say i configured the timer in auto-reload mode and the external interrupt to detect falling edges already...

    External_INT: SETB TR1
    

    Like this i can only start the timer. I have no idea how to stop the timer. Any suggestions?

  • Use a buffer chip with hysterese input. Or you may use an OP:amp as comparator.

    I don't know what you mean by "protect SFR register, using push and pop".

    There is nothing really magic about SFR. You just have to realize that you get into trouble if both ISR and main application writes to the same register at the same time - who will win? Also, some registers must be read in a specific order because the read operation has a side effect. For example, a read from a serial port acknowledges the reception of the byte. A 16-bit capture register often requires that the processor reads out the low and high byte in a specific order.

    Push and pop doesn't have any special meaning for SFR. They do have special meaning for the normal processor registers. An ISR, that intends to use a register that the main application uses, must first save the old contents so that it can be restored before the ISR ends.

    Also look in the manual for the use of register banks.

  • Doesn't the data sheet have a suggestion how you stop the timer or alternatively just reads out the timer count?

    If you are going to develop the program in assembler, then you must figure out a way to either manage with an 8-bit timing value - or how to combine a high and low byte into a 16-bit number. Further, you must figure out how you convert a period time to a frequency (f = 1/T). This would be trivial in C.

  • My oscillator can only reach a minimum of 2MHz. In this case, the timer will overflow before the pulse come in. And if i take the time between 2 pulse, it will not be accurate. I could not find a 12KHz crystal which can give me 1ms ticks. I can only find 32.768KHz crystal which gives me 0.36ms ticks. Therefore, the program will run very slow and refreshes very slow.

    I just thought of a method using 2MHz...
    Can i just run the timer when the 1st pulse comes in and let it overflow? Everytime it overflow, i increment a variable until it reaches the 2nd pulse. Than i multiply the variable with 0.39sec(Time to overflow) to give me the time. Than i 1/T = F...
    Than F * 60 = BPM...
    Just asking whether isit advisable to use the method.

  • Can i just run the timer when the 1st pulse comes in and let it overflow?

    Yes !

    That's the whole secret behind measuring long time intervals with a fast timer.

  • Yes, most people would count timer overflows before having to use special crystals that are not suitable for the rest of the application.

    But, as I wrote in your previous thread, you really do not want to base your bmp on the time between two heart beats! The heart is not a metronome where each beat comes at exactly the same time interval. There is a bit of jitter, so you want to measure the time between a couple of heart beats to get an average.

  • I see... So instead of incrementing a variable until the 2nd pulse, i should increment until the 3-4 pulse?

  • Correct! No existing (real) heart beat monitor measures the pulse using a single heart beat interval.

  • I see... So instead of incrementing a variable until the 2nd pulse, i should increment until the 3-4 pulse?

    That would be one way to do it, but it would result in a very slow update rate, which might prove very irritating to the user of the device.

    Instead, you can measure the beat-to-beat frequency, but output an average value of the last X measurements (the larger X, the smoother the output).

  • Instead, you can measure the beat-to-beat frequency, but output an average value of the last X measurements (the larger X, the smoother the output).

    What do u mean by "output an average value of the last X measurements"? What is X measurements?