예제 #1
0
// Initialize and start the stepper motor subsystem
void stepper_init() {  
  // Configure directions of interface pins
  STEPPING_DDR |= (STEPPING_MASK | DIRECTION_MASK);
  STEPPING_PORT = (STEPPING_PORT & ~(STEPPING_MASK | DIRECTION_MASK)) | INVERT_MASK;
  
  // waveform generation = 0100 = CTC
  TCCR1B &= ~(1<<WGM13);
  TCCR1B |= (1<<WGM12);
  TCCR1A &= ~(1<<WGM11);
  TCCR1A &= ~(1<<WGM10);

  // output mode = 00 (disconnected)
  TCCR1A &= ~(3<<COM1A0);
  TCCR1A &= ~(3<<COM1B0);

  // Configure Timer 2
  TCCR2A = 0; // Normal operation
  TCCR2B = 0; // Disable timer until needed.
  TIMSK2 |= (1<<TOIE2); // Enable Timer2 interrupt flag
  
  adjust_speed(MINIMUM_STEPS_PER_MINUTE);
  clear_vector(stepper_position);
  stepper_set_position( CONFIG_X_ORIGIN_OFFSET, 
                        CONFIG_Y_ORIGIN_OFFSET, 
                        CONFIG_Z_ORIGIN_OFFSET );
  acceleration_tick_counter = 0;
  current_block = NULL;
  stop_requested = false;
  stop_status = STATUS_OK;
  busy = false;
  
  // start in the idle state
  // The stepper interrupt gets started when blocks are being added.
  stepper_go_idle();  
}
예제 #2
0
void move_to_cell(StepperA* motor, VerticalActuatorA* va, unsigned char cell) {
    vertical_actuator_transition_tier(va, cell / CELLS_PER_TIER);
    timer_delay_ms(DELAY_BETWEEN_MOVEMENTS_MS);
    stepper_set_position(motor, stepper_degrees_to_position((cell % CELLS_PER_TIER) * DEGREES_BETWEEN_CELLS));
    timer_delay_ms(DELAY_BETWEEN_MOVEMENTS_MS);
}
예제 #3
0
파일: gcode.c 프로젝트: Sagittarii/stepper
void processGCode(const cmd_param param)
{
    switch ((int)param.g)
    {
        case 0: // G0 = Rapid move
            // Handle G0 as G1 (so no break here)
        case 1: // G1 = Controlled move

            if (param.f_set && (param.f != 0.0) )
            {
                stepper_set_feedrate(AXIS_X, param.f);
                stepper_set_feedrate(AXIS_Y, param.f);
                stepper_set_feedrate(AXIS_Z, param.f);
                stepper_set_feedrate(AXIS_E, param.f);
            }

            if ( param.x_set || param.y_set || param.z_set || param.e_set )
            {
                float pos[AXIS_NUM] = {param.x, param.y, param.z, param.e};
                bool set[AXIS_NUM] = {param.x_set, param.y_set, param.z_set, param.e_set};
                stepper_move(pos, set);
            }
            else
            {
                puts("ok\n");
            }
            break;
        case 4: // G4 = Dwell
            puts("ok\n");
            break;
        case 10: // G10 = Head Offset
            puts("ok\n");
            break;
        case 20: // G20 = Set Units to Inches
            /// \todo to handle
            puts("!!\n"); // Send Command Fail to block the system
            break;
        case 21: // G21 = Set Units to Millimeters
            /// \todo to handle
            puts("ok\n");
            break;
        case 28: // G28 = Move to Origin
            stepper_reset(); /// \todo change to real move to origin
            puts("ok\n");
            break;
        case 29:
        case 30:
        case 31:
        case 32: // G29-32 = Bed probing
            puts("ok\n");
            break;
        case 90: // G90 = Set to Absolute Positioning
            stepper_set_absolute(AXIS_X);
            stepper_set_absolute(AXIS_Y);
            stepper_set_absolute(AXIS_Z);
            puts("ok\n");
            break;
        case 91: // G91 = Set to Relative Positioning
            stepper_set_relative(AXIS_X);
            stepper_set_relative(AXIS_Y);
            stepper_set_relative(AXIS_Z);
            puts("ok\n");
            break;
        case 92: // G92 = Set Position
            if (param.x_set)
            {
                stepper_set_position(AXIS_X, param.x);
            }
            if (param.y_set)
            {
                stepper_set_position(AXIS_Y, param.y);
            }
            if (param.z_set)
            {
                stepper_set_position(AXIS_Z, param.z);
            }
            if (param.e_set)
            {
                stepper_set_position(AXIS_E, param.e);
            }

            puts("ok\n");
            break;
        default:
            puts("ok\n");
            break;
    }
}