本帖最后由 yuzhexian 于 2014-10-16 19:43 编辑
streetkid 发表于 2014-10-16 11:44
没做过这个,不是很理解,以下仅供参考. 首先通过你的描述,我个人的理解是,20个面是用来确定一个物体的位置 ...
对的,20个凹面反射的信号是判断物体相对位置的,棱镜前面装30度角照相镜头,物体是热的,发射的红外光投射到20个凹面镜上,再投射到一个光敏器件上,产生va信号,这样va信号与tg信号的相位差就能反映出物体的位置变化,由于物体的运动速度比较快,电机的速度跟不上,系统要求周期不能大于5ms,所以做20个面,提高va的频率,每一转来20个va信号,但基准tg每一圈只有一个(如果也做20个,跟va的误差会很大),所以对tg 20倍频,我贴的时序图是tg倍频以后的,我把程序贴出来,忘指教,int0就是我说的va信号
int1接tg信号,周期2.109ms,tg总是超前va的,这有硬件决定
org 0000h
ljmp main
org 0013h ;外部中断INT1
ljmp start
org 001bh
ljmp time ;定时中断T1
org 0100h
time_hreg equ 30h
time_lreg equ 31h
da_hreg equ 32h
da_lreg equ 33h
temp_hreg equ 34h
temp_lreg equ 35h
temp1_hreg equ 36h
temp1_lreg equ 37h
time_hcopy equ 38h
time_lcopy equ 39h
csd bit P3.7 ;P2.4 ;ADS7611的I/O
clk0 bit P1.2 ;P2.5
sdi bit P1.3 ;P2.6
ld bit P1.4 ;P2.7
csx bit P3.1 ;P2.3;P2.3 X25045的I/O
so bit P3.0 ;P2.2
si bit P3.4 ;P2.0
sck bit P3.5 ;P2.1
rise bit P1.7 ;in signal is h,or down
sethigh bit P1.6 ;in signal is h
y_n bit P1.5 ;out y/n metal
main: mov sp,#5fh
setb y_n
mov ie,#8ch ;允许中断INT1 T1
mov tmod,#19h ;T1由TR1启动16位定时,T0由TR0+INT0启动16位定时
mov th1,#0f7h
mov tl1,#0c3h
setb it1 ;外部INT1为边沿触发方式(下降沿)
mov th0,#00h
mov tl0,#00h
setb tr0
lcall ini45
;mov ie,#87h
;setb ea
setb sethigh
jb sethigh,w1
mov time_hreg,#00h
mov time_lreg,#00h
ljmp loop
w1: mov time_hreg,#08h
mov time_lreg,#3ch
loop:lcall comp
cpl csx
clr c
mov a,time_lcopy
mov temp1_lreg,a
mov a,time_hcopy
mov temp1_hreg,a
setb rise
jb rise,up
clr c
mov a,#3ch
subb a,temp1_lreg
mov temp_lreg,a
mov a,#08h
subb a,temp1_hreg
mov temp_hreg,a
mov a,temp_hreg
swap a
anl a,#11110000b
mov temp_hreg,a
mov a,temp_lreg
swap a
anl a,#00001111b
add a,temp_hreg
mov da_hreg,a
mov a,temp_lreg
swap a
anl a,#11110000b
mov da_lreg,a
lcall da76
ljmp loop
up: mov temp_hreg,temp1_hreg
mov temp_lreg,temp1_lreg
mov a,temp_hreg
swap a
anl a,#11110000b
mov temp_hreg,a
mov a,temp_lreg
swap a
anl a,#00001111b
add a,temp_hreg
mov da_hreg,a
mov a,temp_lreg
swap a
anl a,#11110000b
mov da_lreg,a
lcall da76
ljmp loop
ini45: clr sck
clr csx
mov a,#06h
lcall out
setb csx
clr csx
mov a,#01h
lcall out
mov a,#00h
lcall out
clr sck
setb csx
ret
out: clr sck;将A输出至X25045
rlc a
mov si,c
setb sck
clr sck
rlc a
mov si,c
setb sck
clr sck
rlc a
mov si,c
setb sck
clr sck
rlc a
mov si,c
setb sck
clr sck
rlc a
mov si,c
setb sck
clr sck
rlc a
mov si,c
setb sck
clr sck
rlc a
mov si,c
setb sck
clr sck
rlc a
mov si,c
setb sck
clr si
ret
da76:clr sdi
setb clk0
setb csd
clr ld
nop
nop
setb ld
nop
clr csd
mov a,da_hreg
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;1
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;2
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;3
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;4
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;5
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;6
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;7
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;8
;DA7611_VALUE送入DAC7611高八位
mov a,da_lreg
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;1
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;2
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;3
clr clk0
rlc a
mov sdi,c
nop
setb clk0 ;4
nop
setb csd
clr ld
nop
setb ld
ret
start:push acc
push psw
mov th1,#0f7h
mov tl1,#0c3h
setb tr1
pop psw
pop acc
reti
time:push acc
push psw
clr tr0
mov time_hreg,th0
mov time_lreg,tl0
mov th0,#00h
mov tl0,#00h
setb tr0
pop psw
pop acc
reti
x2_y:clr y_n
mov time_hcopy,time_hreg
mov time_lcopy,time_lreg
ret
comp:mov a,time_hreg
cjne a,#08h,x1
ljmp x2
x1: jc x2_y;no object
ljmp comp_end
x2: mov a,time_lreg
cjne a,#3ch,x3
ljmp x2_y
x3: jc x2_y
comp_end: setb y_n
setb sethigh
jb sethigh,ww1
mov time_hcopy,#00h
mov time_lcopy,#00h
ret
ww1:mov time_hcopy,#08h
mov time_lcopy,#3ch
ret
end
|