/****************************************************************************** * * Copyright (C) 2008 Chris Morley * * * This module is a software microstepper for Mesa"s 7i32 hardware stepper controller * ****************************************************************************** * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General * Public License as published by the Free Software Foundation. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA * * THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR * ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE * TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of * harming persons must have provisions for completely removing power * from all motors, etc, before persons enter any danger area. All * machinery must be designed to comply with local and national safety * codes, and the authors of this software can not, and do not, take * any responsibility for such compliance. * * This code was written as part of the EMC HAL project. For more * information, go to www.linuxcnc.org. * ******************************************************************************/ component mesa7i32driver"Driver for Mesa 7i32 step driver"; description """Software driver for 1/8 microstepping using mesa's 7i32 microstepping hardware driver \ this converts step and direction signals to current intensity and sign signals \ for mesa's driver. One could change the values in the intensity ramps to compensate for angular error or create 1/4 \ 1/16 stepping ramps etc. One should probably create a pin to halve the current output for when the motor is at rest."""; pin in bit step#[2]"step signal from a step driver"; pin in bit dir#[2]"direction signal from a step driver"; pin out bit enable#[4]"enable output pin"; pin out float intensity#[4]"signed current intensity for pwm"; param rw u32 type_ = 0 "parameter for type of stepping: 0 = 1/8 microstepping, 1 = 1/2 stepping \ both channels will be the same"; function_"function to do the conversion work"; license "GPL"; ;; typedef enum { EIGHTH_STEP, HALF_STEP } Type; //these floats hold the intensity ramps // 1/8 stepping has 32 unique intensity combinations for 32 positions per full step // though 1/2 stepping only has 8 unique combinations we copy it 4 times for 32 positions just to make the code easier to write float xi[2][32] = { /*current intensity for 1/8 stepping*/ {10,9.8,9.2,8.3,7,5.5,3.8,2, 0,-2,-3.8,-5.5,-7,-8.3,-9.2,-9.8, -10,-9.8,-9.2,-8.3,-7,-5.5,-3.8,-2, 0,2,3.8,5.5,7,8.3,9.2,9.8}, /*current intensity for half stepping:*/ {10,10,0,-10,-10,-10,0,10, 10,10,0,-10,-10,-10,0,10, 10,10,0,-10,-10,-10,0,10, 10,10,0,-10,-10,-10,0,10} }; float yi[2][32] = { /* current intensity for 1/8 stepping*/ {0,2,3.8,5.5,7,8.3,9.2,9.8, 10,9.8,9.2,8.3,7,5.5,3.8,2, 0,-2,-3.8 ,-5.5,-7,-8.3,-9.2,-9.8, -10,-9.8,-9.2,-8.3,-7,-5.5,-3.8,-2}, /*current intensity for half stepping:*/ {0,10,10,10,0,-10,-10,-10, 0,10,10,10,0,-10,-10,-10, 0,10,10,10,0,-10,-10,-10, 0,10,10,10,0,-10,-10,-10} }; int z=1,z2=1; FUNCTION(_) { static int tmp0=0,tmp1=0; if (type_ !=HALF_STEP) (type_= EIGHTH_STEP); //FIRST STEPPER PORT // checks to see there was a logic 0 on step pin before stepping again. (meaning this is a new step not the same step) // Enable pins' logic levels are based on whether the intensity pins are zero or not // temp0 is for keeping track of what logic the step pin was at last time through this routine if (step(0)==1 && tmp0==0) { if(dir(0)==1) {z++;}else{z--;} if ((z)==-1 ){z=31;} if ((z)==32) {z=0;} enable(0)=(intensity(0)=xi[type_][z]); enable(1)=(intensity(1)=yi[type_][z]); tmp0=1; }else {if (step(0)==0) {tmp0=0;}} //SECOND STEPPER PORT if (step(1)==1 && tmp1==0) { if(dir(1)==1) {z2++;}else{z2--;} if ((z2)==-1 ){z2=31;} if ((z2)==32) {z2=0;} enable(2)=(intensity(2)=xi[type_][z2]); enable(3)=(intensity(3)=yi[type_][z2]); tmp1=1; }else{ if (step(1)==0) {tmp1=0;}} }