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

Maths Routine Problem???

Hi all,

I managed to get my interrupts working, and i have figured out a way to calculate the heart rate which is:

z = 60/(0.39*R7) = 153.84/R7 = 154/R7

But when i tried this formula, the LCD only display 77 BPM and 154 BPM. It seems that the overflow counter, R7, only count 1 - 2.

This is my code:

;***************************************
;-----------INTERRUPT CONFIGURATIONS-----------
;***************************************
SETB EA          ; Enable Global Interrupts
SETB ET0         ; Enable Timer 0 Interrupt
SETB EX0         ; Enable External Interrupt 0
SETB PX0         ; External Interrupt 0 High Priority

;***************************************
;------------TIMER 0 CONFIGURATIONS------------
;***************************************
TIMER_0 EQU 65535
SETB IT0          ; External Interrupt 0 detect falling-edge
MOV TMOD,#01H   ; Set Timer 0 to Mode 1
MOV A,CKCON     ; Move CKCON to Accumualtor
CLR ACC.3       ; Set system clock to divided by 12
MOV 70H,#00H    ; Move 0 to 70H
MOV R7,#02H     ; Move 4 to R7
MOV 62H,#01H    ; Move 1 to 62H
MOV TH0,#HIGH TIMER_0 ; Set High Byte of Timer 0
MOV TL0,#LOW TIMER_0  ; Set Low Byte of Timer 0

;**********************
;-Wait Until 4th Pulse-
;**********************
WAIT:   CJNE R7,#00H,WAIT  ; Compare and jump to subroutine "WAIT" if R7 != 0
CLR TR0 ; Stop Timer 0

;******
;-Math-
;******
MATH:   MOV A,#9AH      ; Move 154 to A
        MOV B,70H
        DIV AB
        MOV R6,A

;**********************
;-External Interrupt 0-
;**********************
EX_INT0:        DJNZ 62H,COUNT  ; Decrement 62H and jump if != 0
        SETB TR0        ; Start Timer 0

COUNT:  DEC R7          ; Decrement R7
        RETI            ; Return from Interrupt

;***********************
;-Timer 0 Overflow Flag-
;***********************
T0_INT: INC 70H                 ; Overflow Counter
             MOV TH0,#HIGH TIMER_0      ; Reloads Timer 0 with High Byte
        MOV TL0,#LOW TIMER_0    ; Reloads Timer 0 with Low Byte
        RETI                    ; Return from Interrupt

Any advice would be greatly apprectiated.

Parents
  • You want a high-resolution timer. That means that you can't just use the overflow value. Timer overflows too seldom. You should also use a couple of bits from the timer registers, until you have enough frequency/timer resolution.

    Just using the overflow value wll mean that when measuring, you will not be able to get a continuous range of output values.

    The external interrupt 0 code should check if enough # of pulse beats have been received, and then retrieve further bits of timer resolution.

    Don't you think that maybe you should sometimes revisit your earlier threads and read the comments there, before starting new threads. The information you received then specifically said that you might extend the timer range with an overflow. It did not say that you should only use the overflow counter, and ignore the values of the timer.

    By the way, why don't you label your variables? How fun is a source line that says:

        INC 70H                 ; Overflow Counter
    


    You have to add a comment just to keep track of what the memory cell 70H is used for, instead of naming the memory cell...

Reply
  • You want a high-resolution timer. That means that you can't just use the overflow value. Timer overflows too seldom. You should also use a couple of bits from the timer registers, until you have enough frequency/timer resolution.

    Just using the overflow value wll mean that when measuring, you will not be able to get a continuous range of output values.

    The external interrupt 0 code should check if enough # of pulse beats have been received, and then retrieve further bits of timer resolution.

    Don't you think that maybe you should sometimes revisit your earlier threads and read the comments there, before starting new threads. The information you received then specifically said that you might extend the timer range with an overflow. It did not say that you should only use the overflow counter, and ignore the values of the timer.

    By the way, why don't you label your variables? How fun is a source line that says:

        INC 70H                 ; Overflow Counter
    


    You have to add a comment just to keep track of what the memory cell 70H is used for, instead of naming the memory cell...

Children