in my second project - a pic driving a steppermotor there were many
problems

Hong Ma's help was crucial in helping to make it work (thank you)- I used
assembly code for programming the code through uing MPLAB by www.microchip.com

http://www.microchip.com/1010/pline/tools/software/index.htm

using a serial cable and the programming pic-chip dock

The circuit for driving the the steppermotors from the output ports of the
PIC I found on this site

http://eio.com/jasstep.htm

a pretty good introduction and tutorial about steppermotors and how to
drive it - the diagram is Figure 2.1 - I could take it pretty much
literaly as supplied using hex inverters MM74HC4049 and 10 K
resistors and the sN3904 powertransitors.

Through measuring the resistance between the cable pairs in the
stppermotor (it has 6 cables) we were able to single out the 2 centertab
cables (see figure 3.1) the resistance of the center tab to any of the
other cables is half of that of the cables going through the entire spool
of the unipolar steppermotor.

Next step was writing the assembly code for the PIC
we used a template and some code sniplet from another chip application and
put it together - see file on the bottom of this text

One problem I had with PIC was I had forgotten to tie MCLR to high (5V)
also the PIC needs to be supplied with a 20MHZ oscillator crystal (with
capacitors embedded - otherwise you have to add them one between both
outerpin and center pin) oscillator is directly conneted to CLKIN and
CLKout pins 9 and 10 of PIC. - power PIC at pin 20 VDD and ground it at
pin 19 VSS and PIN 8 VSS

The stepper motor driver cables go into the emitter of the four
powertransitors - sequence has to be tested by giving them pulses while
connecting the centertabs to 5V and see which direction it turns.

then connect center tabs of steppermotor to external powersource that
corresponds to Voltage specs of the motor. Now driving the motor through
the assembly pattern should turn the motor the desired way


assembly code - crucial is setting portB as output pin
1-4 in this case through teh Hex number E1 - or 00011110

then loop through and set one of the pins high while others low to drive
the steppermotor with the correct pattern - the DLOOP sets the time
between each step.

hope it helps


;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PICmicro PIC16F876. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
; Template file assembled with MPLAB V4.00 and MPASM V2.20.00. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************


list p=16f876 ; list directive to define processor
#include <p16f876.inc> ; processor specific variable
definitions

; __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _RC_OSC &
_WRT_ENABLE_ON & _LVP_ON & _DEGUB_OFF & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm
file.
; The lables following the directive are located in the respective .inc
file.
; See respective data sheet for additional information on configuration
word.


;***** VARIABLE DEFINITIONS
w_temp EQU 0x70 ; variable used for context saving
status_temp EQU 0x71 ; variable used for context saving
TEMP1 equ 0x20 ;Temp variables
TEMP2 equ 0x21
TEMP3 equ 0x22

;**********************************************************************
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are cleared
goto main ; go to beginning of program


ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register
contents
movf STATUS,w ; move status register into W
register
movwf status_temp ; save off contents of STATUS
register


; isr code can go here or be located as a call subroutine elsewhere


; movf status_temp,w ; retrieve copy of STATUS
register
; movwf STATUS ; restore pre-isr STATUS
register contents
; swapf w_temp,f
; swapf w_temp,w ; restore pre-isr W register
contents
; retfie ; return from interrupt

main
CLRF STATUS ; Bank0
CLRF PORTB ; Initialize PORTB by clearing
output
; data latches
BSF STATUS, RP0 ; Select Bank1
MOVLW 0xE1 ; Value used to initialize data
direction
MOVWF TRISB ; E1 :11100001 - CF PORTB<3:0> =
inputs, PORTB<5:4> = outputs
; PORTB<7:6> = inputs
BCF STATUS, RP0


; remaining code goes here
; pattern to drive steppermotor forward is 1000 0100 0010 0001...

CLRF STATUS
LOOP
MOVLW 0x10 ; specifies the the 4th pin
MOVWF PORTB ; of portb to go high
call DELAY ; then make delay loop

MOVLW 0x08 ; same for 3th...all others low
MOVWF PORTB
call DELAY

MOVLW 0x04 ;2th
MOVWF PORTB
call DELAY

MOVLW 0x02 ; 1 th all in hex code that equals
MOVWF PORTB ; high and low setting in binary
call DELAY ; 00000010


;***************************************
;* This routine is a software delay. *
;* Fosc = 1/Tosc; Tcycle = 4 x Tosc *
;* Delay = TEMP1xTEMP2xTEMP3xTcycle *
;***************************************

DELAY

movlw 0xFF
movwf TEMP1 ;TEMP1 = 255
movwf TEMP2 ;TEMP2 = 255
movlw 0x07
movwf TEMP3 ;TEMP3 = 7

DLOOP
decfsz TEMP1, F
goto DLOOP

decfsz TEMP2, F
goto DLOOP

decfsz TEMP3, F
goto DLOOP

retlw 0x00

END ; directive 'end of program'


This site was whacked using the TRIAL version of WebWhacker. This message does not appear on a licensed copy of WebWhacker.