;*****************************************
;-----------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 CONFIGURATIONS----------
;**************************************
SETB TCON.2
MOV TMOD,#10H
MOV CKCON,#000H
;**********
;-Start Timer-
;**********
START: MOV 40H,#000H
MOV TH1,#0D0H
MOV TL1,#0A0H ; Program timer to run for 5 seconds
SETB TR1 ; Start timer
WAIT: JNB TF1,WAIT
;****************************
;-Timer 1 Overflow Interrupt-
;****************************
T1_INT: RETI
;**********************
;-External Interrupt 1-
;**********************
EX_INT: INC 40H ; Increment 40H
RETI
MOV IE,#8CH
CLR RS1
CLR RS0
MOV SP,#07H
Main_RAM_Byte segment data
Stack segment data
SEG Main_RAM_Byte
Variable_1: ds 1 ;declare 1 byte in internal RAM
Variable_2: ds 2 ;declare two consecutive bytes in RAM
SEG Stack
ds 10 ;declare 10 bytes for stack
mov sp,#Stack-1 ;initialize stack
mov a,Variable_1
MOV 40H,#000H
Time_0 equ 65535-10000 ;10ms interrupt
mov TH0,#HIGH Time_0 ;load timer value
mov TL0,#LOW Time_0
mov TMOD,#01H ;timer 0 mode 1
setb ET0 ;enable interrupt timer 0
setb EA
setb TR0 ;start timer 0
mov sp,#Stack-1 ;initialize stack
CSEG AT 0000h
jmp StartMain
CSEG AT 000bh
jmp ISR_Timer0
CSEG AT 0023h
jmp ISR_SerialInterrupt
CSEG AT RESET
jmp MainProg
CSEG AT TIMER0
jmp Timer_0
CONFIG: MOV R7,#00H
MOV R3,#04H
MOV TH0,#00H
MOV TL0,#00H
WAIT: CJNE R3,#00H,WAIT
CLR TR0
INT_T1: INC R7 ; Timer 1 ISR
RETI
EX_INT: SETB TR1 ; External ISR
DEC R3
RETI
mcs51mc said:What will the max expected time be and how accurate do you want it?
Time_1 equ 65535-10000 ;10ms interrupt assuming 12MHz xtal
mov TH1,#HIGH Time_1 ;load timer value
mov TL1,#LOW Time_1
mov TMOD,#10H ;timer 1 mode 1
setb ET1 ;enable interrupt timer 1
setb EA
EndlessLoop:
;Do your main code stuff here
jmp EndlessLoop
mov TH1,#HIGH Time_1 ;reload timer value
mov TL1,#LOW Time_1
push acc ;save some registers used in ISR
push psw
inc OverflowConter ;Count number of timer overflows Max 255
;Do other timed stuff here
pop psw ;restore registers used in ISR
pop acc
reti
Hmm...S.K said:About the math routine, I'm still abit blur...
I know the concept, the only problem is to write it in code.
Lets say,
x = 0.39 * R7
y = 1 / x
z = y * 60
Than display z
With your code R7 will increment every 65536µs assuming you have a 12MHz xtal. Is that what you want? I bet not
YepS.K said:I got what you mean, meaning i have to set the value in TH1 and TL1 10ms so that after the 4th pulse, the math routine will be easier to do isn't it?
just use R7 * 10ms...
Time_1 equ 65535-10000 ;10ms interrupt assuming 12MHz xtal
Time_1 equ 65535-2000 ;2ms interrupt assuming 12MHz xtal
because 10ms is a bad choice if you need 1ms accuracy or want to measure several minutes!!mcs51ms said:What will the max expected time be and how accurate do you want it?
Elementary math ...S.K said:Also, how do you get 153.8461???
One thing for sure, it's not about baking cookiesS.K said:Yeah.. been to 8052.com... still trying to figure out what the tutorial is talking about...
Originally Posted by mcs51ms
What will the max expected time be and how accurate do you want it?
Elementary math ...
Z = 60 / (0.39 * R7) Your three formulas in one
Z = 60 / 0.39 * 1 / R7
Z = 153.8461 * 1 / R7
Z = 153.8461 / R7
TIME_0 EQU 65535
MOV TMOD,#01H
SETB EA
SETB ET1
MOV TH0,#HIGH TIME_0
MOV TLO,#LOW TIME_0
1) How many sensors do you have and what are their outputs?
2) Do you mean you digitalized the sensor output and search for the maximum value? Did you use on chip hardware or code to do that?
3) What is the ADC scan rate? How many readings/sec?
Please review the datasheet concerning the timer stuff!S.K said:So the timer code will be:
Am i right? Since i want the timer to run for the whole of 65535 ticks.Code:TIME_0 EQU 65535 MOV TMOD,#01H SETB EA SETB ET1 MOV TH0,#HIGH TIME_0 MOV TLO,#LOW TIME_0
Time_1 equ 65535[b]-10000[/b] ;10ms interrupt assuming 12MHz xtal
Time_1 equ 65535[b]-2000[/b] ;2ms interrupt assuming 12MHz xtal
Like I already said do some evaluations in Excel to determine what is best suited for you application! Use the "Integer" function to calculate the way a µC do, that is without fractional numbers.S.K said:And for the math routine, i need to use 16-bit division? Cause 615 is greater than 255.
Must i need the remainder of the division since i do not need so much accuracy? If i used 2MHz, R7 won't be greater than 0FFH and it will be easier to do the math routine
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?