mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-26 21:10:05 +08:00
implement low level sampling
This commit is contained in:
@@ -35,10 +35,12 @@
|
||||
float vbus_voltage = 12.0f;
|
||||
bool brake_resistor_armed = false;
|
||||
/* Private constant data -----------------------------------------------------*/
|
||||
static const GPIO_TypeDef* GPIOs_to_samp[] = { GPIOA, GPIOB, GPIOC };
|
||||
static const int num_GPIO = sizeof(GPIOs_to_samp) / sizeof(GPIOs_to_samp[0]);
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
// Two motors, sampling port A,B,C (coherent with current meas timing)
|
||||
static uint16_t GPIO_port_samples [2][3];
|
||||
static uint16_t GPIO_port_samples [2][num_GPIO];
|
||||
/* CPU critical section helpers ----------------------------------------------*/
|
||||
|
||||
static inline uint8_t cpu_enter_critical() {
|
||||
@@ -419,6 +421,22 @@ void pwm_trig_adc_cb(ADC_HandleTypeDef* hadc, bool injected) {
|
||||
}
|
||||
}
|
||||
|
||||
void tim_update_cb(TIM_HandleTypeDef* htim) {
|
||||
int portsamples_arr;
|
||||
if (htim == &htim1) {
|
||||
portsamples_arr = 0;
|
||||
} else if (htim == &htim8) {
|
||||
portsamples_arr = 1;
|
||||
} else {
|
||||
low_level_fault(Motor::ERROR_UNEXPECTED_TIMER_CALLBACK);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_GPIO; ++i) {
|
||||
GPIO_port_samples[portsamples_arr][i] = GPIOs_to_samp[i]->IDR;
|
||||
}
|
||||
}
|
||||
|
||||
// @brief Sums up the Ibus contribution of each motor and updates the
|
||||
// brake resistor PWM accordingly.
|
||||
void update_brake_current() {
|
||||
|
||||
@@ -34,6 +34,7 @@ void safety_critical_apply_brake_resistor_timings(uint32_t low_off, uint32_t hig
|
||||
extern "C" {
|
||||
void pwm_trig_adc_cb(ADC_HandleTypeDef* hadc, bool injected);
|
||||
void vbus_sense_adc_cb(ADC_HandleTypeDef* hadc, bool injected);
|
||||
void tim_update_cb(TIM_HandleTypeDef* htim);
|
||||
}
|
||||
|
||||
// Initalisation
|
||||
|
||||
@@ -63,7 +63,8 @@ public:
|
||||
ERROR_NOT_IMPLEMENTED_MOTOR_TYPE = 0x0020,
|
||||
ERROR_BRAKE_CURRENT_OUT_OF_RANGE = 0x0040,
|
||||
ERROR_NUMERICAL = 0x0080,
|
||||
ERROR_BRAKE_DEADTIME_VIOLATION = 0x0100
|
||||
ERROR_BRAKE_DEADTIME_VIOLATION = 0x0100,
|
||||
ERROR_UNEXPECTED_TIMER_CALLBACK = 0x0200
|
||||
};
|
||||
|
||||
enum TimingLog_t {
|
||||
|
||||
Reference in New Issue
Block a user