messu Postat Iunie 3, 2009 Partajează Postat Iunie 3, 2009 Se poate face asa ceva? Din cate am studiat, par "echivalente", insa la microcontrolere joc sub grupa mica.Ce-ar trebui sa schimb, in afara de declarare si configurare, la urmatorul cod, scris pentru F84, ca sa ruleze pe F628 ?File HALFSTEP.ASM; ... 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). RA4 selects full or half-step.; Steps on negative going edge of step pulse.; CPU configuration processor 16f84 include __config _XT_OSC & _WDT_OFF & _PWRTE_ON; Declare variablespattA equ H'0D' ;Current step pattern number (0-7) for axis AlastA equ H'0E' ;Last state of step pin on axis A (1 is high, 0 is low)pattB equ H'0F' ;Current step pattern number (0-7) for axis BlastB equ H'10' ;Last state of step pin on axis B (1 is high, 0 is low)inport equ H'11' ;Value of port A when read (stored for later access)temp equ 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) movlw B'00011111' tris PORTA movlw B'00000000' tris PORTB ;Clear ports and zero motors clrf PORTA movlw B'00010001' movwf PORTB clrf lastA clrf lastB clrf pattA clrf pattB;Loop around for a while to let everything stabilize movlw d'255' movwf inportloop: decfsz inport, 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 Bmain: movf PORTA, w movwf inportA10: btfsc lastA, 0 goto A01 btfss inport, 2 goto A01 bsf lastA, 0A01: btfss lastA, 0 goto B10 btfsc inport, 2 goto B10 bcf lastA, 0 call stepAB10: btfsc lastB, 0 goto B01 btfss inport, 0 goto B01 bsf lastB, 0B01: btfss lastB, 0 goto main btfsc inport, 0 goto main bcf lastB, 0 call stepB goto main;------------------------------------------;***stepA - sub to cycle axis A one half step; Dir of 1 is increase, else decreasestepA: btfss inport, 3 decf pattA, f btfsc inport, 3 incf pattA, f;Check for pattern overflow and fix movf pattA, w sublw D'255' movlw D'07' btfsc STATUS, 2 movwf pattA movf pattA, w sublw D'08' btfsc STATUS, 2 clrf pattA ;Get step pattern and send to port B on bits 0-3 movf PORTB, w andlw B'11110000' movwf temp movf pattA, w btfsc PORTA , 4 call dcode btfss PORTA , 4 call dfcode iorwf temp, w movwf PORTB return;------------------------------------------;***stepB - sub to cycle axis B one half step; Dir of 1 is increase, else decreasestepB: btfss inport, 1 decf pattB, f btfsc inport, 1 incf pattB, f;Check for pattern overflow and fix movf pattB, w sublw D'255' movlw D'07' btfsc STATUS, 2 movwf pattB movf pattB, w sublw D'08' btfsc STATUS, 2 clrf pattB ;Get step pattern and send to port B on bits 4-7 movf PORTB, w andlw B'00001111' movwf temp swapf temp, f movf pattB, w btfsc PORTA , 4 call dcode btfss PORTA , 4 call dfcode iorwf temp, f swapf temp, w movwf PORTB 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 patterndcode: addwf PCL, f retlw B'00000001' ;0 retlw B'00000011' ;1 retlw B'00000010' ;2 retlw B'00000110' ;3 retlw B'00000100' ;4 retlw B'00001100' ;5 retlw B'00001000' ;6 retlw B'00001001' ;7dfcode: addwf PCL, f retlw B'00000001' ;0 retlw B'00000010' ;1 retlw B'00000100' ;2 retlw B'00001000' ;3 retlw B'00000001' ;4 retlw B'00000010' ;5 retlw B'00000100' ;6 retlw B'00001000' ;7;Mandatory end of program command end Link spre comentariu
messu Postat Iunie 9, 2009 Autor Partajează Postat Iunie 9, 2009 N-are nimeni nici o idee ? Sau am intrebat ceva ce nu trebuia intrebat ? Link spre comentariu
ghimpe-- Postat Iunie 9, 2009 Partajează Postat Iunie 9, 2009 Nu ma pricep la pic-uri, dar cred ca te poti inspira de aici. Este codul sursa pentru frecventiometrul de aici Link spre comentariu
Vizitator yo2lio Postat Iunie 9, 2009 Partajează Postat Iunie 9, 2009 processor 16f628include <p16f628.inc>__config _XT_OSC & _WDT_OFF & _PWRTE_ON; Declare variablespattA equ H'20' ;Current step pattern number (0-7) for axis AlastA equ H'21' ;Last state of step pin on axis A (1 is high, 0 is low)pattB equ H'22' ;Current step pattern number (0-7) for axis BlastB equ H'23' ;Last state of step pin on axis B (1 is high, 0 is low)inport equ H'24' ;Value of port A when read (stored for later access)temp equ H'25'; Programorg 0 ; start at address 0;***************************************************;; START OF PIC 16F628 CODE FOR STEP;;;***************************************************;;------------------------------------------;****Power on reset startpoint;------------------------------------------;***Initialization of program; Set port B as output and port A as input (except bit 4)movlw B'00011111'andwf STATUS,f movlw B'00000111'movwf CMCONmovlw B'00011111'tris PORTAmovlw B'00000000'tris PORTB;Clear ports and zero motorsclrf PORTAmovlw B'00010001'movwf PORTBclrf lastAclrf lastBclrf pattAclrf pattB;Loop around for a while to let everything stabilizemovlw d'255'movwf inportloop: decfsz inport, 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 Bmain: movf PORTA, wmovwf inportA10: btfsc lastA, 0goto A01btfss inport, 2goto A01bsf lastA, 0A01: btfss lastA, 0goto B10btfsc inport, 2goto B10bcf lastA, 0call stepAB10: btfsc lastB, 0goto B01btfss inport, 0goto B01bsf lastB, 0B01: btfss lastB, 0goto mainbtfsc inport, 0goto mainbcf lastB, 0call stepBgoto main;------------------------------------------;***stepA - sub to cycle axis A one half step; Dir of 1 is increase, else decreasestepA: btfss inport, 3decf pattA, fbtfsc inport, 3incf pattA, f;Check for pattern overflow and fixmovf pattA, wsublw D'255'movlw D'07'btfsc STATUS, 2movwf pattAmovf pattA, wsublw D'08'btfsc STATUS, 2clrf pattA;Get step pattern and send to port B on bits 0-3movf PORTB, wandlw B'11110000'movwf tempmovf pattA, wbtfsc PORTA , 4call dcodebtfss PORTA , 4call dfcodeiorwf temp, wmovwf PORTBreturn;------------------------------------------;***stepB - sub to cycle axis B one half step; Dir of 1 is increase, else decreasestepB: btfss inport, 1decf pattB, fbtfsc inport, 1incf pattB, f;Check for pattern overflow and fixmovf pattB, wsublw D'255'movlw D'07'btfsc STATUS, 2movwf pattBmovf pattB, wsublw D'08'btfsc STATUS, 2clrf pattB;Get step pattern and send to port B on bits 4-7movf PORTB, wandlw B'00001111'movwf tempswapf temp, fmovf pattB, wbtfsc PORTA , 4call dcodebtfss PORTA , 4call dfcodeiorwf temp, fswapf temp, wmovwf PORTBreturn;------------------------------------------;***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 patterndcode: addwf PCL, fretlw B'00000001' ;0retlw B'00000011' ;1retlw B'00000010' ;2retlw B'00000110' ;3retlw B'00000100' ;4retlw B'00001100' ;5retlw B'00001000' ;6retlw B'00001001' ;7dfcode: addwf PCL, fretlw B'00000001' ;0retlw B'00000010' ;1retlw B'00000100' ;2retlw B'00001000' ;3retlw B'00000001' ;4retlw B'00000010' ;5retlw B'00000100' ;6retlw B'00001000' ;7;Mandatory end of program commandend Link spre comentariu
messu Postat Iunie 9, 2009 Autor Partajează Postat Iunie 9, 2009 Multumesc. Nu prea m-a ajutat, sincer sa fiu. Am modificat codul, dupa cel exemplificat acolo, atat cat m-am priceput insa n-am obtinut nimic. Am avut o multime de erori la compilare. Pana la urma am gasit o referire aici http://www.winpicprog.co.uk/pic_tutorial1.htm care m-a mai deslusit. Compilarea a mers OK. Nici o eroare ! Din pacate la simularea in ISIS nu merge nimic. Ca de obicei, totul e OK,.... dar nu functioneaza nimic:aplauze Incerc ca mai caut explicatii.... Link spre comentariu
messu Postat Iunie 9, 2009 Autor Partajează Postat Iunie 9, 2009 Multumesc yo2lio !Mulutmesc tuturor !E bun codul tau, dar, la compilare, da o lista NESFARSITA de "WARNINGS"Intre timp, desi nu sint foarte convins ce-am facut , l-am "carpit" si eu si, pentru varianta cu oscilator intern de 4Mhz, arata cam asa:; File HALFSTEP.ASM; ... for PIC16F628 microcontroller; Program to use F628 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). RA4 selects full or half-step.; Steps on negative going edge of step pulse. LIST p=16F628 ;tell assembler what chip we are using include "P16F628.inc" ;include the defaults for the chip __config 0x3D18 ;sets the configuration settings ;(oscillator type etc.) org 0x0000 ;org sets the origin, 0x0000 for the 16F628, ;this is where the program starts running movlw 0x07 movwf CMCON ;turn comparators off ; Declare variablespattA equ H'20' ;Current step pattern number (0-7) for axis AlastA equ H'21' ;Last state of step pin on axis A (1 is high, 0 is low)pattB equ H'22' ;Current step pattern number (0-7) for axis BlastB equ H'23' ;Last state of step pin on axis B (1 is high, 0 is low)inport equ H'24' ;Value of port A when read (stored for later access)temp equ H'25'; Program;***************************************************;; START OF PIC 16F628 CODE FOR STEP;;;***************************************************;;------------------------------------------;****Power on reset startpoint;------------------------------------------;***Initialization of program ; Set port B as output and port A as input (except bit 4) bsf STATUS, RP0 ;select bank 1 movlw b'00000000' ;set PortB all outputs movwf TRISB movlw b'00011111' movwf TRISA ;set PortA all outputs bcf STATUS, RP0 ;select bank 0 ;Clear ports and zero motors clrf PORTA movlw b'00010001' movwf PORTB clrf lastA clrf lastB clrf pattA clrf pattB;Loop around for a while to let everything stabilize movlw d'255' movwf inportloop: decfsz inport, 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 Bmain: movf PORTA, w movwf inportA10: btfsc lastA, 0 goto A01 btfss inport, 2 goto A01 bsf lastA, 0A01: btfss lastA, 0 goto B10 btfsc inport, 2 goto B10 bcf lastA, 0 call stepAB10: btfsc lastB, 0 goto B01 btfss inport, 0 goto B01 bsf lastB, 0B01: btfss lastB, 0 goto main btfsc inport, 0 goto main bcf lastB, 0 call stepB goto main;------------------------------------------;***stepA - sub to cycle axis A one half step; Dir of 1 is increase, else decreasestepA: btfss inport, 3 decf pattA, f btfsc inport, 3 incf pattA, f;Check for pattern overflow and fix movf pattA, w sublw D'255' movlw D'07' btfsc STATUS, 2 movwf pattA movf pattA, w sublw D'08' btfsc STATUS, 2 clrf pattA ;Get step pattern and send to port B on bits 0-3 movf PORTB, w andlw B'11110000' movwf temp movf pattA, w btfsc PORTA , 4 call dcode btfss PORTA , 4 call dfcode iorwf temp, w movwf PORTB return;------------------------------------------;***stepB - sub to cycle axis B one half step; Dir of 1 is increase, else decreasestepB: btfss inport, 1 decf pattB, f btfsc inport, 1 incf pattB, f;Check for pattern overflow and fix movf pattB, w sublw D'255' movlw D'07' btfsc STATUS, 2 movwf pattB movf pattB, w sublw D'08' btfsc STATUS, 2 clrf pattB ;Get step pattern and send to port B on bits 4-7 movf PORTB, w andlw B'00001111' movwf temp swapf temp, f movf pattB, w btfsc PORTA , 4 call dcode btfss PORTA , 4 call dfcode iorwf temp, f swapf temp, w movwf PORTB 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 patterndcode: addwf PCL, f retlw B'00000001' ;0 retlw B'00000011' ;1 retlw B'00000010' ;2 retlw B'00000110' ;3 retlw B'00000100' ;4 retlw B'00001100' ;5 retlw B'00001000' ;6 retlw B'00001001' ;7dfcode: addwf PCL, f retlw B'00000011' ;0 retlw B'00000110' ;1 retlw B'00001100' ;2 retlw B'00001001' ;3 retlw B'00000011' ;4 retlw B'00000110' ;5 retlw B'00001100' ;6 retlw B'00001001' ;7;Mandatory end of program command end Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum