' {$STAMP BS2} ' {$PBASIC 2.5} '--------------------------------------- ' Revision history ' CNC003 - adapted hardware to speed up stepper ' moved connections TO CONRAD card TO first shift register ' moved STROBE to MIDIpin ' LTPtest004 - connected pin 1 and 2 of LTP port ' Test if LTP port is read by BASIC stamp ' LTPtest005 - test to run the stepper with LTP via X-step/dir ' CNC006 - Connected Y-step/dir and Z-step/dir ' CNC007 - read LTP bits close together ' CNC008 - only 4 steps '--------------------------------------- ' Pin layout of hardware DataP CON 0 ' Data pin to 74HC595 for columns. Clock CON 1 ' Shift clock to '595 for columns. Latch CON 2 ' Moves data from shift register to output latch for columns. DataP2 CON 3 ' Data pin to 74HC595 for rows. Clock2 CON 4 ' Shift clock to '595 for rows. Latch2 CON 5 ' Moves data from shift register to output latch for rows. LTPdirZ CON 8 ' Direction of Z stepper, from PC's LTP port pin 8 LPTstepZ CON 9 ' Step pulse for Z stepper, from PC's LTP port pin 7 LTPdirY CON 10 ' Direction of Y stepper, from PC's LTP port pin 5 LPTstepY CON 11 ' Step pulse for Y stepper, from PC's LTP port pin 4 LTPdirX CON 12 ' Direction of X stepper, from PC's LTP port pin 2 LPTstepX CON 13 ' Step pulse for X stepper, from PC's LTP port pin 1 MIDIpin CON 14 ' Pin for MIDI interface, used here for STROBE SerLCD CON 15 ' Pin for serial communication to LCD RS232pin CON 16 ' Pin of standard RS232 communication hardware ' voor elke Strobe puls wordt een motor bijgewerkt ' voor elke motor update zijn 8 bits nodig naar het schuifregister, ' gevolgd door een STROBE puls om de gegevens in te klokken. ' we gebruiken de variable MOTOR daarvoor met ' bit0 CURRENTA1 ' bit1 CURRENTA2 ' bit2 CURDIRA ' bit3 CURRENTB1 ' bit4 CURRENTB2 ' bit5 CURDIRB ' bit6 MOTSEL1 ' bit7 MOTSEL2 '--------------------------------------- ' Stepper pattern table '--------------------------------------- ' table with patterns ' ^ ' | IA ' | ' | -- ' | -- -- ' | ......--......-- ' | -- -- ' | -- ' ' ^ ' | IB ' | ' | -- ' | -- -- ' | ..--......--.... ' | -- -- ' | -- ' ' ' STEP IA IB CURRENTA1 CURRENTA2 CURDIRA CURRENTB1 CURRENTB2 CURDIRB ' 1 +60 -60 1 0 0 1 0 1 ' 2 +100 0 0 0 0 1 1 0 ' 3 +60 +60 1 0 0 1 0 0 ' 4 0 +100 1 1 0 0 0 0 ' 5 -60 +60 1 0 1 1 0 0 ' 6 -100 0 0 0 1 1 1 1 ' 7 -60 -60 1 0 1 1 0 1 ' 8 0 -100 1 1 1 0 0 1 MOTOR VAR Byte(8) 'MOTOR(0)=%00101001 'MOTOR(1)=%00011000 'MOTOR(2)=%00001001 'MOTOR(3)=%00000011 'MOTOR(4)=%00001101 'MOTOR(5)=%00111100 'MOTOR(6)=%00101101 'MOTOR(7)=%00100111 ' STEP IA IB CURRENTA1 CURRENTA2 CURDIRA CURRENTB1 CURRENTB2 CURDIRB ' 1 +100 0 0 0 0 1 1 0 ' 2 0 +100 1 1 0 0 0 0 ' 3 -100 0 0 0 1 1 1 1 ' 4 0 -100 1 1 1 0 0 1 ' 5 +100 0 0 0 0 1 1 0 ' 6 0 +100 1 1 0 0 0 0 ' 7 -100 0 0 0 1 1 1 1 ' 8 0 -100 1 1 1 0 0 1 MOTOR(0)=%00011000 MOTOR(1)=%00000011 MOTOR(2)=%00111100 MOTOR(3)=%00100111 MOTOR(4)=%00011000 MOTOR(5)=%00000011 MOTOR(6)=%00111100 MOTOR(7)=%00100111 ' Other Constants N2400 CON $418D ' for LCD. Define inverted, 2400-bps serial ' Variables Xpos VAR Nib Ypos VAR Nib Zpos VAR Nib Xstep VAR Bit XstepOld VAR Bit Xdir VAR Bit Ystep VAR Bit YstepOld VAR Bit Ydir VAR Bit Zstep VAR Bit ZstepOld VAR Bit Zdir VAR Bit TheBegin: '--------------------------------------- ' Initialize hardware '--------------------------------------- SHIFTOUT DataP,Clock,MSBFIRST,[0] ' Send the highbyte bits. SHIFTOUT DataP,Clock,MSBFIRST,[0] ' Send the lowbyte bits. PULSOUT Latch,1 ' Transfer to outputs. SHIFTOUT DataP2,Clock2,MSBFIRST,[17] ' Send the rowbyte. PULSOUT Latch2,1 ' Transfer to outputs. HIGH MIDIpin INPUT LTPdirX INPUT LPTstepX INPUT LTPdirY INPUT LPTstepY INPUT LTPdirZ INPUT LPTstepZ PAUSE 500 '--------------------------------------- ' Show the welcome message '--------------------------------------- TheMenu: PAUSE 500 SEROUT SerLCD,N2400,[12, "hemey CNCsoft",13,"v CNC008"] PAUSE 500 '--------------------------------------- ' Initialize software '--------------------------------------- Xpos=0 Ypos=0 Zpos=0 XstepOld = 1 YstepOld = 1 ZstepOld = 1 '--------------------------------------- ' Main loop '--------------------------------------- again: Xstep = IN13 Xdir = IN12 Ystep = IN11 Ydir = IN10 Zstep = IN9 Zdir = IN8 IF (Xstep = XstepOld) THEN NoXChange IF (Xdir = 1) THEN Xpos = Xpos+1 ELSE Xpos = Xpos-1 ENDIF GOSUB StepX XstepOld = Xstep NoXChange: IF (Ystep = YstepOld) THEN NoYChange IF (Ydir = 1) THEN Ypos = Ypos+1 ELSE Ypos = Ypos-1 ENDIF GOSUB StepY YstepOld = Ystep NoYChange: IF (Zstep = ZstepOld) THEN NoZChange IF (Zdir = 1) THEN Zpos = Zpos+1 ELSE Zpos = Zpos-1 ENDIF GOSUB StepZ ZstepOld = Zstep NoZChange: GOTO again '--------------------------------------- ' Subroutines '--------------------------------------- StepX: ' SEROUT SerLCD,N2400,[12, "hemey CNC mot X",13, IBIN8 MOTOR(Xpos & %0111)] ' SEROUT SerLCD,N2400,[12, "hemey CNC mot X",13, Xpos] SHIFTOUT DataP,Clock,LSBFIRST,[MOTOR(Xpos & %0111) | %00000000] ' Send the highbyte bits. PULSOUT Latch,1 ' Transfer to outputs. PULSOUT MIDIpin, 1 ' Send STROBE RETURN StepY: ' SEROUT SerLCD,N2400,[12, "hemey CNC mot X",13, IBIN8 MOTOR(Xpos & %0111)] ' SEROUT SerLCD,N2400,[12, "hemey CNC mot X",13, Xpos] SHIFTOUT DataP,Clock,LSBFIRST,[MOTOR(Ypos & %0111) | %01000000] ' Send the highbyte bits. PULSOUT Latch,1 ' Transfer to outputs. PULSOUT MIDIpin, 1 ' Send STROBE RETURN StepZ: ' SEROUT SerLCD,N2400,[12, "hemey CNC mot X",13, IBIN8 MOTOR(Xpos & %0111)] ' SEROUT SerLCD,N2400,[12, "hemey CNC mot X",13, Xpos] SHIFTOUT DataP,Clock,LSBFIRST,[MOTOR(Zpos & %0111) | %10000000] ' Send the highbyte bits. PULSOUT Latch,1 ' Transfer to outputs. PULSOUT MIDIpin, 1 ' Send STROBE RETURN |