frontend adc stuff
This commit is contained in:
parent
877dd0fca3
commit
95af24a12a
@ -60,6 +60,7 @@ void Error_Handler(void);
|
|||||||
/* Private defines -----------------------------------------------------------*/
|
/* Private defines -----------------------------------------------------------*/
|
||||||
#define debugUart huart4
|
#define debugUart huart4
|
||||||
#define mbusUart huart5
|
#define mbusUart huart5
|
||||||
|
#define frontendAdc hadc1
|
||||||
#define Loop_Enable_Pin GPIO_PIN_2
|
#define Loop_Enable_Pin GPIO_PIN_2
|
||||||
#define Loop_Enable_GPIO_Port GPIOE
|
#define Loop_Enable_GPIO_Port GPIOE
|
||||||
#define Loop_Disable_Pin GPIO_PIN_3
|
#define Loop_Disable_Pin GPIO_PIN_3
|
||||||
|
@ -57,6 +57,7 @@ void DebugMon_Handler(void);
|
|||||||
void PendSV_Handler(void);
|
void PendSV_Handler(void);
|
||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
void EXTI4_IRQHandler(void);
|
void EXTI4_IRQHandler(void);
|
||||||
|
void ADC1_2_IRQHandler(void);
|
||||||
void UART4_IRQHandler(void);
|
void UART4_IRQHandler(void);
|
||||||
void UART5_IRQHandler(void);
|
void UART5_IRQHandler(void);
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
@ -35,7 +35,7 @@ void MX_ADC1_Init(void)
|
|||||||
*/
|
*/
|
||||||
hadc1.Instance = ADC1;
|
hadc1.Instance = ADC1;
|
||||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||||
hadc1.Init.ContinuousConvMode = DISABLE;
|
hadc1.Init.ContinuousConvMode = ENABLE;
|
||||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||||
@ -76,6 +76,9 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
|||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||||
HAL_GPIO_Init(Frontend_In_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(Frontend_In_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* ADC1 interrupt Init */
|
||||||
|
HAL_NVIC_SetPriority(ADC1_2_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspInit 1 */
|
/* USER CODE END ADC1_MspInit 1 */
|
||||||
@ -98,6 +101,8 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
|||||||
*/
|
*/
|
||||||
HAL_GPIO_DeInit(Frontend_In_GPIO_Port, Frontend_In_Pin);
|
HAL_GPIO_DeInit(Frontend_In_GPIO_Port, Frontend_In_Pin);
|
||||||
|
|
||||||
|
/* ADC1 interrupt Deinit */
|
||||||
|
HAL_NVIC_DisableIRQ(ADC1_2_IRQn);
|
||||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspDeInit 1 */
|
/* USER CODE END ADC1_MspDeInit 1 */
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/* External variables --------------------------------------------------------*/
|
/* External variables --------------------------------------------------------*/
|
||||||
|
extern ADC_HandleTypeDef hadc1;
|
||||||
extern UART_HandleTypeDef huart4;
|
extern UART_HandleTypeDef huart4;
|
||||||
extern UART_HandleTypeDef huart5;
|
extern UART_HandleTypeDef huart5;
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
@ -217,6 +218,20 @@ void EXTI4_IRQHandler(void)
|
|||||||
/* USER CODE END EXTI4_IRQn 1 */
|
/* USER CODE END EXTI4_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles ADC1 and ADC2 global interrupts.
|
||||||
|
*/
|
||||||
|
void ADC1_2_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN ADC1_2_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END ADC1_2_IRQn 0 */
|
||||||
|
HAL_ADC_IRQHandler(&hadc1);
|
||||||
|
/* USER CODE BEGIN ADC1_2_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END ADC1_2_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles UART4 global interrupt.
|
* @brief This function handles UART4 global interrupt.
|
||||||
*/
|
*/
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/* External variables --------------------------------------------------------*/
|
/* External variables --------------------------------------------------------*/
|
||||||
|
extern ADC_HandleTypeDef hadc1;
|
||||||
extern UART_HandleTypeDef huart4;
|
extern UART_HandleTypeDef huart4;
|
||||||
extern UART_HandleTypeDef huart5;
|
extern UART_HandleTypeDef huart5;
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
@ -212,6 +213,20 @@ void EXTI4_IRQHandler(void)
|
|||||||
/* USER CODE END EXTI4_IRQn 1 */
|
/* USER CODE END EXTI4_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles ADC1 and ADC2 global interrupts.
|
||||||
|
*/
|
||||||
|
void ADC1_2_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN ADC1_2_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END ADC1_2_IRQn 0 */
|
||||||
|
HAL_ADC_IRQHandler(&hadc1);
|
||||||
|
/* USER CODE BEGIN ADC1_2_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END ADC1_2_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles UART4 global interrupt.
|
* @brief This function handles UART4 global interrupt.
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Processed by ../tools/insertMyCode.sh
|
# Processed by ../tools/insertMyCode.sh
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Oct 29 22:51:14 CET 2020]
|
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sat Oct 31 20:50:19 CET 2020]
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
@ -37,7 +37,7 @@ BUILD_DIR = build
|
|||||||
######################################
|
######################################
|
||||||
# C sources
|
# C sources
|
||||||
C_SOURCES = \
|
C_SOURCES = \
|
||||||
User/Src/led.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c hottislib/PontCoopScheduler.c \
|
User/Src/frontend.c User/Src/led.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c hottislib/PontCoopScheduler.c \
|
||||||
Core/Src/main.c \
|
Core/Src/main.c \
|
||||||
Core/Src/gpio.c \
|
Core/Src/gpio.c \
|
||||||
Core/Src/adc.c \
|
Core/Src/adc.c \
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Oct 29 22:51:14 CET 2020]
|
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sat Oct 31 20:50:19 CET 2020]
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
|
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 <main.h>
|
||||||
#include <usart.h>
|
#include <usart.h>
|
||||||
|
#include <adc.h>
|
||||||
|
|
||||||
#include <PontCoopScheduler.h>
|
#include <PontCoopScheduler.h>
|
||||||
|
|
||||||
@ -12,11 +13,13 @@
|
|||||||
#include <loopCtrl.h>
|
#include <loopCtrl.h>
|
||||||
#include <mbusComm.h>
|
#include <mbusComm.h>
|
||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
|
#include <frontend.h>
|
||||||
|
|
||||||
|
|
||||||
void my_setup_1() {
|
void my_setup_1() {
|
||||||
schInit();
|
schInit();
|
||||||
logInit();
|
logInit();
|
||||||
|
// frontendInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_errorHandler() {
|
void my_errorHandler() {
|
||||||
@ -35,7 +38,7 @@ void my_setup_2() {
|
|||||||
led(RED, OFF);
|
led(RED, OFF);
|
||||||
led(GREEN, ON);
|
led(GREEN, ON);
|
||||||
|
|
||||||
schAdd(helloMeterbus, NULL, 0, 2000);
|
schAdd(helloMeterbus, NULL, 0, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_loop() {
|
void my_loop() {
|
||||||
@ -52,3 +55,10 @@ void HAL_GPIO_EXTI_Callback(uint16_t pin) {
|
|||||||
loopStatusCallback();
|
loopStatusCallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||||
|
if (hadc == &frontendAdc) {
|
||||||
|
frontendAdcCallback(hadc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#MicroXplorer Configuration settings - do not modify
|
#MicroXplorer Configuration settings - do not modify
|
||||||
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_1
|
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_1
|
||||||
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,master,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag
|
ADC1.ContinuousConvMode=ENABLE
|
||||||
|
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,master,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,ContinuousConvMode,NbrOfConversion
|
||||||
|
ADC1.NbrOfConversion=1
|
||||||
ADC1.NbrOfConversionFlag=1
|
ADC1.NbrOfConversionFlag=1
|
||||||
ADC1.Rank-0\#ChannelRegularConversion=1
|
ADC1.Rank-0\#ChannelRegularConversion=1
|
||||||
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_1CYCLE_5
|
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_1CYCLE_5
|
||||||
@ -44,10 +46,11 @@ Mcu.Pin8=PB13
|
|||||||
Mcu.Pin9=PB14
|
Mcu.Pin9=PB14
|
||||||
Mcu.PinsNb=22
|
Mcu.PinsNb=22
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=debugUart,huart4;mbusUart,huart5
|
Mcu.UserConstants=debugUart,huart4;mbusUart,huart5;frontendAdc,hadc1
|
||||||
Mcu.UserName=STM32F103VCTx
|
Mcu.UserName=STM32F103VCTx
|
||||||
MxCube.Version=6.0.0
|
MxCube.Version=6.0.0
|
||||||
MxDb.Version=DB.6.0.0
|
MxDb.Version=DB.6.0.0
|
||||||
|
NVIC.ADC1_2_IRQn=true\:0\:0\:false\:false\:true\:true\:true
|
||||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||||
NVIC.EXTI4_IRQn=true\:0\:0\:false\:false\:true\:true\:true
|
NVIC.EXTI4_IRQn=true\:0\:0\:false\:false\:true\:true\:true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user