PIC16F88 08 Stepper Motor |
|
This uses a stepper motor and Darlington Driver board - 28BYJ-48. The motor is geared for slow but precise movement. It's OK to run this for short periods via the 7805 voltage regulator but it gets quite hot. For prolonged operation, a separate 5 Volt supply should be used for the motor.
; PIC16F88 Configuration Bit Settings ; CONFIG1 and CONFIG2 #include "p16F88.inc" __CONFIG _CONFIG1, _FOSC_INTOSCIO & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CCPMX_RB0 & _CP_OFF __CONFIG _CONFIG2, _FCMEN_ON & _IESO_ON RES_VECT CODE 0x0000 ; processor reset to vector address zero GOTO START ; go to beginning of program MAIN_PROG CODE ; let linker place main program START: ; INITIALISATION bsf STATUS, RP0 ; Select bank 1. movlw b'00000000' ; Set all port pins to output / Disable ADC / Set for digital i/o movwf ADCON1 ; Disble ADC module (Never leave this to chance) movwf ANSEL ; Set analog i/o for digital i/o (Never leave this to chance) movwf TRISA ; Set porta for output - RA5 is input only so this bit is ignored movlw b'11111111' ; Set all portB pins to input / unused movwf TRISB ; Set porta for output - RA5 is input only so this bit is ignored movlw b'00000000' ; <<<< Set Oscillator to 31.25 kHz or movwf OSCCON ; <<<< 128 microseconds per line of code. CLRWDT ; Clear the Watchdog Timer and prescaler movlw b'00000011' ; 1:8 prescaler movwf OPTION_REG ; The prescaler settings are stored in OPTION_REG bcf STATUS, RP0 ; Select bank 0. STEPPER: MOVLW 0x02 ; xxx0001x ; The control board does not have a line zero - neither does this code. MOVWF PORTA CALL DELAY MOVLW 0x04 ; xxx0010x MOVWF PORTA CALL DELAY MOVLW 0x08 ; xxx0100x MOVWF PORTA CALL DELAY MOVLW 0x10 ; xxx1000x MOVWF PORTA CALL DELAY GOTO STEPPER ; continue forever DELAY: bcf INTCON, TMR0IF ; Clear the TMR0IF flag MOVLW d'220' ; Very SLOW motor movement. Increase 220 up to 256 in small steps MOVWF TMR0 ; The motor will run faster until it stalls. DELAY_POLL: btfss INTCON, TMR0IF ; did TMR0 roll over yet? Is TMR0IF set? goto DELAY_POLL ; NO - Go back and repeat the DELAY_POLL polling loop. RETURN ; YES - Return from the subroutine end
Contact, Copyright, Cookies and Legalities: C Neil Bauers - reviseOmatic V4 - © 2016/17
Hosted at linode.com - London
Please report website problems to Neil