Ejemplo n.º 1
0
void tick_task(uint8_t tick_type) {
	if(tick_type == TICK_TASK_TYPE_CALCULATION) {
		stepper_tick_calc_counter++;
		stepper_current_sum += adc_channel_get_data(STEPPER_CURRENT_CHANNEL);
		if(stepper_tick_calc_counter % 100 == 0) {
			stepper_current = stepper_current_sum/100;
			stepper_current_sum = 0;
		}
		// Switch Output Voltage between extern and stack
		if(stepper_get_external_voltage() < STEPPER_VOLTAGE_EPSILON) {
			PIO_Set(&pin_voltage_switch);
		} else {
			PIO_Clear(&pin_voltage_switch);
		}
	} else if(tick_type == TICK_TASK_TYPE_MESSAGE) {
		stepper_tick_counter++;

		if(stepper_position_reached) {
			stepper_position_reached = false;
			stepper_position_reached_signal();
		}

		stepper_check_error_signals();
	}
}
Ejemplo n.º 2
0
void stepper_check_error_signals(void) {
	if(stepper_tick_counter % 1000 != 0 || stepper_state == STEPPER_STATE_OFF) {
		return;
	}

	const uint16_t external_voltage = stepper_get_external_voltage();
	const uint16_t stack_voltage    = stepper_get_stack_voltage();

	// Under Voltage if external voltage is below minimum voltage (regardless
	// of stack voltage), or if external voltage is zero and stack velotage is
	// below minimum voltage

	if((external_voltage > STEPPER_VOLTAGE_EPSILON &&
	    external_voltage < stepper_minimum_voltage) ||
	   (external_voltage < STEPPER_VOLTAGE_EPSILON &&
	    stack_voltage > STEPPER_VOLTAGE_EPSILON &&
	    stack_voltage < stepper_minimum_voltage)) {
		UnderVoltageSignal uvs = {
			com_stack_id,
			TYPE_UNDER_VOLTAGE,
			sizeof(UnderVoltageSignal),
			external_voltage < STEPPER_VOLTAGE_EPSILON ? stack_voltage : external_voltage
		};

		send_blocking_with_timeout(&uvs,
		                           sizeof(UnderVoltageSignal),
		                           com_current);
		led_on(LED_STD_RED);
	} else {
		led_off(LED_STD_RED);
	}
}
void get_external_input_voltage(const ComType com, const GetExternalInputVoltage *data) {
	GetExternalInputVoltageReturn geivr;

	geivr.header        = data->header;
	geivr.header.length = sizeof(GetExternalInputVoltageReturn);
	geivr.voltage       = stepper_get_external_voltage();

	send_blocking_with_timeout(&geivr, sizeof(GetExternalInputVoltageReturn), com);
}
Ejemplo n.º 4
0
void get_external_input_voltage(uint8_t com, const GetExternalInputVoltage *data) {
	GetExternalInputVoltageReturn geivr;

	geivr.stack_address = data->stack_address;
	geivr.type          = data->type;
	geivr.length        = sizeof(GetExternalInputVoltageReturn);
	geivr.voltage       = stepper_get_external_voltage();

	send_blocking_with_timeout(&geivr, sizeof(GetExternalInputVoltageReturn), com);
}