frontend adc stuff
This commit is contained in:
13
cube/User/Inc/frontend.h
Normal file
13
cube/User/Inc/frontend.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef _FRONTEND_H_
|
||||
#define _FRONTEND_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <adc.h>
|
||||
|
||||
|
||||
void frontendInit();
|
||||
void frontendAdcCallback(ADC_HandleTypeDef* hadc);
|
||||
void frontendEnable();
|
||||
void frontendDisable();
|
||||
|
||||
#endif // _FRONTEND_H_
|
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);
|
||||
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <main.h>
|
||||
#include <usart.h>
|
||||
#include <adc.h>
|
||||
|
||||
#include <PontCoopScheduler.h>
|
||||
|
||||
@ -12,11 +13,13 @@
|
||||
#include <loopCtrl.h>
|
||||
#include <mbusComm.h>
|
||||
#include <logger.h>
|
||||
#include <frontend.h>
|
||||
|
||||
|
||||
void my_setup_1() {
|
||||
schInit();
|
||||
logInit();
|
||||
// frontendInit();
|
||||
}
|
||||
|
||||
void my_errorHandler() {
|
||||
@ -35,7 +38,7 @@ void my_setup_2() {
|
||||
led(RED, OFF);
|
||||
led(GREEN, ON);
|
||||
|
||||
schAdd(helloMeterbus, NULL, 0, 2000);
|
||||
schAdd(helloMeterbus, NULL, 0, 10000);
|
||||
}
|
||||
|
||||
void my_loop() {
|
||||
@ -52,3 +55,10 @@ void HAL_GPIO_EXTI_Callback(uint16_t pin) {
|
||||
loopStatusCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||
if (hadc == &frontendAdc) {
|
||||
frontendAdcCallback(hadc);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user