I have included a file which will control a stepper motor. The stepper motor that i am using has an opto-switch so when the motor reaches a pre defined location it sends a high signal to the PIC, Every aspect of the program works, ie direction, run. But we cannot get the STOPTOP working, It seems the strpper motor output is bouncing so when STOPTOP is reached it does not give a clear high, I want to include a number of checks in the CLOCK subroutine to stop the motor output from bouncing, Any suggestions would be appreciated. Regards Andy Bassam ;***************************************************************************** ;written by: Andrew Bassam * ;date: 12 January 2000 * ;version: 1.0 * ;filename: smotor.asm * ;target chip: PIC12C508 * ;clock: 4MHz (internal) * ;function: Stepper Motor Controller * ;***************************************************************************** list P=12C508 include "p12c508.inc" ;============= ;Declarations: counter equ h'08' ; Register used to output a CLK pulse. #define CLK GPIO,0 ; I/O port names. #define CCW GPIO,1 #define TOPFLAG GPIO,2 #define DIR GPIO,4 #define RUN GPIO,5 #define STOPTOP GPIO,3 org 0 goto Start ;============ ;Subroutines; Init movlw b'111100' ; Set GP0-1 as outputs, GP2-5 as inputs. tris GPIO movlw b'11000100' ; Use prescalar, timer=8.192 ms =~ 10 ms. option clrf GPIO ; Reset general port. retlw 0 Direction btfss DIR ; Check input direction. bcf CCW ; Set output direction accordingly. btfsc DIR bsf CCW retlw 0 Pulse bsf CLK ; Start clk pulse. clrf TMR0 ; Reset timer 0. Loop movfw TMR0 andlw d'2' btfsc STATUS,Z ; Is timer0 = 2 (50 uS passed)? goto Loop ; No, so keep looping. bcf CLK ; Yes. stop clk pulse. call Timming retlw 0 Timming movfw TMR0 btfss STATUS,Z ; Is timer0=0 (8 mS passed)? goto Timming ; No, so keep looping. retlw 0 ; Yes, return to main. ;============== ;Program Start: Start call Init ; Set up I/Os and option register. Main call Direction ; Set motor to input switch direction. btfss RUN ; Is run switch on? goto Main ; No. btfss TOPFLAG ; Yes, Is motor at top? call Pulse ; No, so keep motor running. btfss STOPTOP ; Yes. Is stoptop switch on? call Pulse ; No, so keep motor running. goto Main ; Yes. END