mcs51mc said:When is an interrupt generated?
Once you know that, what is the time between 2 interrupts with the above code?
Time_1 equ 65535[B]-10000[/B] ;10ms interrupt assuming 12MHz xtal
Time_1 equ 65535[B]-2000[/B] ;2ms interrupt assuming 12MHz xtal
That's working the wrong way!!S.K said:Hmm... I thought of another easier method. That is to set the timer to run for 5 secs and count the number of pulses during that 5 secs than using the answer to multiply by 12 to get BPM.
Excuse me but I think you still don'tS.K said:Assuming the interrupt is generated at 1sec per beat, the time between 2 interrupts will be 2secs.
Yea, i understand the meaning of:
Code:Time_1 equ 65535[B]-10000[/B] ;10ms interrupt assuming 12MHz xtal Time_1 equ 65535[B]-2000[/B] ;2ms interrupt assuming 12MHz xtal
Don'tS.K said:Assuming
You can't expect the beats to come every sec
How will time 1sec?
Are you sure of your peak detection?
Connect a stable signal with known frequency to your µC to do the tests!
extrn code (add_32_signed, add_32_unsigned, add_24_signed, add_24_unsigned, add_16_signed, add_16_unsigned, add_8_signed, add_8_unsigned)
extrn code (sub_32_signed, sub_32_unsigned, sub_24_signed, sub_24_unsigned, sub_16_signed, sub_16_unsigned, sub_8_signed, sub_8_unsigned)
extrn code (mul_16x16_signed, mul_16x16_unsigned, mul_16x16_signed_op1)
extrn code (div_32x16_signed, div_32x16_unsigned, div_32x16_signed_op1)
extrn data (MathLib_Op1, MathLib_Op2, MathLib_Res1, MathLib_Res2)
extrn bit (MathLib_DivByZero, MathLib_Res1Neg, MathLib_Res2Neg, MathLib_Overflow, MathLib_Underflow)
mov MathLib_Op1+0,MathLib_Res1+2 ;Average n samples * a
mov MathLib_Op1+1,MathLib_Res1+3
mov MathLib_Op2+0,#043h ;a= 17255 (4366)h
mov MathLib_Op2+1,#066h
call mul_16x16_unsigned
mov MathLib_Op1+0,MathLib_Res1+0 ;Result + b
mov MathLib_Op1+1,MathLib_Res1+1
mov MathLib_Op1+2,MathLib_Res1+2
mov MathLib_Op1+3,MathLib_Res1+3
mov MathLib_Op2+0,#0F6h ;b= -156912265 (F6A5 B577)h
mov MathLib_Op2+1,#0A5h
mov MathLib_Op2+2,#0B5h
mov MathLib_Op2+3,#077h
call add_32_signed
mov Temperature+0,MathLib_Res1+0 ;Store result
mov Temperature+1,MathLib_Res1+1
Long time ago I used the free 2K evaluation kit from Keil. I have OBJ files in the project folder, so Keil also generate OBJ files but I don't know if you can provide an OBJ fileS.K said:I'm using Keil assembler... I'm not sure how to include OBJ files... Is OBJ files like another file that i can call in my main program?
I know some µC like the AT89C2051 have a comparator capability on specific inputs to check amplitudes.S.K said:Btw, i have a question... Can 8051 detect pulses below/above a certain amplitude
Isn't that what you are doing??S.K said:and also can it detect pulses below/above a certain frequency?
What do you mean by "range"?S.K said:Like is there a range for the 8051 to detect the pulses?
;*************
;-Header File-
;*************
$include (c8051f200.inc)
ORG 0000H
LJMP CONFIG
ORG 0003H
LJMP EX_INT0
ORG 002BH
LJMP T2_INT
ORG 0100H
;*************
;-Definitions-
;*************
DB0 EQU P3.0
DB1 EQU P3.1
DB2 EQU P3.2
DB3 EQU P3.3
DB4 EQU P3.4
DB5 EQU P3.5
DB6 EQU P3.6
DB7 EQU P3.7
RS EQU P2.7
RW EQU P2.5
EN EQU P2.6
DAT EQU P3
TIMER_2 EQU 65535 - 10000
RAM_ADDR EQU 40H
ASCI_RSULT EQU 50H
OVERFLOW_COUNTER EQU 70H
START_TIMER EQU 60H
VALUE_LOW EQU 65H
VALUE_HIGH EQU 66H
;***************
;-Configuration-
;***************
CONFIG:
;**************************************
;------------PORT I/O CONFIGURATIONS----------
;**************************************
MOV PRT0MX,#080H ; PRT0MX: T2EX routed to port pin
MOV PRT1MX,#000H ; PRT1MX: Initial Reset Value
MOV PRT2MX,#000H ; PRT2MX: Initial Reset Value
MOV P2MODE,#0FFH ; Set Port 2 as Input
MOV P0MODE,#0FFH ; Set Port 0 as Input
MOV P1MODE,#000H ; Set Port 1 as Analog Input
MOV PRT3CF,#000H ; Set Port 3 as Output
CLR RS1
CLR RS0
;**********************************************
;-----------OSCILLATOR CONFIGURATIONS----------
;**********************************************
MOV OSCXCN,#067H ; External Oscillator Control Register
CLR A ; Clear value of Accumulator
DJNZ ACC,$ ; Wait for
DJNZ ACC,$ ; at least 1ms
OX_WAIT: MOV A,OSCXCN ; Move data in OSCXCN to Accumulator
JNB ACC.7,OX_WAIT ; Poll XTLVLD
MOV OSCICN,#008H ; Internal Oscillator Control Register
;**********************************************
;-----------INTERRUPT CONFIGURATIONS-----------
;**********************************************
SETB EA ; Enable Global Interrupts
SETB ET2 ; Enable Timer 2 Interrupt
SETB EX0 ; Enable External Interrupt 0
SETB PX0 ; External Interrupt 0 High Priority
;**********************************************
;------------TIMER 0 CONFIGURATIONS------------
;**********************************************
SETB EXEN2 ; Enable High to low transition causes a capture
SETB CT2 ; Timer function
SETB T2CON.1 ; Capture on high to low transiton on T2EX
MOV A,CKCON ; Move CKCON to Accumualtor
CLR ACC.3 ; Set system clock to divided by 12
MOV OVERFLOW_COUNTER,#00 ; Move 0 to R7
MOV R7,#0 ; Move 4 to R3
MOV START_TIMER,#01 ; Move 1 to R4
MOV TH2,#HIGH TIMER_2
MOV TL2,#LOW TIMER_2
;***********************************************
;----------WATCHDOG TIMER CONFIGURATIONS--------
;***********************************************
CLR EA ; *****************
MOV WDTCN,#0DEH ; Disable WatchDog
MOV WDTCN,#0ADH ; Timer
SETB EA ; *****************
;***************
;-Main Function-
;***************
MAIN: ACALL INIT_LCD ; Call subroutine "INIT_LCD"
ACALL CLEAR_LCD ; Call subroutine "CLEAR_LCD"
ACALL ON_LCD ; Call subroutine "ON_LCD"
ACALL WAIT ; Call subroutine "WAIT
;*******************************
;-Initialization By Instruction-
;*******************************
INIT_LCD: CLR EN
CLR RS ; FUNCTION SET
MOV DAT,#30H ; ************************
SETB EN
ACALL DELAY ; Interface is 8-bits long
CLR EN
ACALL DELAY ; ************************
CLR RS ; FUNCTION SET
MOV DAT,#30H ; ************************
SETB EN
ACALL DELAY ; Interface is 8-bits long
CLR EN
ACALL DELAY ; ************************
CLR RS ; FUNCTION SET
MOV DAT,#30H ; ************************
SETB EN
ACALL DELAY ; Interface is 8-bits long
CLR EN
ACALL DELAY ; ************************
CLR RS ; FUNCTION SET
MOV DAT,#38H ; ************************
SETB EN ; Set LCD to 8-bits,
ACALL DELAY ; 2 lines and 5x7 matrix
CLR EN
ACALL DELAY ; ************************
CLR RS ; DISPLAY OFF
MOV DAT,#08H ; ************************
SETB EN ; Display Off
ACALL DELAY ; Cursor Off
CLR EN ; Blink of Cursor Off
ACALL DELAY ; ************************
CLR RS ; CLEAR DISPLAY
MOV DAT,#01H ; ************************
SETB EN
ACALL DELAY ; Clear Display
CLR EN
ACALL DELAY ; ************************
CLR RS ; ENTRY MODE SET
MOV DAT,#06H ; ************************
SETB EN ; Increment Cursor Position
ACALL DELAY ; No Display Shift
CLR EN
ACALL DELAY ; ************************
CLR RS ; CURSOR POSITION
MOV DAT,#80H ; ************************
SETB EN
ACALL DELAY ; Force cursor to position
CLR EN ; at 1st line 1st position
ACALL DELAY ; ************************
RET
;********
;-On LCD-
;********
ON_LCD: CLR RS ; ON LCD
MOV DAT,#0CH ; *************************
SETB EN ; Display On
ACALL DELAY ; Cursor On
CLR EN ; Blink of Cursor On
ACALL DELAY ; *************************
RET
;***********
;-Clear LCD-
;***********
CLEAR_LCD:CLR RS ; CLEAR DISPLAY
MOV DAT,#01H ; *************************
SETB EN
ACALL DELAY ; Clear Display
CLR EN
ACALL DELAY ; *************************
RET
;**********************
;-Wait Until 4th Pulse-
;**********************
WAIT: CJNE R7,#00H,WAIT ; Wait for 4th pulses
CLR TR2 ; Stop Timer 0
;******
;-Math-
;******
MATH: MOV A,OVERFLOW_COUNTER ; Stuck here... :(
MOV B,
;***********************************
;-Converting Binary(Hex) to Decimal-
;***********************************
BIN_DEC_CONVRT: MOV R0,#RAM_ADDR ; Save decimal digits in these RAM locations
MOV A,R6
MOV B,#10 ; B = 0A hex (10 dec)
DIV AB ; Divide by 10
MOV @R0,B ; Save lower digit
INC R0
MOV B,#10
DIV AB ; Divide by 10
MOV @R0,B ; Save the next digit
INC R0
MOV B,#10
DIV AB ; Divide by 10
MOV @R0,B ; Save the next digit
INC R0
MOV @R0,A ; Save the last digit
;*****************************
;-Converting Decimal to ASCII-
;*****************************
DEC_ASCI_CONVRT: MOV R0,#RAM_ADDR ; Addr of decimal data
MOV R1,#ASCI_RSULT ; Addr of ASCII data
MOV R2,#4 ; Count
BACK: MOV A,@R0 ; Get decimal digit
ORL A,#30H ; Make it an ASCII digit
MOV @R1,A ; Save it
INC R0 ; Next digit
INC R1 ; Next
DJNZ R2,BACK ; Repeat until last one
;*********
;-Display-
;*********
DISPLAY: MOV A,52H ; Move data in 52H to Accumulator
ACALL PRINT ; Call subroutine "PRINT"
MOV A,51H ; Move data in 51H to Accumulator
ACALL PRINT ; Call subroutine "PRINT"
MOV A,50H ; Move data in 50H to Accumulator
ACALL PRINT ; Call subroutine "PRINT"
MOV A,#' '
ACALL PRINT ; Call subroutine "PRINT"
MOV A,#'B' ; Move "B" to Accumulator
ACALL PRINT ; Call subroutine "PRINT"
MOV A,#'P' ; Move "P" to Accumulator
ACALL PRINT ; Call subroutine "PRINT"
MOV A,#'M' ; Move "M" to Accumulator
ACALL PRINT ; Call subroutine "PRINT"
;******
;-Loop-
;******
LOOP: ACALL DELAY1 ; Call subroutine "DELAY1"
LJMP CLEAR_LCD ; Program will loop back to "CLEAR_LCD"
;*******
;-Print-
;*******
PRINT: CLR EN ; PRINT
SETB RS ; *************************
CLR RW
MOV DAT,A
SETB EN ; Print out data onto LCD
ACALL DELAY
CLR EN
ACALL DELAY ; *************************
RET
;**********************
;-External Interrupt 0-
;**********************
EX_INT0: DJNZ START_TIMER,COUNT ; Start timer 0 only once
SETB TR0 ; Start Timer 0
COUNT: DEC R7 ; Count number of pulses
MOV VALUE_LOW,RCAP2L
MOV VALUE_HIGH,RCAP2H
RETI
;***********************
;-Timer 2 Overflow Flag-
;***********************
T2_INT: INC OVERFLOW_COUNTER ; Count number of overflows
MOV TH2,#HIGH TIMER_0 ; Reloads Timer 0 with High Byte
MOV TL2,#LOW TIMER_0 ; Reloads Timer 0 with Low Byte
RETI
;*************
;-Delay Loops-
;*************
DELAY: MOV R1,#004H
D1: MOV R2,#0FFH
D2: DJNZ R2,D2
DJNZ R1,D1
RET
DELAY1: MOV R4,#0AH
D4: MOV R5,#0FFH
D5: MOV R6,#0FFH
D6: DJNZ R6,D6
DJNZ R5,D5
DJNZ R4,D4
RET
END ; End of Program
SETB T2CON.1 ; Capture on high to low transiton on T2EX
MOV A,CKCON ; Move CKCON to Accumualtor
CLR ACC.3 ; Set system clock to divided by 12
MOV OVERFLOW_COUNTER,#00 ; Move 0 to R7
SETB CT2 ; Timer function
SETB T2CON.1 ; Capture on high to low transiton on T2EX
;**********************
;-Wait Until 4th Pulse-
;**********************
WAIT: CJNE R7,#00H,WAIT ; Wait for 4th pulses
CLR TR2 ; Stop Timer 0
EndlessLoop:
call ReadKeyPad ;Always check for user input
jnb MathDone, NoMath
clr MathDone
call DoMath
call DisplayResult
NoMath:
jnb JobABC,NoABC
clr JobABC
call JobABCCode
NoABC:
jmp EndlessLoop
Since you don't reload the acc in CKCON this has no effect on itS.K said:I see... Well, the meaning of :
Code:MOV A,CKCON ; Move CKCON to Accumualtor CLR ACC.3
is to make sure that my osc is divided by 12 as i did not want the osc to run too fast...
I know what the "Wait" loop is for but holding up the µC isn't good practiceS.K said:The "WAIT" loop is to wait until the 4th pulse and stop the timer...
S.K
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?