Stepper motor smart interface for CNC 2 to CNC 2.5 upgrade

 home

 

Stepper motor smart interface schematics. Click picture for details

This smart interface controll the head movment on vertical axe of a CNC machine.
All data graphics are stored into internal eeprom of microcontroller.
For keyboard and display connection I have use the user interface board of a fault Nokia5110 phone.
 


Source code file for stepper motor smart interface

;=======Stepper.ASM=========================01/03/03==V 1.0==
; Upgrade for CNC 2 to CNC 2,5
; A0 bidirectional sense bit
; A1 impulse bit
; A2..A4 keyboard
; B0..B4 lcd
; B5 leduri
; B6 buzzer
; B7 Vcmd
; internal clock
; standard crystal 4MHz, 1us/instruction
; Created by E.D.Eng. Bergthaller Iulian-Alexandru
;------------------------------------------------------------
; configure programmer
list p=16f84;f=inhx8m
#INCLUDE P16F84.INC
_CP_OFF equ H'3FFF' ;code protect off
_PwRTE_ON equ H'3FFF' ;Power on timer on
_wDT_OFF equ H'3FFB' ;watch dog timer off
_XT_OSC equ H'3FFD' ;crystal oscillator
__CONFIG _CP_OFF & _PwRTE_ON & _wDT_OFF & _XT_OSC
;------------------------------------------------------------
; cpu init
count1 equ 0C
count2 equ 0D
count3 equ 0E
count4 equ 0F
afisaj equ 10
dig equ 11
xini equ 12
dig1 equ 14
dig2 equ 15
dig3 equ 16
obn1 equ 17
obn2 equ 18
obn3 equ 19
unt1 equ 1A
unt2 equ 1B
unt3 equ 1C
acu1 equ 1D
acu2 equ 1E
acu3 equ 1F
#DEFINE sens PORTA,0
#DEFINE spik PORTA,1
#DEFINE msus PORTA,2
#DEFINE mjos PORTA,3
#DEFINE okay PORTA,4
#DEFINE dorc PORTB,0
#DEFINE sclk PORTB,1
#DEFINE sdta PORTB,2
#DEFINE enab PORTB,3
#DEFINE rset PORTB,4
#DEFINE ledu PORTB,5
#DEFINE beep PORTB,6
#DEFINE tens PORTB,7
;------------------------------------------------------------
;------------------------------------------------------------
org 0x00
goto init
org 0x04
;************************************************************************
init
bsf STATUS,RP0 ; SET BANK = 1.
movlw B'00000000' ; SET PORTB TO ALL OUTPUT.
movwf TRISB
movlw B'11111100' ; SET PORTA TO INPUT/OUTPUT.
movwf TRISA
bcf STATUS,RP0 ; SET BANK = 0.
bcf sens
bcf spik
clrf dig1 ;digit ini
clrf dig2
clrf dig3
clrf obn1
clrf obn2
clrf obn3
clrf unt1
clrf unt2
clrf unt3
clrf acu1
clrf acu2
clrf acu3
;************************************************************************
;* LCD Display ini *
;************************************************************************
bsf dorc
bsf ledu
bsf enab
bsf tens ;lcd logic voltage on
call lcres ;reset for 250 ms
movlw 0x21 ;extended set command
call lccmd
movlw 0xC5 ;Vop
call lccmd
movlw 0x13 ;bias loop
call lccmd
movlw 0x22 ;vertical mode and normal set command
call lccmd
movlw 0x09 ;mod control all dots on
call lccmd
call cbild ;erase lcd
call pause
movlw 0x0C ;mod control normal
call lccmd
movlw 0x80 ;x ini
movwf xini
call lccmd
;************************************************************************
;* Start Graphic on LCD *
;************************************************************************
movlw 0x04
movwf count3
movlw B'00110010'
movwf EEADR
vlop call lin1
call gout
incf EEADR,F
call lin3
call gout
incf EEADR,F
call lin5
call gout
incf EEADR,F
call xinc
decfsz count3,F
goto vlop
;************************************************************************
;* mirror image (eeprom memory too small) *
;************************************************************************
movlw 0x03
movwf count3
movlw B'00111000'
movwf EEADR
mirr call lin1 ;line 1
call gout
incf EEADR,F
call lin3 ;line 3
call gout
incf EEADR,F
call lin5 ;line 5
call gout
movlw 0x05 ;address decrement with 5 for mirror
subwf EEADR,F
call xinc
decfsz count3,F
goto mirr
;************************************************************************
movlw 0x9D ; coloana 29
call lccmd
call lin1
call pct
call lin3
call pct
call lin5
call pct
;************************************************************************
movlw 0x20 ;horizontal mode
call lccmd
;************************************************************************
;* parcare bostan la nivel superior - calibration *
;************************************************************************
call calib
call buzz
;************************************************************************
;* manual calibration to stuff surface *
;************************************************************************
clrf dig1
clrf dig2
clrf dig3
nou call lin3
call invs
movf acu1,W
movwf dig1
movf acu2,W
movwf dig2
movf acu3,W
movwf dig3
call lcout
call gndrf
movf dig1,W
movwf acu1
movf dig2,W
movwf acu2
movf dig3,W
movwf acu3
;************************************************************************
;* setarea adancimii de prelucrare - down position calibration *
;************************************************************************
call lin5
call invs
movf unt1,W
movwf dig1
movf unt2,W
movwf dig2
movf unt3,W
movwf dig3
call lcout
call scan
movf dig1,W
movwf unt1
movf dig2,W
movwf unt2
movf dig3,W
movwf unt3
clrf dig1
clrf dig2
clrf dig3
;************************************************************************
;* setarea pozitiei de baza - base position calibration *
;************************************************************************
call lin1
call invs
movf obn1,W
movwf dig1
movf obn2,W
movwf dig2
movf obn3,W
movwf dig3
call lcout
call scan
movf dig1,W
movwf obn1
movf dig2,W
movwf obn2
movf dig3,W
movwf obn3
;************************************************************************
; asteapta comanda de la CNC - wait command from CNC (simulation) *
;************************************************************************
; bsf STATUS,RP0 ; SET BANK = 1.
; movlw B'11111101' ; SET PORTA TO INPUT ON SENSE
; movwf TRISA
; bcf STATUS,RP0 ; SET BANK = 0.
call caps
call pause
movf unt1,W
movwf dig1
movf unt2,W
movwf dig2
movf unt3,W
movwf dig3
call capj
goto nou
;************************************************************************
caps movf dig1,F ; zero bit test if dig1=dig1=0
btfss STATUS,2
goto niv1
movf dig2,F ; zero bit test if dig2=dig2=0
btfss STATUS,2
goto niv1
movf dig3,F ; zero bit test if dig3=dig3=0
btfsc STATUS,2
goto niv2
niv1 call lcjos
call lin1
call lcout
call dsus
goto caps
niv2 retlw 00
;************************************************************************
capj movf dig1,F ; zero bit test if dig1=dig1=0
btfss STATUS,2
goto lev1
movf dig2,F ; zero bit test if dig2=dig2=0
btfss STATUS,2
goto lev1
movf dig3,F ; zero bit test if dig3=dig3=0
btfsc STATUS,2
goto lev2
lev1 call lcjos
call lin5
call lcout
call djos
goto capj
lev2 retlw 00
;************************************************************************
;* Knopf initialisierungen - Head ini *
;************************************************************************
calib movlw 0x04
movwf count4
lo1 movlw 0xC8
movwf count2
lo2 call dsus
decfsz count2,F ; decrement and skip next line if zero
goto lo2 ; if not zero
decfsz count4,F ; decrement count1 if count2 is zero
goto lo1 ; do inside loop again if count1 nz
retlw 00
;************************************************************************
dsus bcf sens
call puls
retlw 00
;************************************************************************
djos bsf sens
call puls
retlw 00
;************************************************************************
puls movlw 0x14
movwf count3
tren bsf spik
call stepp
bcf spik
call stepp
decfsz count3,F ; decrement and skip next line if zero
goto tren ; if not zero
retlw 00
;************************************************************************
buzz movlw 0x7F
movwf count2
suna bsf beep
call stepp
bcf beep
call stepp
decfsz count2,F ; decrement and skip next line if zero
goto suna ; if not zero
retlw 00
;************************************************************************
;* count up on 3 digits *
;************************************************************************
lcsus incf dig1,F
movlw 0x0A
subwf dig1,W
btfss STATUS,2 ;test zero bit
goto gatas
clrf dig1
incf dig2,F
movlw 0x0A
subwf dig2,W
btfss STATUS,2 ;test zero bit
goto gatas
clrf dig2
incf dig3,F
movlw 0x0A
subwf dig3,W
btfss STATUS,2 ;test zero bit
goto gatas
clrf dig3
gatas retlw 00
;************************************************************************
;* count down on 3 digits *
;************************************************************************
lcjos decf dig1,F
movlw 0xFF
subwf dig1,W
btfss STATUS,2 ;test zero bit
goto gataj
movlw 0x09
movwf dig1
decf dig2,F
movlw 0xFF
subwf dig2,W
btfss STATUS,2 ;test zero bit
goto gataj
movlw 0x09
movwf dig2
decf dig3,F
movlw 0xFF
subwf dig3,W
btfss STATUS,2 ;test zero bit
goto gataj
movlw 0x09
movwf dig3
gataj retlw 00
;************************************************************************
invs movlw 0x9D ; coloana 29
call lccmd
movlw 0xC6 ; doua puncte - two dots
call lcdta
retlw 00
;************************************************************************
norm movlw 0x9D ; coloana 29
call lccmd
call pct ; un punct - one dot
retlw 00
;************************************************************************
pct movlw 0xC0 ; punct
call lcdta
retlw 00
;************************************************************************
lin1 movlw 0x40 ; linia 1
call lccmd
retlw 00
;************************************************************************
lin3 movlw 0x42 ; linia 3
call lccmd
retlw 00
;************************************************************************
lin5 movlw 0x44 ; linia 5
call lccmd
retlw 00
;************************************************************************
;* eeprom read and display *
;************************************************************************
gout call EEPROMREAD
call lcdta
retlw 00
;************************************************************************
;* increment x axe when vertical mode it is used *
;************************************************************************
xinc incf xini,F
movf xini,W
call lccmd
retlw 00
;************************************************************************
;* lcd out for 3 digits *
;************************************************************************
lcout movlw 0xA0 ; coloana 32
movwf xini
call lccmd
movf dig1,W
movwf dig ; dig=dig1
call mux
movlw 0x97 ; coloana 23
movwf xini
call lccmd
movf dig2,W
movwf dig ; dig=dig2
call mux
movlw 0x91 ; coloana 17
movwf xini
call lccmd
movf dig3,W
movwf dig ; dig=dig3
call mux
retlw 00
;************************************************************************
;* display one digit,read the data from eeprom and calculate address *
;************************************************************************
mux movlw 0x00
movwf EEADR
movlw 0x05
movwf count2 ;cinci coloane pe cifra - five bytes for a digit
;************************************************************************
;* obtine adresa eeprom pt. cifra - give eeprom address for a digit *
;************************************************************************
movf dig,F ; zero bit test if dig=dig=0
btfss STATUS,2
goto adlcd
movlw 0x00
movwf EEADR
goto cmlc
adlcd movlw 0x00
adun addlw 0x05
decfsz dig,F
goto adun
movwf EEADR ; now eeadr contains the address for the digit
;************************************************************************
;* display digit byte by byte *
;************************************************************************
cmlc call gout
incf EEADR,F
call xinc
decfsz count2,F
goto cmlc
retlw 00
;************************************************************************
;* gndrf scaneaza taste, comanda motor si afiseaza - keyboard scan *
;************************************************************************
gndrf bsf ledu
town0 btfsc mjos
goto town1
call buzz
call dsus
call lcjos
call lcout
town1 btfsc msus
goto town2
call buzz
call djos
call lcsus
call lcout
town2 btfsc okay
goto town0
call buzz
call norm
bcf ledu
call pause
retlw 00
;************************************************************************
;* gndrf scaneaza taste si afiseaza - keyboard scan and display *
;************************************************************************
scan bsf ledu
down0 btfsc mjos
goto down1
call buzz
call lcjos
call lcout
down1 btfsc msus
goto down2
call buzz
call lcsus
call lcout
down2 btfsc okay
goto down0
call buzz
call norm
bcf ledu
call pause
retlw 00
;************************************************************************
;************************************************************************
lcdta bsf dorc ; lcd data
bcf enab ; lcd enable
call varsa
bsf enab
retlw 00
;************************************************************************
lccmd bcf dorc ; lcd command
bcf enab ; lcd enable
call varsa
bsf enab
retlw 00
;************************************************************************
lcres bcf rset ;reset
call pause
bsf rset ;dezactivare reset
retlw 00
;************************************************************************
;* seriall communication to lcd *
;************************************************************************
varsa movwf afisaj
movlw 0x08
movwf count4
vbit bcf sclk
btfsc afisaj,7 ;bit0
bsf sdta
btfss afisaj,7
bcf sdta
nop
nop
nop
bsf sclk
nop
nop
nop
rlf afisaj,1
decfsz count4,F
goto vbit
retlw 00
;************************************************************************
;* erase lcd *
;************************************************************************
cbild bcf sdta ; data it is null for clearing
movlw 0x06 ; 6 lines
movwf count3
c3 movlw 0x54 ; 84 coloane
movwf count1
c1 movlw 0x08 ; one bytes it is send with 8 clock pulse
movwf count2
bsf dorc
bcf enab
c2 bcf sclk
nop
nop
bsf sclk
decfsz count2,F
goto c2
bsf enab
decfsz count1,F
goto c1
decfsz count3,F
goto c3
retlw 00
;************************************************************************
; Citire eeprom de la adresa eeadr - eeprom read subroutine *
;************************************************************************
EEPROMREAD
BSF STATUS,5 ; SET TO BANK 1
BSF EECON1,00 ; INITIATES AN EEPROM READ
BCF STATUS,5 ; SET TO BANK 0
MOVF EEDATA,W ; TRANSFER EEDATA DIN EEPROM IN ACCU
RETURN
;************************************************************************
;* Durata puls pas motor - stepp time *
;************************************************************************
stepp movlw 0x7F
movwf count1
pas1 decfsz count1,F ; decrement and skip next line if zero
goto pas1 ; if not zero
retlw 00
;************************************************************************
pause movlw 0x07
movwf count3
d3 movlw 0x32
movwf count1
d1 movlw 0xFA
movwf count2
d2 decfsz count2,F
goto d2
decfsz count1,F
goto d1
decfsz count3,F
goto d3
retlw 00
;************************************************************************
;* adrese cifre intre 2100 si 2131 inclusiv - no. address and data *
;************************************************************************
ORG 0x2100
de 0x7C,0xA2,0x92,0x8A,0x7C,0x00,0x84,0xFE,0x80,0x00
de 0x84,0xC2,0xA2,0x92,0x8C,0x42,0x82,0x8A,0x96,0x62
de 0x30,0x28,0x24,0xFE,0x20,0x4E,0x8A,0x8A,0x8A,0x72
de 0x78,0x94,0x92,0x92,0x60,0x02,0xE2,0x12,0x0A,0x06
de 0x6C,0x92,0x92,0x92,0x6C,0x0C,0x92,0x92,0x52,0x3C
;************************************************************************
;* adrese grafica intre 2132 si 213D inclusiv - arrow and home data *
;************************************************************************
de 0x08,0xF9,0x10,0x0C,0x8A,0x30
de 0xFE,0x8C,0x7F,0xFF,0x88,0xFF
;************************************************************************
end
;============================================================

Just some stepper motor smart interface photos. Click picture for details


Back to my home page
Last updated April, 2003
Copyright 2003 Bergthaller Iulian-Alexandru

 

eXTReMe Tracker