From: Mark Willcox
; stepr.asm, To learn stepper motor and a2d converter for a 16f873 ;last edited 5/25/2000. Originated by Tony Nixon and modified by ;Mark Willcox. Step code, 3-6-C-9,is output on portB, Hex code is ;output on portC by an 8 LED bargraph display. A 50k pot is used to vary ;time delay eg, step speed. ; The wiper of the pot goes to RA0 (analog input) the high end of the pot ;goes to +Vdd and the other end of the pot goes to -Vss/ground. ; PortB is connected to a darlington pair consisting of a 2N3904 driving ;a MJE3055T. Each coil(collector) is clamped by a 1N4934 diode to common ;ground. The stepper motor is a SLO-SYN 200oz/in, 3V@4A. ; This is a fun code to play with, you can reverse direction by ;reversing the step sequence, ie, 9-C-6-3. ; Have fun and please send me any modifications that make this code ;better. Thanks again to Tony Nixon for all his help. Mark Willcox. ; #include <p16F873.inc> LIST p=16F873, ;R=HEX __config _XT_OSC & _PWRTE_ON & _WDT_OFF & _LVE_OFF errorlevel 1,-302 CBLOCK 0X20 CounterA,CounterB,store ENDC f EQU 1 w EQU 0 OUTPUT EQU 06 org 00h clrf PORTA clrf PORTB clrf PORTC clrf store bsf STATUS,RP0 MOVLW B'00000001' MOVWF TRISA ;all outputs except RA0 CLRF TRISB CLRF TRISC MOVLW B'00010110' ;left justified, RA0 = input MOVWF ADCON1 MOVLW B'11010111' ;prescaler 1:256 tmr0, internal clock MOVWF OPTION_REG BCF STATUS,RP0 MOVLW B'01000001' ;a2d = on, ch0, fosc/8 MOVWF ADCON0 mnloop ;btfss INTCON,T0IF ;50us loop delay @ 4Mhz ;goto mnloop ;This part makes motor too slow! BCF INTCON,T0IF BSF ADCON0,GO_DONE ;start a2d conversion WAITA2D NOP ;wait 4 finish BTFSC ADCON0,GO_DONE GOTO WAITA2D MOVF ADRESH,w ;upper 8 bits-ignor lower 3,semi colon 4 debug ;MOVLW H'03' ;for debug only MOVWF store ;put a/d value in reg for time delay MOVWF PORTC ;display binary on portC MOVLW H'03' ;step sequence MOVWF OUTPUT ;to motor driver circuitry CALL DELAY ;variable delay MOVLW H'06' ;To reverse motor direction... MOVWF OUTPUT ;9 CALL DELAY ;C MOVLW H'0C' ;6 MOVWF OUTPUT ;3 CALL DELAY MOVLW H'09' MOVWF OUTPUT CALL DELAY GOTO mnloop DELAY movf store,w movwf CounterB movwf CounterA loop nop decfsz CounterA,f goto loop decfsz CounterB,f goto loop return END
|file: /Techref/microchip/a2d-step-rw.htm, 3KB, , updated: 2006/1/30 11:29, local time: 2020/7/13 09:34,
|©2020 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://techref.massmind.org/techref/microchip/a2d-step-rw.htm"> PIC Microcontoller IO Routine </A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to techref.massmind.org!