Commit fc44113b authored by Luiz Fernando Lavado Villa's avatar Luiz Fernando Lavado Villa 💬
Browse files

The O² board lacks an extra analog input, which is quite useful for interfacing with sensors.

parent e1fb48bf
......@@ -73,6 +73,11 @@
label = "I_HIGH";
};
extra-meas-adc2 {
io-channels = <&adc2 5>;
label = "EXTRA_MEAS";
};
/* Temperature channel */
/*
temp-sensor {
......
......@@ -168,7 +168,7 @@
};
&adc2 {
pinctrl-0 = <&adc2_in1_pa0 &adc2_in2_pa1 &adc2_in3_pa6>;
pinctrl-0 = <&adc2_in1_pa0 &adc2_in2_pa1 &adc2_in3_pa6 &adc2_in5_pc4>;
status = "okay";
};
......
......@@ -46,8 +46,12 @@ static float32_t offset_currents[3] = {25.9, 29.28, 0}; //i1_low, i2_low o
static float32_t gain_voltages[3] = {0.0462, 0.0462, 0.0640}; //v1_low, v2_low and v_high
static float32_t offset_voltages[3] = {94.04, 94.04, 4.408}; //v1_low, v2_low and v_high
static float32_t gain_extra = 1.0; //gain for the extra
static float32_t offset_extra = 1.0; //offset for the extra
// Temperature
static float32_t gain_temperature = 0.0;
static float32_t gain_temperature = 1.0;
static float32_t offset_temperature = 0.0;
......@@ -93,6 +97,11 @@ float32_t data_conversion_convert_temp(uint16_t raw_value)
return (raw_value*gain_temperature)+offset_temperature;
}
float32_t data_conversion_convert_extra(uint16_t raw_value)
{
return (raw_value*gain_extra)+offset_extra;
}
/**
......@@ -139,3 +148,9 @@ void data_conversion_set_temp_parameters(float32_t gain, float32_t offset)
gain_temperature = gain;
offset_temperature = offset;
}
void data_conversion_set_extra_parameters(float32_t gain, float32_t offset)
{
gain_extra = gain;
offset_extra = offset;
}
......@@ -97,6 +97,14 @@ float32_t data_conversion_convert_i_high(uint16_t raw_value);
*/
float32_t data_conversion_convert_temp(uint16_t raw_value);
/**
* @brief Converts the values of the extra parameter into a physical unit
*
* @param[in] raw_value
*
* @return a foat32_t value for the extra measurement
*/
float32_t data_conversion_convert_extra(uint16_t raw_value);
/**
......@@ -155,6 +163,14 @@ void data_conversion_set_i_high_parameters(float32_t gain, float32_t offset);
*/
void data_conversion_set_temp_parameters(float32_t gain, float32_t offset);
/**
* @brief Change the parameters for the extra measurement
*
* @param[in] gain gain of temp sensor
* @param[in] offset offset of the sensor
*/
void data_conversion_set_extra_parameters(float32_t gain, float32_t offset);
#ifdef __cplusplus
}
......
......@@ -56,6 +56,7 @@ DataAcquisition::channel_assignment_t DataAcquisition::i1_low_assignement =
DataAcquisition::channel_assignment_t DataAcquisition::i2_low_assignement = {0};
DataAcquisition::channel_assignment_t DataAcquisition::i_high_assignement = {0};
DataAcquisition::channel_assignment_t DataAcquisition::temp_sensor_assignement = {0};
DataAcquisition::channel_assignment_t DataAcquisition::extra_sensor_assignement = {0};
/////
......@@ -98,6 +99,11 @@ void DataAcquisition::setChannnelAssignment(uint8_t adc_number, const char* cha
temp_sensor_assignement.adc_number = adc_number;
temp_sensor_assignement.channel_rank = channel_rank;
}
else if (strcmp(channel_name, "EXTRA_MEAS") == 0)
{
extra_sensor_assignement.adc_number = adc_number;
extra_sensor_assignement.channel_rank = channel_rank;
}
}
void DataAcquisition::start()
......@@ -174,6 +180,12 @@ uint16_t* DataAcquisition::getTemperatureRawValues(uint32_t& number_of_values_ac
return data_dispatch_get_acquired_values(temp_sensor_assignement.adc_number, temp_sensor_assignement.channel_rank, &number_of_values_acquired);
}
uint16_t* DataAcquisition::getExtraRawValues(uint32_t& number_of_values_acquired)
{
return data_dispatch_get_acquired_values(extra_sensor_assignement.adc_number, extra_sensor_assignement.channel_rank, &number_of_values_acquired);
}
float32_t DataAcquisition::getV1Low()
{
uint32_t data_count;
......@@ -279,6 +291,22 @@ float32_t DataAcquisition::getTemperature()
return converted_data;
}
float32_t DataAcquisition::getExtra()
{
uint32_t data_count;
static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet
uint16_t* buffer = getExtraRawValues(data_count);
if (data_count > 0) // If data was received it gets converted
{
uint16_t raw_value = buffer[data_count - 1];
converted_data = data_conversion_convert_extra(raw_value);
}
return converted_data;
}
float32_t DataAcquisition::convertV1Low(uint16_t raw_value)
{
return data_conversion_convert_v1_low(raw_value);
......@@ -314,6 +342,11 @@ float32_t DataAcquisition::convertTemperature(uint16_t raw_value)
return data_conversion_convert_temp(raw_value);
}
float32_t DataAcquisition::convertExtra(uint16_t raw_value)
{
return data_conversion_convert_extra(raw_value);
}
void DataAcquisition::setV1LowParameters(float32_t gain, float32_t offset)
{
......@@ -349,3 +382,8 @@ void DataAcquisition::setTemperatureParameters(float32_t gain, float32_t offset)
{
data_conversion_set_temp_parameters(gain, offset);
}
void DataAcquisition::setExtraParameters(float32_t gain, float32_t offset)
{
data_conversion_set_extra_parameters(gain, offset);
}
......@@ -100,6 +100,7 @@ public:
static uint16_t* getI2LowRawValues(uint32_t& number_of_values_acquired);
static uint16_t* getIHighRawValues(uint32_t& number_of_values_acquired);
static uint16_t* getTemperatureRawValues(uint32_t& number_of_values_acquired);
static uint16_t* getExtraRawValues(uint32_t& number_of_values_acquired);
/**
* These functions return the latest acquired measure expressed
......@@ -118,6 +119,7 @@ public:
static float32_t getI2Low();
static float32_t getIHigh();
static float32_t getTemperature();
static float32_t getExtra();
/**
* Use these functions to convert values obtained using
......@@ -131,6 +133,7 @@ public:
static float32_t convertI2Low(uint16_t raw_value);
static float32_t convertIHigh(uint16_t raw_value);
static float32_t convertTemperature(uint16_t raw_value);
static float32_t convertExtra(uint16_t raw_value);
/**
* Use these functions to tweak the conversion values for
......@@ -143,6 +146,7 @@ public:
static void setVHighParameters(float32_t gain, float32_t offset);
static void setIHighParameters(float32_t gain, float32_t offset);
static void setTemperatureParameters(float32_t gain, float32_t offset);
static void setExtraParameters(float32_t gain, float32_t offset);
private:
......@@ -162,6 +166,7 @@ private:
static channel_assignment_t i2_low_assignement;
static channel_assignment_t i_high_assignement;
static channel_assignment_t temp_sensor_assignement;
static channel_assignment_t extra_sensor_assignement;
};
......
......@@ -329,6 +329,11 @@ void HardwareConfiguration::configureAdcDefaultAllMeasurements()
configure_adc_default_all_measurements();
}
void HardwareConfiguration::configureAdcDefaultAllMeasurementsAndExtra()
{
configure_adc_default_all_measurements_and_extra();
}
void HardwareConfiguration::setLeg1DeadTime(uint16_t rise_ns, uint16_t fall_ns)
{
......
......@@ -142,6 +142,7 @@ public:
static void configureAdcTriggerSource(uint8_t adc_number, adc_ev_src_t trigger_source);
static void configureAdcDiscontinuousMode(uint8_t adc_number, uint32_t dicontinuous_count);
static void configureAdcDefaultAllMeasurements();
static void configureAdcDefaultAllMeasurementsAndExtra();
};
......
......@@ -150,3 +150,28 @@ void configure_adc_default_all_measurements()
configure_adc_channels(1, adc1_channels, number_of_channels_adc1);
configure_adc_channels(2, adc2_channels, number_of_channels_adc2);
}
void configure_adc_default_all_measurements_and_extra()
{
uint8_t number_of_channels_adc1 = 3;
uint8_t number_of_channels_adc2 = 4;
const char* adc1_channels[] =
{
"I1_LOW",
"V1_LOW",
"V_HIGH"
};
const char* adc2_channels[] =
{
"I2_LOW",
"V2_LOW",
"I_HIGH",
"EXTRA_MEAS"
};
configure_adc_channels(1, adc1_channels, number_of_channels_adc1);
configure_adc_channels(2, adc2_channels, number_of_channels_adc2);
}
......@@ -104,4 +104,17 @@ void configure_adc_discontinuous_mode(uint8_t adc_number, uint32_t dicontinuous_
void configure_adc_default_all_measurements();
/**
* This function is used to configure all ADC channels in default configuration.
* Channels will be attributed as follows:
* ADC1 - V1_LOW ADC2 - I1_LOW
* V2_LOW I2_LOW
* V_HIGH I_HIGH
* EXTRA_MEAS
*
* This function must be called BEFORE ADC is started.
*/
void configure_adc_default_all_measurements_and_extra();
#endif // ADC_CONFIGURATION_H_
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment