mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-18 18:20:15 +08:00
Merge branch 'timing' into devel_fast
This commit is contained in:
@@ -31,6 +31,7 @@ constexpr float adc_ref_voltage = 3.3f;
|
||||
// Arbitrary non-zero inital value to avoid division by zero if ADC reading is late
|
||||
float vbus_voltage = 12.0f;
|
||||
float ibus_ = 0.0f; // exposed for monitoring only
|
||||
bool task_timers_armed = false;
|
||||
bool brake_resistor_armed = false;
|
||||
bool brake_resistor_saturated = false;
|
||||
/* Private constant data -----------------------------------------------------*/
|
||||
@@ -385,6 +386,8 @@ void vbus_sense_adc_cb(ADC_HandleTypeDef* hadc, bool injected) {
|
||||
// This is the callback from the ADC that we expect after the PWM has triggered an ADC conversion.
|
||||
// Timing diagram: Firmware/timing_diagram_v3.png
|
||||
void pwm_trig_adc_cb(ADC_HandleTypeDef* hadc, bool injected) {
|
||||
|
||||
adc_timestamp = sample_TIM13();
|
||||
#define calib_tau 0.2f //@TOTO make more easily configurable
|
||||
constexpr float calib_filter_k = CURRENT_MEAS_PERIOD / calib_tau;
|
||||
|
||||
@@ -405,10 +408,12 @@ void pwm_trig_adc_cb(ADC_HandleTypeDef* hadc, bool injected) {
|
||||
bool current_meas_not_DC_CAL = !counting_down;
|
||||
|
||||
// Check the timing of the sequencing
|
||||
if (current_meas_not_DC_CAL)
|
||||
if (current_meas_not_DC_CAL) {
|
||||
axis.motor_.log_timing(TIMING_LOG_ADC_CB_I);
|
||||
else
|
||||
}
|
||||
else {
|
||||
axis.motor_.log_timing(TIMING_LOG_ADC_CB_DC);
|
||||
}
|
||||
|
||||
bool update_timings = false;
|
||||
if (hadc == &hadc2) {
|
||||
@@ -453,6 +458,19 @@ void pwm_trig_adc_cb(ADC_HandleTypeDef* hadc, bool injected) {
|
||||
}
|
||||
float current = axis.motor_.phase_current_from_adcval(ADCValue);
|
||||
|
||||
|
||||
if(current_meas_not_DC_CAL && axis_num == 0 && hadc == &hadc2){
|
||||
if (task_timers_armed) {
|
||||
TaskTimer::sample_next = true;
|
||||
task_timers_armed = false;
|
||||
axes[0].task_times_.adc_cb.startTime = adc_timestamp; // Start of ADC2
|
||||
}
|
||||
}
|
||||
|
||||
if(current_meas_not_DC_CAL && axis_num == 0 && hadc == &hadc3){
|
||||
axes[0].task_times_.adc_cb.stopTimer(); // End of ADC3
|
||||
}
|
||||
|
||||
if (current_meas_not_DC_CAL) {
|
||||
// ADC2 and ADC3 record the phB and phC currents concurrently,
|
||||
// and their interrupts should arrive on the same clock cycle.
|
||||
@@ -485,6 +503,8 @@ void pwm_trig_adc_cb(ADC_HandleTypeDef* hadc, bool injected) {
|
||||
// @brief Sums up the Ibus contribution of each motor and updates the
|
||||
// brake resistor PWM accordingly.
|
||||
void update_brake_current() {
|
||||
axes[0].task_times_.brake_update.beginTimer();
|
||||
axes[1].task_times_.brake_update.beginTimer();
|
||||
float Ibus_sum = 0.0f;
|
||||
for (size_t i = 0; i < AXIS_COUNT; ++i) {
|
||||
if (axes[i].motor_.armed_state_ == Motor::ARMED_STATE_ARMED) {
|
||||
@@ -533,6 +553,8 @@ void update_brake_current() {
|
||||
int low_off = high_on - TIM_APB1_DEADTIME_CLOCKS;
|
||||
if (low_off < 0) low_off = 0;
|
||||
safety_critical_apply_brake_resistor_timings(low_off, high_on);
|
||||
axes[0].task_times_.brake_update.stopTimer();
|
||||
axes[1].task_times_.brake_update.stopTimer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user