|
Re: Electronics and software combination questions September 12, 2013 02:45PM |
Registered: 12 years ago Posts: 95 |
//=======================================
void motorDrive() {
curMicros = micros();
if (mMoves == 0) {
Serial.print("StartMoveZ");
mMoves = 1;
startMoveMicros = curMicros;
for (byte m = 0; m < motorCount; m++) { // for each of the motors
motors[m].nxtInterval = curMicros + motors[m].rptInterval;
// Serial.println(motors[m].nxtInterval);
}
// Serial.print("Z");
}
else {
// mMoves++;
// if (pcData.pcVars.cmdType == 'c') {
// Serial.print(curMicros - startMoveMicros);
// Serial.print(" ");
// Serial.print(motors[0].nxtInterval);
// Serial.print("Z");
// }
for (byte m = 0; m < motorCount; m++) { // for each of the motors
// set the stepPin low if appropriate
if (motors[m].pulseHigh && curMicros >= motors[m].nxtLow) {
digitalWrite(motors[m].stepPin, LOW);
motors[m].pulseHigh = false;
// msteps[m]++;
} // if (micros() - motors[m].lastMicros
// is it time to step this motor
if ((curMicros >= motors[m].nxtInterval)) { // is it time to step this motor
// the PC will have figured out that this step won't happen
// before the previous step is complete
// Serial.print("StepTimeZ");
digitalWrite(motors[m].stepPin, HIGH);
motors[m].pulseHigh = true;
motors[m].lastMicros = micros();
motors[m].nxtLow = motors[m].nxtInterval + pulseWidth; //motors[m].rptInterval / 2;
motors[m].nxtInterval += motors[m].rptInterval;
msteps[m]++;
} // if (countVal % motors[m].rptInterval == 0)
} // for (byte m = 0;
if (curMicros - startMoveMicros > moveTotalMicros) { // i.e. this movement is complete
for (byte m = 0; m < motorCount; m++) { // for each of the motors
digitalWrite(motors[m].stepPin, LOW);
motors[m].pulseHigh = false;
}
// Serial.print("Movement CompleteZ");
// Serial.print("MSTEPS ");
// Serial.print(msteps[0]);
// Serial.print(" ");
// Serial.println(msteps[1]);
// Serial.print("Curmicros1 ");
// Serial.println(curMicros1);
// Serial.println(scndMicros);
// Serial.print(mMoves);
// Serial.print("Z");
countVal = 0;
mMoves = 0;
countInProgress = false;
getLineFromPC();
Serial.print("Data requested after moveZ");
}
// unsigned long endMicros = micros();
// Serial.print("Move Loop ");
// Serial.print(endMicros - startMicros);
// Serial.print("Z");
}
}
|
Re: Electronics and software combination questions September 12, 2013 03:17PM |
Registered: 14 years ago Posts: 809 |
|
Re: Electronics and software combination questions September 12, 2013 04:46PM |
Registered: 12 years ago Posts: 95 |
The lathe itself is an extravagance because I don't use it much and converting it to CNC and 3D printing is an even greater extravagance - but fun.|
Re: Electronics and software combination questions September 12, 2013 05:03PM |
Registered: 15 years ago Posts: 406 |
|
Re: Electronics and software combination questions September 12, 2013 05:42PM |
Registered: 14 years ago Posts: 1,236 |
|
Re: Electronics and software combination questions September 13, 2013 03:55AM |
Registered: 12 years ago Posts: 95 |
|
Re: Electronics and software combination questions September 13, 2013 04:50AM |
Registered: 15 years ago Posts: 1,797 |
|
Re: Electronics and software combination questions September 13, 2013 12:05PM |
Registered: 12 years ago Posts: 95 |
|
Re: Electronics and software combination questions September 16, 2013 11:35AM |
Registered: 12 years ago Posts: 14 |
|
Re: Electronics and software combination questions September 16, 2013 06:03PM |
Registered: 12 years ago Posts: 95 |
|
Re: Electronics and software combination questions September 17, 2013 09:59AM |
Registered: 12 years ago Posts: 2 |
|
Re: Electronics and software combination questions September 17, 2013 01:37PM |
Registered: 12 years ago Posts: 95 |