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.

Parents
  • 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.

Reply
  • 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.

Children
  • 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?

  • What is X measurements?

    X is a positive number which is larger than 1.

    So if X is 4, you take four beat-to-beat measurements and average them.

  • "4 beat-to-beat measurements"

    You mean like from one pulse to 1 pulse, that is considerd one beat-to-beat? If i take 4 beat-to-beat, won't that a very long time?

  • The concept is called a running average.

    You use the time between beat 5 and 1 (4 periods) to emit a bmp.

    Then you use the time between beat 6 and 2 (4 periods) to emit a bmp.

    Then you use the time between beat 7 and 3 (4 periods) to emit a bmp.

    The first output will not be available until after you have detected 5 heart beats. Then, the display may update for every new heart beat detected.

    However, since a normal person at the best has a rest pulse just under 30 and normally in the 50-70 bpm, you can ignore the concept of a running average.

    If you take the time between 5 beats, a pulse of 28 bmp would give the first result after 9-11 seconds and then a new value every 9 seconds.

    With a more normal pulse of 60, the first value would be available afer 4-5 seconds, with a new update every 4 seconds.

    A young person at very hard load would with a pulse of 200 get a first value after 1.2-1.5 seconds, and a new update every 1.2 seconds.

  • I see... Many thanks for your all help...

    Regards,
    natur3