Skip to content
Snippets Groups Projects
Commit 0463e9ae authored by Thomas Walter's avatar Thomas Walter Committed by Clément Foucher
Browse files

[ADD] Update calibration coefficient via serial port

Add the functionnality to change the dataAcquisition parameters (gain, offset) via the serial port.
parent fcd6654d
No related branches found
No related tags found
1 merge request!53[ADD] Update calibration coefficient via serial port
......@@ -4,5 +4,6 @@ config OWNTECH_DATA_ACQUISITION
select DMA
depends on OWNTECH_ADC_DRIVER
depends on OWNTECH_HRTIM_DRIVER
depends on CONSOLE_GETCHAR
# Force-select the following to avoid dependency loop
select OWNTECH_SCHEDULING
......@@ -28,8 +28,13 @@
/////
// Include
// Zephyr
#include <zephyr.h>
#include <console/console.h>
// Stdlib
#include <stdlib.h>
// Current file header
#include "data_conversion.h"
......@@ -59,6 +64,67 @@ static float32_t offset_temperature = 0.0;
static float32_t gain_analog_comm = 1.0;
static float32_t offset_analog_comm = 0.0;
//Maximum number of number for gain and offset value
static const uint8_t MaxCharInOneLine = 20;
/////
// Private Functions
float32_t get_calibration_coefficients(const char* physicalParameter,const char* gainOrOffset)
{
uint8_t carcount;
char received_char;
char line[MaxCharInOneLine];//number of character in one line
float32_t parameterCoefficient;
do
{
//Initializing variables for eventual loop
carcount = 0;
printk("Type %s %s and press enter \n", physicalParameter, gainOrOffset);
do
{
received_char = console_getchar();
line[carcount] = received_char;
if(received_char == 0x08)//backspace character
{
if(carcount>0)//To avoid carcount being negative
carcount--;
}
else
{
carcount++;
}
printk("%c", received_char);//echoing value
if(carcount>=(MaxCharInOneLine-1))
{
printk("Maximum caracter allowed reached \n");
break;
}
} while ((received_char!='\n')); // EOL char : CRLF
line[carcount-2] = '\0'; // adding end of tab character to prepare for atof function
//Converting string to float
parameterCoefficient = atof(line);
//Getting confirmation
printk("%s %s applied will be : %f\n", physicalParameter, gainOrOffset, parameterCoefficient);
//Getting validation
printk("Press y to validate, any other character to retype the %s \n", gainOrOffset);
received_char = console_getchar();
}while(received_char != 'y');
return parameterCoefficient;
}
/////
// Public Functions
......@@ -170,3 +236,47 @@ void data_conversion_set_analog_comm_parameters(float32_t gain, float32_t offset
gain_analog_comm = gain;
offset_analog_comm = offset;
}
void set_default_acquisition_parameters()
{
float32_t gains[] = {1, 1, 1, 1, 1, 1};
float32_t offsets[] = {0, 0, 0, 0, 0, 0};
data_conversion_set_v_high_parameters(gains[0], offsets[0]);
data_conversion_set_v1_low_parameters(gains[1], offsets[1]);
data_conversion_set_v2_low_parameters(gains[2], offsets[2]);
data_conversion_set_i_high_parameters(gains[3], offsets[3]);
data_conversion_set_i1_low_parameters(gains[4], offsets[4]);
data_conversion_set_i2_low_parameters(gains[5], offsets[5]);
printk("Calibration gains set to default !\n");
}
void set_user_acquisition_parameters()
{
static float32_t gains[6];//VH, V1, V2, IH, I1, I2
static float32_t offsets[6];//VH, V1, V2, IH, I1, I2
gains[0] = get_calibration_coefficients("VHigh", "gain");
gains[1] = get_calibration_coefficients("V1Low", "gain");
gains[2] = get_calibration_coefficients("V2Low", "gain");
gains[3] = get_calibration_coefficients("I2Low", "gain");
gains[4] = get_calibration_coefficients("IHigh", "gain");
gains[5] = get_calibration_coefficients("I1Low", "gain");
offsets[0] = get_calibration_coefficients("VHigh", "offset");
offsets[1] = get_calibration_coefficients("V1Low", "offset");
offsets[2] = get_calibration_coefficients("V2Low", "offset");
offsets[3] = get_calibration_coefficients("I2Low", "offset");
offsets[4] = get_calibration_coefficients("IHigh", "offset");
offsets[5] = get_calibration_coefficients("I1Low", "offset");
data_conversion_set_v_high_parameters(gains[0], offsets[0]);
data_conversion_set_v1_low_parameters(gains[1], offsets[1]);
data_conversion_set_v2_low_parameters(gains[2], offsets[2]);
data_conversion_set_i_high_parameters(gains[3], offsets[3]);
data_conversion_set_i1_low_parameters(gains[4], offsets[4]);
data_conversion_set_i2_low_parameters(gains[5], offsets[5]);
printk("Calibration coefficients updated !\n");
}
\ No newline at end of file
......@@ -22,6 +22,7 @@
* @author Antoine Boche <antoine.boche@laas.fr>
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Luiz Villa <luiz.villa@laas.fr>
* @author Thomas Walter <thomas.walter@laas.fr>
*/
#ifndef DATA_CONVERSION_H_
......@@ -186,5 +187,14 @@ void data_conversion_set_extra_parameters(float32_t gain, float32_t offset);
*/
void data_conversion_set_analog_comm_parameters(float32_t gain, float32_t offset);
/**
* @brief Set calibration coefficients of all gains to 1 and all offsets to 0
*/
void set_default_acquisition_parameters();
/**
* @brief Retrieve calibration coefficients via console input and update them
*/
void set_user_acquisition_parameters();
#endif // DATA_CONVERSION_H_
......@@ -22,6 +22,7 @@
*
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Luiz Villa <luiz.villa@laas.fr>
* @author Thomas Walter <thomas.walter@laas.fr>
*/
......@@ -477,3 +478,13 @@ void DataAcquisition::_setParameters(channel_assignment_t assignment, float32_t
{
assignment.set_parameters(gain, offset);
}
void DataAcquisition::setDefaultCalibrationFactors(void)
{
set_default_acquisition_parameters();
}
void DataAcquisition::setUserCalibrationFactors(void)
{
set_user_acquisition_parameters();
}
\ No newline at end of file
......@@ -21,6 +21,7 @@
* @date 2023
*
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Thomas Walter <thomas.walter@laas.fr>
*/
......@@ -265,6 +266,17 @@ public:
void setAnalogCommParameters(float32_t gain, float32_t offset);
///@}
/**
* @brief Init default gain and offset structures for all ADCs and
* sets these default parameters.
*/
void setDefaultCalibrationFactors(void);
/**
* @brief Retrieve stored parameters from Flash memory and configure ADC parameters
*/
void setUserCalibrationFactors(void);
private:
/**
* Internal types definitions.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment