Projeto
Fresadora CNCManual parte Eletrônica Completa
http://eufacoemcasa.blogspot.com
porMaurícioHilstEu Faço em Casa...
N° 217 de Dezembro de 2008 - CORREÇÃO (13/09/2008 Inicial)
Fresadora CNC - Manual parte Eletrônica Completa
Os circuitos aqui descritos são destinados ao acionamento de motores de passo específicos para o projeto, caso queira utilizar outros modelos de motores leia o documento �Motor de Passo & Calculo de Driver (eufacoemcasa.blogspot.com).pdf� também disponivel neste blog.
O código utilizado no PIC 16F84A para este projeto está disponivel textualmente nas últimas paginas deste documento e também neste blog.
Seja coerente quanto a escolha da fonte de alimentação para que não haja falta de corrente para o acionamento dos motores e periféricos. Utilize uma fonte AT ou ATX adaptada para esse funcionamento (para que ela ligue desconectada da placa mãe).
COGD
RRIIO
INRO
3
VESÃ DB6
; File STEP.ASM ---> version 2; ... for PIC16F84 microcontroller; Program to use F84 as a step and direction controller for a unipolar; step motor. Step and direction pins are RA0, RA1; RA2, RA3; RB0-3 and RB4-7 are the windings; in order (driven by NPN small sig transistors or MOSFETS); Steps on negative going edge of step pulse.
; CPU configuration; (It's a 16F84, RC oscillator,; watchdog timer off, power-up timer on)
processor 16f84include <p16f84.inc>__config _RC_OSC & _WDT_OFF & _PWRTE_ON
; Declare variables
pattAequ H'0D' ;Current step pattern number (0-7) for axis AlastAequ H'0E' ;Last state of step pin on axis A (1 is high, 0 is low)pattBequ H'0F' ;Current step pattern number (0-7) for axis BlastBequ H'10' ;Last state of step pin on axis B (1 is high, 0 is low)inportequ H'11' ;Value of port A when read (stored for later access)tempequ H'12'
; Program
org 0 ; start at address 0
;***************************************************;; START OF PIC 16F84 CODE FOR STEP;;;***************************************************;
;------------------------------------------;****Power on reset startpoint;------------------------------------------
;***Initialization of program
; Set port B as output and port A as input (except bit 4)
movlwB'00001111'tris PORTAmovlwB'00000000'tris PORTB
;Clear ports and zero motors
clrfPORTAmovlwB'00010001'movwfPORTBclrflastAclrflastBclrfpattAclrfpattB
;Loop around for a while to let everything stabilize
movlwd'255'movwfinport
loop: decfszinport, f; goto loop
;***Basic program loop
;Main routine - check pin states and step on negative edge;Get port data and store, then check axis A;A10 checks if old is 0, new is 1 (update register);A01 checks if old is 1, new is 0 (step and update register);Similarly for axis B
main: movfPORTA, wmovwfinport
A10: btfsclastA, 0goto A01btfssinport, 2goto A01bsf lastA, 0
A01: btfsslastA, 0goto B10btfscinport, 2goto B10bcf lastA, 0call stepA
B10: btfsclastB, 0goto B01btfssinport, 0goto B01bsf lastB, 0
B01: btfsslastB, 0goto mainbtfscinport, 0goto mainbcf lastB, 0call stepBgoto main
;------------------------------------------;***stepA - sub to cycle axis A one half step; improve this later to read RA4 and choose full/halfsteps as appropriate; Dir of 1 is increase, else decrease
stepA:btfssinport, 3decfpattA, fbtfscinport, 3incf pattA, f
;Peter Homann's optimization for add/subtract mod 7
movlw D'07' andwf pattA, f
;Get step pattern and send to port B on bits 0-3
movfPORTB, wandlwB'11110000'movwftempmovfpattA, wcall dcodeiorwftemp, wmovwfPORTB
return
;------------------------------------------;***stepB - sub to cycle axis B one half step; improve this later to read RA4 and choose full/halfsteps as appropriate; Dir of 1 is increase, else decrease
stepB: btfssinport, 1decfpattB, fbtfscinport, 1incf pattB, f
;Check for pattern overflow and fix
;Peter Homann's optimization for add/subtract mod 7
movlw D'07' andwf pattB, f
;Get step pattern and send to port B on bits 4-7
movfPORTB, wandlwB'00001111'movwftempswapftemp, fmovfpattB, wcall dcodeiorwftemp, fswapftemp, wmovwfPORTB
return
;------------------------------------------;***stepcode - sub to generate bit pattern for number in w (!!MUST BE 0-7!!); pattern is stored in w register (lower four bits) for half step pattern
dcode: addwfPCL, fretlwB'00000001' ;0retlwB'00000011' ;1retlwB'00000010' ;2retlwB'00000110' ;3retlwB'00000100' ;4retlwB'00001100' ;5retlwB'00001000' ;6retlwB'00001001' ;7
;Mandatory end of program command
end