Hi all,
I'm currently doing a project on measuring heart rate using a sensor.
I have tried programming to display the beats per min(BPM) on a LCD but to no avail. I'm using Silabs C8051F226 development kit. The LCD only displays 2 values either "77 BPM" or "154 BPM". I'm using a timer and an external interrupt. In the external ISR, when the 1st pulse comes in, i'll start the timer and stop the timer at the 2nd pulse. And in the timer ISR, i count the number of overflows. I suspect that my overflows counter always count from 1-2 only... Thats why in my maths routine, it gave me the 2 values.
My code are as follows:
Any advice?
I'm currently doing a project on measuring heart rate using a sensor.
I have tried programming to display the beats per min(BPM) on a LCD but to no avail. I'm using Silabs C8051F226 development kit. The LCD only displays 2 values either "77 BPM" or "154 BPM". I'm using a timer and an external interrupt. In the external ISR, when the 1st pulse comes in, i'll start the timer and stop the timer at the 2nd pulse. And in the timer ISR, i count the number of overflows. I suspect that my overflows counter always count from 1-2 only... Thats why in my maths routine, it gave me the 2 values.
My code are as follows:
Rich (BB 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