6-2 步进电动机实现两轴联动直线运动程序

更新时间:2023-05-26 15:44:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

电动机,dsPIC,自动控制,程序

《步进电动机实现两轴联动直线运动程序》

.equ __30F6010, 1

.include "C:\Program Files\Microchip\MPLAB ASM30 Suite\Support\inc\p30f6010.inc" .global __reset

.global __OC7Interrupt

.global __OC8Interrupt

config __FOSC, CSW_FSCM_OFF & XT_PLL4

config __FWDT, WDT_OFF

config __FBORPOR, PBOR_ON & BORV_27 & PWRT_16 & MCLR_EN

config __FGS, CODE_PROT_OFF

.bss

XAL: .space 2

XBL: .space 2

YAL: .space 2

YBL: .space 2

XAH: .space 2

XBH: .space 2

YAH: .space 2

YBH: .space 2

tL: .space 2

tH: .space 2 ;

K: .space 2

dXL: .space 2

dYL: .space 2

dXH: .space 2

dYH: .space 2

Tx: .space 2

Ty: .space 2

DIR: .space 2

NXL: .space 2

NXH: .space 2

NYL: .space 2

NYH: .space 2

Testx: .space 2

Testy: .space 2

.text

__reset:

mov #__SP_init, W15

mov #__SPLIM_init, W0

mov W0, SPLIM

nop

clr W0

mov W0, W14

repeat #12

电动机,dsPIC,自动控制,程序

mov W0, [++W14]

clr W14 MOV #0x0001, w0

MOV w0, OC7CON BSET OC7CON, #1 MOV #0x0009, w0

MOV w0, OC8CON BSET OC8CON, #1 Mov #0xFFFC,w0

Mov w0,TRISG Mov #0x5544,w0

Mov w0,IPC8 Clr IFS2 Clr Testx Clr Testy

Bset SR,#C

Mov XBL,W2 Mov XAL,W0

Sub w2,w0,w6 Mov XBH,w2

Mov XAH,w0

Subb w2,w0,w5

Bra n,TB1

Bra z,TB5

bclr DIR,#0

Goto TB2

TB1:

Bset DIR,#0

Mov w6,ACCAL Mov w5,ACCAH

Clr ACCAU

Neg A

Mov ACCAL,w6

Mov ACCAH,w5

TB2:

Mov w6,ACCAL Mov w5,ACCAH

Clr ACCAU

Sftac A,#2

Mov ACCAL, w6

Mov ACCAH, w5

Mov w6, NXL

Mov w5, NXH

Sftac A,#2

电动机,dsPIC,自动控制,程序

Mov ACCAL, w0 Mov #68,w1

Mul.uu w0,w1,w2 Clr w4 Clr w5

Ff1l w3,w4 Bra nc,TB3 Ff1l w2,w5 Bra c,TB5 Mov #-16, w4

Subr w5,#1,w5 Mov w2,ACCAL Mov w3,ACCAH Clr ACCAU

Sftac A,w4 Sftac A,w5 Mov ACCAH,w6 Mov tL,w2 Mov tH,w3

Repeat #17

div.ud w2,w6 mov w0,ACCAL clr ACCAH

sftac A,w4

sftac A,w5

Goto TB4

TB3:

Subr w4,#1,w4 Mov w2,ACCAL Mov w3,ACCAH Clr ACCAU

Sftac A,w4 Mov ACCAH,w6 Mov tL,w2 Mov tH,w3

Repeat #17

div.ud w2,w6 mov w0,ACCAL clr ACCAH

sftac A,w4

TB4:

Mov ACCAH,w0 mov w0,Tx goto TB6

电动机,dsPIC,自动控制,程序

TB5:

Clr Tx

Clr NXL Clr NXH

TB6:

Bset SR,#C

Mov YBL,W2

Mov YAL,W0

Sub w2,w0,w6 Mov YBH,w2

Mov YAH,w0

Subb w2,w0,w5 Bra n,TB7 Bra z,TB11

bclr DIR,#1 Goto TB8

TB7:

Bset DIR,#1 Mov w6,ACCAL Mov w5,ACCAH Clr ACCAU

Neg A Mov ACCAL,w6 Mov ACCAH,w5 TB8:

Mov w6,ACCAL Mov w5,ACCAH Clr ACCAU

Sftac A,#2 Mov ACCAL, w6 Mov ACCAH, w5 Mov w6, NYL Mov w5, NYH

Sftac A,#2 Mov ACCAL, w0 Mov #68,w1

Mul.uu w0,w1,w2 Clr w4 Clr w5

Ff1l w3,w4 Bra nc,TB9 Ff1l w2,w5 Bra c,TB11 Mov #-16, w4

电动机,dsPIC,自动控制,程序

Subr w5,#1,w5 Mov w2,ACCAL Mov w3,ACCAH Clr ACCAU

Sftac A,w4 Sftac A,w5 Mov ACCAH,w6 Mov tL,w2 Mov tH,w3

Repeat #17

div.ud w2,w6 mov w0,ACCAL clr ACCAH

sftac A,w4

sftac A,w5

Goto TB10

TB9:

Subr w4,#1,w4 Mov w2,ACCAL Mov w3,ACCAH Clr ACCAU

Sftac A,w4 Mov ACCAH,w6 Mov tL,w2 Mov tH,w3

Repeat #17

div.ud w2,w6 mov w0,ACCAL clr ACCAH

sftac A,w4

TB10:

Mov ACCAH,w0 mov w0,Ty goto TB12

TB11:

Clr Ty Clr NYL Clr NYH TB12:

MOV Tx, w0 MOV w0, OC7R

Mov w0,PR2 MOV Ty, w0 MOV w0, OC8R

电动机,dsPIC,自动控制,程序

Mov w0,PR3 Mov DIR,w0

Mov w0,PORTG BSET T2CON, #TON BSET T3CON, #TON Bset IEC2,#OC7IE Bset IEC2,#OC8IE abc:

Goto abc __OC7Interrupt: Push.s Push w0

Inc Testx

Btsc Testx,#0

Goto H2

Dec NXL BRA C,H1

DEC NXH

H1:

Mov NXL,w0

Ior NXH,wreg Bra NZ,H2 Bclr T2CON, #TON H2:

Bclr IFS2,#OC7IF Pop w0

Pop.s Retfie

__OC8Interrupt: Push.s Push w0

Inc Testy

Btsc Testy,#0

Goto H4

Dec NYL BRA C,H3

DEC NYH

H3:

Mov NYL,w0

Ior NYH,wreg Bra NZ,H4 Bclr T3CON, #TON H4:

电动机,dsPIC,自动控制,程序

Bclr IFS2,#OC8IF Pop w0 Pop.s Retfie

.end

本文来源:https://www.bwwdw.com/article/fvo4.html

Top