Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
dev_current_sensor.c
Go to the documentation of this file.
1
2
9#include <stdbool.h>
10#include "config/macros.h"
11#include "adc/adc1.h"
12
13#define SENSOR_OFFSET_NUM_MEASUREMENTS (1000)
14
15
23{
24 uint32_t Accumulator;
26 uint16_t Offset;
28 uint16_t LimitHigh;
29 uint16_t LimitLow;
30};
32
33
41 .Accumulator = 0,
42 .MeasurementCounter = 0,
45
46
57static void __inline__ Dev_SensorOffsetCal(SENSOR_OFFSET_CAL_t* sensor, uint16_t adcReading)
58{
59 // current sensor offset is not measured
60 sensor->Accumulator += adcReading;
62 {
63 // average to determine the offset
64 uint16_t offset = (uint16_t) (__builtin_divud(sensor->Accumulator, sensor->MeasurementCounter));
65
66 sensor->Accumulator = 0;
67 sensor->MeasurementCounter = 0;
68
69 // check if result is within acceptable limits
70 if ((offset < sensor->LimitHigh) && (offset > sensor->LimitLow))
71 {
72 // measured offset is reasonable. Update stored value and exit
73 sensor->Offset = offset;
74 sensor->CalibrationComplete = true;
75 }
76 }
77}
78
79
94
95
105
106
112{
114}
115
116
This is the generated driver header file for the ADC1 driver.
@ ISEC_AVG
Definition adc_types.h:63
#define SENSOR_OFFSET_NUM_MEASUREMENTS
Number of measurement to calculate the average over.
#define ISEC_AVG_SENSOR_OFFSET_LIMIT_LOW
Definition macros.h:84
#define ISEC_AVG_SENSOR_OFFSET_LIMIT_HIGH
Definition macros.h:83
static void __inline__ Dev_SensorOffsetCal(SENSOR_OFFSET_CAL_t *sensor, uint16_t adcReading)
Measure the sensor offset.
uint16_t Dev_CurrentSensor_Get_CalibrationStatus(void)
API function to get the calibration status.
void Dev_CurrentSensor_Clr_Offset(void)
API function to clear the sensor offset.
uint16_t Dev_CurrentSensor_Get_Offset(void)
API function to get the sensor offset.
void Dev_CurrentSensorOffsetCal(void)
Measures the currents sensor offset.
SENSOR_OFFSET_CAL_t isecAvgCurrentSensor
Data Object of sensor offset calibration.
static uint16_t ADC1_ConversionResultGet(enum ADC_CHANNEL channel)
Returns the conversion value for the channel selected.
Definition adc1.h:178
Stores data related to sensor calibration, including data related to sensor offset.
uint32_t Accumulator
used for sensor offset measurement at startup
uint16_t LimitHigh
upper bound of what offset should be, offset needs to be < limitHigh and > limitLow for sensorCalibra...
uint16_t MeasurementCounter
used for sensor offset measurement at startup
uint16_t LimitLow
low bound of what offset should be
bool CalibrationComplete
set to true if the sensor is calibrated
uint16_t Offset
measured offset