frontend adc stuff
This commit is contained in:
49
cube/User/Src/frontend.c
Normal file
49
cube/User/Src/frontend.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <main.h>
|
||||
#include <adc.h>
|
||||
|
||||
#include <frontend.h>
|
||||
|
||||
#include <logger.h>
|
||||
|
||||
|
||||
|
||||
static const double SHUNT_RESISTOR = 20.0;
|
||||
static const double U_REF = 3.3;
|
||||
static const double I_THRESHOLD = 0.005;
|
||||
static const uint16_t N_MAX = 4095;
|
||||
|
||||
|
||||
|
||||
static volatile uint16_t frontendAdcThreshold = 0;
|
||||
static volatile bool frontendEnabled = false;
|
||||
|
||||
|
||||
void frontendInit() {
|
||||
double u_threshold = I_THRESHOLD * SHUNT_RESISTOR;
|
||||
frontendAdcThreshold = (uint16_t) (u_threshold / U_REF * ((double) N_MAX));
|
||||
logMsg("frontendInit, threshold calculated: %d", frontendAdcThreshold);
|
||||
|
||||
HAL_ADCEx_Calibration_Start(&frontendAdc);
|
||||
logMsg("frontendInit, calibration done");
|
||||
HAL_ADC_Start_IT(&frontendAdc);
|
||||
logMsg("frontendInit, adc started");
|
||||
}
|
||||
|
||||
void frontendSetThreshold(uint16_t threshold) {
|
||||
frontendAdcThreshold = threshold;
|
||||
}
|
||||
|
||||
void frontendEnable() {
|
||||
frontendEnabled = true;
|
||||
}
|
||||
|
||||
void frontendDisable() {
|
||||
frontendEnabled = false;
|
||||
}
|
||||
|
||||
void frontendAdcCallback(ADC_HandleTypeDef* hadc) {
|
||||
uint16_t rawValue = HAL_ADC_GetValue(hadc);
|
||||
|
||||
}
|
Reference in New Issue
Block a user