uln2803步進電機的控制原理電路圖和源程序 步進電機的控制原理和程序
選自北航出版 耿德根主編《高速嵌入式單片機原理與應用》第七章7.4.2
源程序:SLAVR742.ASM
自從六十年代初期步進電機面世以來,在過去幾年它的重要性大大提高了。它用來驅動時鐘和其他采用指針的儀器,打印機、繪圖儀、磁盤光盤驅動器、各種自動控制閥、各種工具,還有機器人等的機械裝置。關于馬進電機工作原理請參考有關資料。
下面用單極1-2相激磁方法步進電機做實驗,即1極、2極、1極、2極、....極以次循環,如何用單極二相激該方法控制步進電機,由讀者或用戶自行
編制程序實驗。
;實驗選用4.5V步進電機,用5V即可,實驗時節省一組步進電機驅動電源;
;型號:MA82135; 相數:2相; 電壓:4.5V; 電流/相:0.12A; 電阻歐姆:34Ω/相; 重量:30g
;*********************************************
;* 步進電機控制程序(單極1-2相) *
;* *
;*SLAVR742.ASM *
;*use ULN2803 ;使用PC0-PC3 驅動步進電機 *
;*use 11-17new bord *
;*********************************************
.include"8515def.inc"
.def temp =r16
.def dt =r19
.def np =r17
.def step =r18
.def TStep =r20
.def cnt =r21
.equ turntab=0x0200
.org $0000
rjmp RESET
.cseg
.org 0x010
RESET:
ldi temp,low(RAMEND) ;設堆棧
out SPL,temp
ldi temp,high(RAMEND)
out SPL+1,temp
ser TEMP ;C口設置為輸出
OUT ddrc,TEMP
ldi zl,low(turntab*2) ;步進電機旋轉資料指針
ldi zh,high(turntab*2)
ldi np,4
ldi temp,$44
out portc,temp ;初始化
ldi TStep,$25
rcall delay
ldi cnt,10
clt
rep: ldi step,192
ldi TStep,1 ;1--255
rcall turn
dec cnt
brne rep
loop: nop
rjmp loop
;*************************************************************
; t=1 uncircle turn ;T=1逆時針轉 *
; t=0 circle turn ;T=0順時針轉 *
; 96 step a turn *
; TStep is time of a step ; *
;*************************************************************
turn: brts uncircle ;判轉向
inc np ;正轉
cpi np,8
brne next
clr np
next: push zl
add zl,np
lpm
out portc,r0
pop zl
rcall delay
dec step
brne turn
ret
uncircle: ;反轉
dec np
cpi np,$ff
brne next
ldi np,$07
rjmp next
delay: push TStep ;延時子程序
del1: ldi dt,70
del2: push dt
del3: dec dt
brne del3
pop dt
dec dt
brne del2
dec TStep
brne del1
pop TStep
ret
.org turntab
; 0 1 2 3 4 5 6 7 ;步進電機旋轉資料表
.db 0x11,0x99,0x88,0xcc,0x44,0x66,0x22,0x33
評論