please dont rip this site

PIC Microcontoller IO Routine

A2D and Stepper Motor Driver

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

Questions:


file: /Techref/microchip/a2d-step-rw.htm, 3KB, , updated: 2006/1/30 10:29, local time: 2024/11/21 20:53,
TOP NEW HELP FIND: 
18.117.71.239:LOG IN

 ©2024 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?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/techref/microchip/a2d-step-rw.htm"> PIC Microcontoller IO Routine </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .