implement low level sampling

This commit is contained in:
Oskar Weigl
2018-04-26 16:08:39 -07:00
parent f9a5763f15
commit 8ac49bfe6e
3 changed files with 22 additions and 2 deletions
+19 -1
View File
@@ -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() {
+1
View File
@@ -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
+2 -1
View File
@@ -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 {