// Perform homing cycle to locate and set machine zero. Only '$H' executes this command. // NOTE: There should be no motions in the buffer and Grbl must be in an idle state before // executing the homing cycle. This prevents incorrect buffered plans after homing. void MotionGoHome(void) { plan_init(); uint16_t limitStatus; uint16_t stepCount; sys.state = STATE_HOMING; // Set system state variable // LIMIT_PCMSK &= ~LIMIT_MASK; // Disable hard limits pin change register for cycle duration xLimitDetected = FALSE; yLimitDetected = FALSE; BSP_SetStepSize(X_AXIS, QUARTER); BSP_SetStepSize(Y_AXIS, QUARTER); BSP_SetStepSize(Z_AXIS, QUARTER); settings.steps_per_mm[X_AXIS] = X_STEPS_MM(QUARTER_STEP); settings.steps_per_mm[Y_AXIS] = Y_STEPS_MM(QUARTER_STEP); settings.steps_per_mm[Z_AXIS] = Z_STEPS_MM(QUARTER_STEP); // Find out if X or Y axis are at limit limitStatus = mPORTCReadBits(xLimitInput.pin||yLimitInput.pin); if(limitStatus) { if(limitStatus & xLimitInput.pin) // If Xat Limit { stepCount = 0; BSP_Timer3Start(100); OpenOC2(XS_PWM_ENA, (ReadPeriod3()>>1), ReadPeriod3()>>1); BSP_AxisEnable(X_AXIS, NEGATIVE); while((mPORTCReadBits(xLimitInput.pin))) { stepCount++; steps_X = 0x1; if(stepCount >= 20) mPORTGToggleBits(xAxis.directionPin.pin); } BSP_AxisDisable(X_AXIS); if(mPORTGReadBits(xAxis.directionPin.pin) == POSITIVE) gcode.position[X_AXIS] = 215.000; else gcode.position[X_AXIS] =0; } if(limitStatus & yLimitInput.pin) // If Xat Limit { stepCount = 0; BSP_Timer2Start(100); OpenOC1(XS_PWM_ENA, (ReadPeriod2()>>1), ReadPeriod2()>>1); BSP_AxisEnable(Y_AXIS, NEGATIVE); while((mPORTCReadBits(yLimitInput.pin))) { stepCount++; steps_Y = 0x1; if(stepCount >= 20) mPORTEToggleBits(yAxis.directionPin.pin); } if(mPORTEReadBits(xAxis.directionPin.pin) == POSITIVE) gcode.position[Y_AXIS] = 215.000; else gcode.position[Y_AXIS] =0; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // STEP 9. configure the CN interrupt handler void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) { unsigned int temp; // clear the mismatch condition temp = PORTReadBits(IOPORT_D, BIT_6); // .. things to do .. toggle the led mPORTDToggleBits(BIT_1); mPORTEToggleBits(BIT_2); // clear the interrupt flag mCNClearIntFlag(); }