Beispiel #1
0
Datei: main.c Projekt: likon/bldc
/*
 * Called every time new ADC values are available. Note that
 * the ADC is initialized from mcpwm.c
 */
void main_dma_adc_handler(void) {
	ledpwm_update_pwm();

	if (sample_at_start && mcpwm_get_state() == MC_STATE_STARTING) {
		sample_now = 0;
		sample_ready = 0;
		was_start_wample = 1;
		sample_at_start = 0;
	}

	static int a = 0;
	if (!sample_ready) {
		a++;
		if (a >= sample_int) {
			a = 0;
			curr0_samples[sample_now] = ADC_curr_norm_value[0];
			curr1_samples[sample_now] = ADC_curr_norm_value[1];
			ph1_samples[sample_now] = ADC_V_L1;
			ph2_samples[sample_now] = ADC_V_L2;
			ph3_samples[sample_now] = ADC_V_L3;
			vzero_samples[sample_now] = ADC_V_ZERO * MCPWM_VZERO_FACT;

			if (mcpwm_get_state() == MC_STATE_DETECTING && 0) {
				status_samples[sample_now] = mcpwm_get_detect_top();
			} else {
				uint8_t tmp;

				if (was_start_wample) {
					if (mcpwm_get_state() == MC_STATE_STARTING) {
						tmp = 1;
					} else if (mcpwm_get_state() == MC_STATE_RUNNING) {
						tmp = 2;
					} else {
						tmp = 3;
					}
				} else {
					tmp = mcpwm_read_hall_phase();
				}

				status_samples[sample_now] = mcpwm_get_comm_step() | (tmp << 3);
			}

			curr_fir_samples[sample_now] = (int16_t)(mcpwm_get_tot_current_filtered() * 100);

			sample_now++;

			if (sample_now == sample_len) {
				sample_ready = 1;
				sample_now = 0;
				was_start_wample = 0;
				chSysLockFromIsr();
				chEvtSignalI(sample_send_tp, (eventmask_t) 1);
				chSysUnlockFromIsr();
			}

			main_last_adc_duration = mcpwm_get_last_adc_isr_duration();
		}
	}
}
Beispiel #2
0
float mc_interface_get_tot_current_filtered(void) {
	float ret = 0.0;

	switch (m_conf.motor_type) {
	case MOTOR_TYPE_BLDC:
	case MOTOR_TYPE_DC:
		ret = mcpwm_get_tot_current_filtered();
		break;

	case MOTOR_TYPE_FOC:
		ret = mcpwm_foc_get_tot_current_filtered();
		break;

	default:
		break;
	}

	return ret;
}