enabled dimming over ADC input
This commit is contained in:
@@ -3,9 +3,15 @@
|
||||
#include "adc.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#define ADC_CONVERTED_DATA_BUFFER_SIZE ((uint32_t) 16) /* Size of array aADCxConvertedData[] */
|
||||
|
||||
#define TOTAL_ADC_CHANNELS 4
|
||||
#define ADC_HISTORY_SIZE 4
|
||||
#define ADC_BUFFER_SIZE (TOTAL_ADC_CHANNELS * ADC_HISTORY_SIZE)
|
||||
#define ADC_CONVERTED_DATA_BUFFER_SIZE ((uint32_t) ADC_BUFFER_SIZE) /* Size of array aADCxConvertedData[] */
|
||||
ALIGN_32BYTES (static uint16_t aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE]);
|
||||
|
||||
#define ADC_CHANNEL_DIMMER 1
|
||||
#define ADC_CHANNEL_BUS 3
|
||||
|
||||
static bool adcIsInitialized = false;
|
||||
|
||||
@@ -53,4 +59,34 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
/* Invalidate Data Cache to get the updated content of the SRAM on the second half of the ADC converted data buffer: 32 bytes */
|
||||
SCB_InvalidateDCache_by_Addr((uint32_t *) &aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE/2], ADC_CONVERTED_DATA_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float BSP_ADC_ReadValue( uint32_t channel, float factor) {
|
||||
if (!adcIsInitialized) {
|
||||
return 0;
|
||||
}
|
||||
// average the last 4 values of the dimmer ADC
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < ADC_HISTORY_SIZE; i++) {
|
||||
sum += aADCxConvertedData[channel + i * TOTAL_ADC_CHANNELS];
|
||||
}
|
||||
|
||||
|
||||
//convert raw ADC value to voltage
|
||||
float voltage = (float)sum / (float)ADC_HISTORY_SIZE / factor; // gemessan an sample pcb
|
||||
|
||||
return voltage;
|
||||
|
||||
}
|
||||
|
||||
float BSP_ADC_ReadDimmerValue() {
|
||||
return BSP_ADC_ReadValue(ADC_CHANNEL_DIMMER, 4319.619048);
|
||||
|
||||
}
|
||||
|
||||
|
||||
float BSP_ADC_ReadBusValue() {
|
||||
return BSP_ADC_ReadValue(ADC_CHANNEL_BUS, 4046.87186);
|
||||
}
|
||||
@@ -135,6 +135,9 @@ void BSP_POWER_FullPowerMode() {
|
||||
|
||||
BSP_GPIO_ClsOn();
|
||||
BSP_GPIO_PeriperalsOn();
|
||||
BSP_GPIO_RadioOn();
|
||||
BSP_ADC_Start();
|
||||
osDelay(10);
|
||||
StartPowerTasks();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user