Esempio n. 1
0
void stepper_set_next_timer(uint32_t velocity) {
	if(velocity == 0) {
		if(stepper_state == STEPPER_STATE_DRIVE) {
			// In drive mode we have a transition from backward to forward here.
			// Wait 10ms in that case
			velocity = 100;
		} else {
			// In step mode this should not happen, stop tc
			stepper_running = false;
			tc_channel_stop(&STEPPER_TC_CHANNEL);
			return;
		}
	}

	int8_t i;
	for(i = 4; i > 0; i--) {
		if(velocity <= stepper_timer_velocity[i-1]) {
			break;
		}
	}

	STEPPER_TC_CHANNEL.TC_CMR = i | TC_CMR_CPCTRG;
	STEPPER_COUNTER = stepper_timer_frequency[i] / velocity;
	if(!stepper_is_currently_running()) {
		stepper_running = true;
		tc_channel_start(&STEPPER_TC_CHANNEL);
	}
}
Esempio n. 2
0
void set_steps(uint8_t com, const SetSteps *data) {
	if(stepper_is_currently_running() || stepper_state == STEPPER_STATE_OFF) {
		return;
	}

	stepper_state = STEPPER_STATE_STEPS;
	stepper_steps = data->steps;
	stepper_make_step_speedramp(data->steps);
}
Esempio n. 3
0
void set_target_position(uint8_t com, const SetTargetPosition *data) {
	if(stepper_is_currently_running() || stepper_state == STEPPER_STATE_OFF) {
		return;
	}

	stepper_state = STEPPER_STATE_TARGET;
	stepper_target_position = data->position;
	stepper_make_step_speedramp(stepper_target_position - stepper_position);
}
Esempio n. 4
0
void stepper_make_drive_speedramp(uint8_t state) {
	stepper_state = STEPPER_STATE_DRIVE;
	stepper_speedramp_state = state;

	if(!stepper_is_currently_running()) {
		// call drive speedramp one time, to get it going
		// (i.e. make velocity != 0)
		stepper_drive_speedramp();
		TC0_IrqHandler();
	}
}
void set_steps(const ComType com, const SetSteps *data) {
	if(stepper_is_currently_running() || stepper_state == STEPPER_STATE_OFF) {
		com_return_setter(com, data);
		return;
	}

	stepper_state = STEPPER_STATE_STEPS;
	stepper_steps = data->steps;
	stepper_make_step_speedramp(data->steps);

	com_return_setter(com, data);
}
void set_target_position(const ComType com, const SetTargetPosition *data) {
	if(stepper_is_currently_running() || stepper_state == STEPPER_STATE_OFF) {
		com_return_setter(com, data);
		return;
	}

	stepper_state = STEPPER_STATE_TARGET;
	stepper_target_position = data->position;
	stepper_make_step_speedramp(stepper_target_position - stepper_position);

	com_return_setter(com, data);
}