Nigel Goodwin said:Perhaps you might try mentioning the processor you're using? - if it was a PIC (which it isn't) the PICList has plenty of details.
You dont have to use the CJNE instruction at all. You can do a subtraction and check the carry flag, which for subtraction is actually a borrow. the following instruction set reference from Atmel has examples in it for this kind of stuff.AceOfHearts said:Appologies, it is an 8051.
Many thanks.
How are you measuring pulse duration? Show your complete code because without that it is difficult to pin-point whats going wrong in it.AceOfHearts said:Many thanks.
I am actually programming an 8051 for an ultrasonic rangefinder (SRF05) and trying to use this method to ascertain if the signal from the device has been on for a certain period of time (the length of this signal tells us the range).
Basically above a certain time period, object is out of range. And when within this time period, it is within range.
So far, I have not got it to work as I want!
Did you read this one: **broken link removed**AceOfHearts said:Many thanks.
I am actually programming an 8051 for an ultrasonic rangefinder (SRF05) and trying to use this method to ascertain if the signal from the device has been on for a certain period of time (the length of this signal tells us the range).
Basically above a certain time period, object is out of range. And when within this time period, it is within range.
So far, I have not got it to work as I want!
;P1.0 = object detected, P1.1 no object detected P0.0 connected to the trigger pin of SRF05. Echo
;line reponse appears 700uS after the end of trigger pulse
AGAIN: MOV A, #0
MOV P0, A ;output port
SETB P0.0
ACAll DELAY_TWENTY
CLR P0.0 ;Trigger
MOV A, #0FFH
MOV P0, A ;input port
STAY: JNB P0.0, STAY
ACALL MONITOR
ACALL DELAY_FIFTY
SJMP AGAIN
;================================================
;=========DELAY_TWENTY=================================
DELAY_TWENTY: MOV TMOD, #01 ;(1)
MOV TL0, #0F1H ;(1) ;Will count up 14D, TOT 20
MOV TH0, #0FFH ;(1)
SETB TR0 ;(1)
AGAIN1: JNB TF0, AGAIN1
CLR TR0 ;(1)
CLR TF0 ;(1)
RET
;==============================================================
;======DELAY_FIFTY============================
DELAY_FIFTY: MOV TMOD, #01 ;(1)
MOV R5, #7
FIRE: MOV TL0, #0
MOV TH0, #0
SETB TR0 ;(1)
AGAIN2: JNB TF0, AGAIN2
CLR TR0 ;(1)
CLR TF0 ;(1)
DJNZ R5, FIRE
RET
;#0FCH ;(1)
;#04BH ;(1)
;============================================================
;=================Monitor=================
MONITOR: CLR C ;clear carry
MOV TMOD, #01 ;(1)
MOV TL0, #0H
MOV TH0, #0H
MOV A, #100 ;(1)
SETB TR0
REMAIN1: JB P0.0, REMAIN ;(1)
SETB P1.0
CLR P1.1
SJMP FINISH
REMAIN: MOV R5, TL0 ;(1)
;CJNE A, #32H, REMAIN1 ;(2)
NOP ;(1)
NOP ;(1)
SUBB A, R5 ;(1)
JNC REMAIN1 ;(2)
SETB P1.1
CLR P1.0
FINISH: CLR TR0
CLR TF0
RET
Is this correct?AceOfHearts said:REMAIN1: JB P0.0, REMAIN ;(1)
mcs51mc said:Is this correct?
I think your idea is to stay here as long P0.0 is high so you should jump to "REMAIN1" not "REMAIN".
In the mean time T0 is counting 1ms intervals (if you have a 12MHz xtal).
What happens after that line is complete unclear to me.
According to what I read in the SRF05 spec, you should divide the measured time by 58 to get distance in cm. Where is your division?
Unless you just want to know if the US see something and check for 30ms time-out of the SRF05But even then the sequence is wrong.
Explain your DELAY_FIFTY: routine
orl P0,#00000001b ;P0.0 is input
mov TMOD, #01 ;Prepare T0 to time P0.0
mov TL0, #0
mov TH0, #0
jnb P0.0, $ ;Wait for +edge of echo pulse
setb TR0 ;Echo pulse active, start timer
jb P0.0, $ ;Wait for -edge of echo pulse
clr TR0 ;end of echo pulse is stop timer
mov a,TL0 ;Load LB timed value
clr c
subb a,#29 ;Time out SRF05 is 30ms
jc ObjectDetected
clr P1.0 ;No object: led off
jmp AGAIN
ObjectDetected:
setb P1.0 ;Object: set led on
jmp AGAIN
Timer-0 is a 16 bit timer. It can represent values upto 65535. Modify your code to compare contents of TL0 and TH0. For ex. 27650d = 6C02hAceOfHearts said:Hi there,
thanks for the code...I really appreciate it.
I am going to look at it further to see how I can adapt it to what I need.
But very quickly, the problem I see is that as I am using a crystal of 11.0592MHZ, each cycle is 1.085uS, so for 30ms, I will need 30ms/1.085uS = 27650 cycles which LB of T0 will not represent 2^8=256.
If I take 10mS to be my time out value, then 20mS/1.085uS = 18434 cycles are required...
Thanks again.
Shame on meAceOfHearts said:Hi there,
But very quickly, the problem I see is that as I am using a crystal of 11.0592MHZ, each cycle is 1.085uS, so for 30ms, I will need 30ms/1.085uS = 27650 cycles which LB of T0 will not represent 2^8=256.
;------------------------------------------------------------------------------
; Compare 2 unsigned operands
;
;Inputs: Operand 1 HB = MathLib_Op1+0
; MathLib_Op1+1
; MathLib_Op1+2
; LB = MathLib_Op1+3
;
; Operand 2 HB = MathLib_Op2+0
; MathLib_Op2+1
; MathLib_Op2+2
; LB = MathLib_Op2+3
;
;Output: MathLib_Greater = 1 when Operand 1 > Operand 2
; MathLib_Equal = 1 when Operand 1 = Operand 2
; MathLib_Less = 1 when Operand 1 < Operand 2
;
;
Comp_8_Unsigned: mov MathLib_Op1+1,#0
mov MathLib_Op2+1,#0
Comp_16_Unsigned: mov MathLib_Op1+2,#0
mov MathLib_Op2+2,#0
Comp_24_Unsigned: mov MathLib_Op1+3,#0
mov MathLib_Op2+3,#0
Comp_32_Unsigned:
CompareUnsigned: clr MathLib_Greater
clr MathLib_Equal
clr MathLib_Less
mov a,MathLib_Op1+0 ;Check HB
cjne a,MathLib_Op2+0,Comp_001
mov a,MathLib_Op1+1 ;Check next byte
cjne a,MathLib_Op2+1,Comp_001
mov a,MathLib_Op1+2 ;Check next byte
cjne a,MathLib_Op2+2,Comp_001
mov a,MathLib_Op1+3 ;Check LB
cjne a,MathLib_Op2+3,Comp_001
setb MathLib_Equal
ret
Comp_001: jc Comp_002
setb MathLib_Greater
ret
Comp_002: setb MathLib_Less
ret
Comp_8_Signed: call CheckSigns
jnc Comp_8_Unsigned
ret
Comp_16_Signed: call CheckSigns
jnc Comp_16_Unsigned
ret
Comp_24_Signed: call CheckSigns
jnc Comp_24_Unsigned
ret
Comp_32_Signed: call CheckSigns
jnc Comp_32_Unsigned
ret
CheckSigns: clr MathLib_Greater
clr MathLib_Equal
clr MathLib_Less
mov a,MathLib_Op1+0 ;Check sign Operand 1
rlc a
jc Comp_003 ;Operand 1 Neg
mov a,MathLib_Op2+0 ;Operand 1 Pos; check Operand 2
rlc a
jnc Comp_004 ;Operand 2 Pos
setb MathLib_Greater ;Op 1 is Pos & Op 2 is Neg -> Greater
setb c
ret
Comp_003: mov a,MathLib_Op2+0 ;Operand 1 Neg; check Operand 2
rlc a
jc Comp_004 ;Operand 2 Neg
setb MathLib_Less ;Op 1 is Neg & Op 2 is Pos -> Less
setb c
ret
Comp_004: clr c
ret
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?