Commit c5ffce57 authored by Clément Foucher's avatar Clément Foucher
Browse files

Use the new Data Acquisition API.

Proceed to modules configuration here so that the specific needs of this library are fully controlled.
parent 38c0b236
{
"name": "opalib_pid_current_mode",
"version": "1.0.0",
"version": "1.1.0",
"description": "OwnTech Power API Library for PID in current mode.",
"keywords": "OwnTech Power API"
}
......@@ -24,9 +24,11 @@
// Owntech modules
#include "data_acquisition.h"
#include "hrtim.h"
#include "data_acquisition.h"
#include "comparator.h"
#include "dac.h"
static const struct device* dac1 = NULL;
static const struct device* dac3 = NULL;
......@@ -49,47 +51,44 @@ static uint32_t reset_value;
/////
// Private functions
void _opalib_pid_current_acquire_dac_values()
static void _opalib_pid_current_acquire_dac_values()
{
static uint32_t v1LowRaw = 0;
static uint32_t v2LowRaw = 0;
static uint32_t vHighRaw = 0;
static uint32_t iHighRaw = 0;
uint32_t v1_low_count;
uint32_t v2_low_count;
uint32_t v_high_count;
uint32_t i_high_count;
// I
while (data_dispatch_get_values_available_in_adc1_channel(0) != 0)
{
// Ignore I1-low, just empty the buffer
data_dispatch_get_next_value_from_adc1_channel(0);
}
while (data_dispatch_get_values_available_in_adc1_channel(1) != 0)
{
// Ignore I2-low, just empty the buffer
data_dispatch_get_next_value_from_adc1_channel(1);
}
while (data_dispatch_get_values_available_in_adc1_channel(2) != 0)
uint16_t* i_high_buffer = data_acquisition_get_i_high_values(&i_high_count);
if (i_high_count > 0)
{
// Acquire latest I-high data
iHighRaw = data_dispatch_get_next_value_from_adc1_channel(2);
iHighRaw = i_high_buffer[i_high_count-1];
}
// V
while (data_dispatch_get_values_available_in_adc2_channel(0) != 0)
uint16_t* v1_low_buffer = data_acquisition_get_v1_low_values(&v1_low_count);
uint16_t* v2_low_buffer = data_acquisition_get_v2_low_values(&v2_low_count);
uint16_t* v_high_buffer = data_acquisition_get_v_high_values(&v_high_count);
if (v1_low_count > 0)
{
// Acquire latest V1-low data
v1LowRaw = data_dispatch_get_next_value_from_adc2_channel(0);
v1LowRaw = v1_low_buffer[v1_low_count-1];
}
while (data_dispatch_get_values_available_in_adc2_channel(1) != 0)
if (v2_low_count > 0)
{
// Acquire latest V2-low data
v2LowRaw = data_dispatch_get_next_value_from_adc2_channel(1);
v2LowRaw = v2_low_buffer[v2_low_count-1];
}
while (data_dispatch_get_values_available_in_adc2_channel(2) != 0)
if (v_high_count > 0)
{
// Acquire latest V-high data
vHighRaw = data_dispatch_get_next_value_from_adc2_channel(2);
vHighRaw = v_high_buffer[v_high_count-1];
}
/////
......@@ -160,6 +159,44 @@ static void _opalib_pid_current_update_reset_value()
void opalib_pid_current_init(double setpoint, double p_i, double i_i, double d_i)
{
uint8_t init_status;
/////
// Data acquisition
data_acquisition_init();
char* adc1_channels[] =
{
"I_HIGH"
};
char* adc2_channels[] =
{
"V1_LOW",
"V2_LOW",
"V_HIGH"
};
init_status = data_acquisition_configure_adc_channels(1, adc1_channels, 1);
__ASSERT( (init_status == 0), "ERROR: ADC 1 channel configuration went wrong!");
init_status = data_acquisition_configure_adc_channels(2, adc2_channels, 3);
__ASSERT( (init_status == 0), "ERROR: ADC 2 channel configuration went wrong!");
data_acquisition_set_adc12_dual_mode(true);
data_acquisition_configure_adc_trigger_source(1, LL_ADC_REG_TRIG_EXT_HRTIM_TRG1);
// Comparator
comparator_init();
// HRTIM
hrtim_init_current();
// DAC
owntech_dac_dac2_constant_init();
owntech_dac_dac1_dac3_current_mode_init();
// Set local variables
dac1 = device_get_binding(DAC1_LABEL);
dac3 = device_get_binding(DAC3_LABEL);
......@@ -167,6 +204,8 @@ void opalib_pid_current_init(double setpoint, double p_i, double i_i, double d_i
p = p_i;
i = i_i;
d = d_i;
data_acquisition_start();
}
void opalib_pid_current_update_setpoint(double setpoint)
......
Markdown is supported
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