Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • rruelland/core
  • afarahhass/core-hrtim
  • lflavado/tutorials
  • owntech/tutorials
  • jlabaisse/core
  • lflavado/core
  • cfoucher/core
  • owntech/power-api/core
8 results
Show changes
Commits on Source (3)
  • Ayoub Farah Hassan's avatar
    Current mode update · f64c74b2
    Ayoub Farah Hassan authored and Luiz Fernando Lavado Villa's avatar Luiz Fernando Lavado Villa committed
    This commit updates owntech modules to implement the current mode.
    
    ## Update of HRTIM module
    
    - Deleting unnecessary LL function generated by cubeMX, and replacing with clear functions.
    - The adc for leg2 was triggered previously by the timing unit's CMP4, this commit replace it with CMP3 as CMP4 is used for current mode.
    
    ## Update of DAC module 
    
    - Adding more trigger for sawtooth generation.
    - Adding "External and Internal" mode for DAC output mode.
    - Update dac_stm32_function_update_reset and dac_stm32_function_update_step to delete the lines disabling/enabling the DACs.
    
    ## Update of Comparator module
    
    - Comparator 1 is now linked to DAC3 and comparator 3 to DAC1.
    
    ## Update of Hardware Configuration module
    
    - Adding essential functions to set the current mode.
    - Adding comparator_configuration files, adding changes to cmake and Kconfig in hardware configuration to include the comparator drivers.
    f64c74b2
  • Thomas Walter's avatar
    Being able to change the instant of triggering of the ADC in center aligned. · fcd6654d
    Thomas Walter authored and Clément Foucher's avatar Clément Foucher committed
    I modified the function _hrtim_init_events_center_aligned in the hrtim_common.c so the triggering of the ADC is not on PER but on a comparator.
    ADC of leg 1 is now triggered by CMP3 (on TIMA) and leg 2 is triggered by CMP4 (on TIMC).
    
    Note : with this update, CMP3 and CMP4 are now unavailable.
    fcd6654d
  • Thomas Walter's avatar
    [ADD] Update calibration coefficient via serial port · 0463e9ae
    Thomas Walter authored and Clément Foucher's avatar Clément Foucher committed
    Add the functionnality to change the dataAcquisition parameters (gain, offset) via the serial port.
    0463e9ae
Showing
with 539 additions and 98 deletions
/*
* Copyright (c) 2021-2022 LAAS-CNRS
* Copyright (c) 2021-2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,8 +18,9 @@
*/
/**
* @date 2022
* @date 2023
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
......@@ -63,7 +64,7 @@ void comparator_gpio_init()
void comparator_comp1_init()
{
LL_COMP_ConfigInputs(COMP1, LL_COMP_INPUT_MINUS_DAC1_CH1, LL_COMP_INPUT_PLUS_IO1);
LL_COMP_ConfigInputs(COMP1, LL_COMP_INPUT_MINUS_DAC3_CH1, LL_COMP_INPUT_PLUS_IO1);
LL_COMP_SetInputHysteresis(COMP1, LL_COMP_HYSTERESIS_NONE);
LL_COMP_SetOutputPolarity(COMP1, LL_COMP_OUTPUTPOL_NONINVERTED);
LL_COMP_SetOutputBlankingSource(COMP1, LL_COMP_BLANKINGSRC_NONE);
......@@ -78,7 +79,7 @@ void comparator_comp1_init()
void comparator_comp3_init()
{
LL_COMP_ConfigInputs(COMP3, LL_COMP_INPUT_MINUS_DAC3_CH1, LL_COMP_INPUT_PLUS_IO2);
LL_COMP_ConfigInputs(COMP3, LL_COMP_INPUT_MINUS_DAC1_CH1, LL_COMP_INPUT_PLUS_IO2);
LL_COMP_SetInputHysteresis(COMP3, LL_COMP_HYSTERESIS_NONE);
LL_COMP_SetOutputPolarity(COMP3, LL_COMP_OUTPUTPOL_NONINVERTED);
LL_COMP_SetOutputBlankingSource(COMP3, LL_COMP_BLANKINGSRC_NONE);
......
/*
* Copyright (c) 2021-2022 LAAS-CNRS
* Copyright (c) 2021-2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,8 +18,9 @@
*/
/**
* @date 2022
* @date 2023
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
......@@ -62,7 +63,11 @@ typedef enum
typedef enum
{
hrtim_trig1,
hrtim_trig2
hrtim_trig2,
hrtim_trig3,
hrtim_trig4,
hrtim_trig5,
hrtim_trig6
} dac_trigger_t;
typedef struct
......@@ -78,7 +83,8 @@ typedef struct
typedef enum
{
dac_pin_internal,
dac_pin_external
dac_pin_external,
dac_pin_internal_and_external
} dac_pin_config_t;
/////
......@@ -152,7 +158,6 @@ static inline void dac_stop(const struct device* dev, uint8_t channel)
api->stop(dev, channel);
}
#ifdef __cplusplus
}
#endif
......
/*
* Copyright (c) 2021-2022 LAAS-CNRS
* Copyright (c) 2021-2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,9 +18,10 @@
*/
/**
* @date 2022
* @date 2023
*
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
......@@ -114,12 +115,44 @@ static void dac_stm32_set_function(const struct device* dev, uint8_t channel, co
{
reset_trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG2;
}
else if (function_config->reset_trigger_source == hrtim_trig3)
{
reset_trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG3;
}
else if (function_config->reset_trigger_source == hrtim_trig4)
{
reset_trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG4;
}
else if (function_config->reset_trigger_source == hrtim_trig5)
{
reset_trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG5;
}
else if (function_config->reset_trigger_source == hrtim_trig6)
{
reset_trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG6;
}
uint32_t step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG1;
if (function_config->step_trigger_source == hrtim_trig2)
{
step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG2;
}
else if (function_config->step_trigger_source == hrtim_trig3)
{
step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG3;
}
else if (function_config->step_trigger_source == hrtim_trig4)
{
step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG4;
}
else if (function_config->step_trigger_source == hrtim_trig5)
{
step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG5;
}
else if (function_config->step_trigger_source == hrtim_trig6)
{
step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG6;
}
uint32_t polarity = LL_DAC_SAWTOOTH_POLARITY_DECREMENT;
if (function_config->polarity == dac_polarity_increment)
......@@ -152,22 +185,7 @@ static void dac_stm32_function_update_reset(const struct device* dev, uint8_t ch
{
data->dac_config->function_config.reset_data = reset_data;
if (data->started[channel-1] == 1)
{
LL_DAC_Disable(dac_dev, dac_channel);
}
LL_DAC_SetWaveSawtoothResetData(dac_dev, dac_channel, reset_data);
if (data->started[channel-1] == 1)
{
LL_DAC_Enable(dac_dev, dac_channel);
while (LL_DAC_IsReady(dac_dev, dac_channel) == 0)
{
// Wait
}
}
}
}
......@@ -182,22 +200,7 @@ static void dac_stm32_function_update_step(const struct device* dev, uint8_t cha
{
data->dac_config->function_config.step_data = step_data;
if (data->started[channel-1] == 1)
{
LL_DAC_Disable(dac_dev, dac_channel);
}
LL_DAC_SetWaveSawtoothStepData(dac_dev, dac_channel, step_data);
if (data->started[channel-1] == 1)
{
LL_DAC_Enable(dac_dev, dac_channel);
while (LL_DAC_IsReady(dac_dev, dac_channel) == 0)
{
// Wait
}
}
LL_DAC_SetWaveSawtoothStepData(dac_dev, dac_channel, step_data);
}
}
......@@ -216,6 +219,11 @@ static void dac_stm32_pin_configure(const struct device* dev, uint8_t channel, d
{
LL_DAC_ConfigOutput(dac_dev, dac_channel, LL_DAC_OUTPUT_MODE_NORMAL, LL_DAC_OUTPUT_BUFFER_ENABLE, LL_DAC_OUTPUT_CONNECT_GPIO);
}
else if (pin_config == dac_pin_internal_and_external)
{
LL_DAC_ConfigOutput(dac_dev, dac_channel, LL_DAC_OUTPUT_MODE_NORMAL, LL_DAC_OUTPUT_BUFFER_ENABLE, LL_DAC_OUTPUT_CONNECT_INTERNAL);
}
}
static void dac_stm32_start(const struct device* dev, uint8_t channel)
......
......@@ -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.
......
......@@ -17,5 +17,6 @@ if(CONFIG_OWNTECH_HARDWARE_CONFIGURATION)
src/adc_configuration.cpp
src/power_driver_configuration.cpp
public_api/HardwareConfiguration.cpp
src/comparator_configuration.cpp
)
endif()
......@@ -7,3 +7,4 @@ config OWNTECH_HARDWARE_CONFIGURATION
depends on OWNTECH_NGND_DRIVER
depends on OWNTECH_TIMER_DRIVER
depends on OWNTECH_GPIO_API
depends on OWNTECH_COMPARATOR_DRIVER
/*
* Copyright (c) 2022 LAAS-CNRS
* Copyright (c) 2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,7 +18,7 @@
*/
/**
* @date 2022
* @date 2023
*
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Luiz Villa <luiz.villa@laas.fr>
......@@ -35,6 +35,7 @@
#include "../src/uart_configuration.h"
#include "../src/adc_configuration.h"
#include "../src/power_driver_configuration.h"
#include "../src/comparator_configuration.h"
// Current class header
#include "HardwareConfiguration.h"
......@@ -89,11 +90,6 @@ void HardwareConfiguration::setBoardVersion(hardware_version_t hardware_version)
/////
// DAC
void HardwareConfiguration::initDac1Dac3CurrentMode()
{
dac_config_dac1_dac3_current_mode_init();
}
void HardwareConfiguration::initDacConstValue(uint8_t dac_number)
{
dac_config_const_value_init(dac_number);
......@@ -104,6 +100,17 @@ void HardwareConfiguration::setDacConstValue(uint8_t dac_number, uint8_t channel
dac_set_const_value(dac_number, channel, const_value);
}
void HardwareConfiguration::slopeCompensationLeg1(float32_t peak_voltage, float32_t low_voltage)
{
set_satwtooth_DAC3(peak_voltage, low_voltage);
}
void HardwareConfiguration::slopeCompensationLeg2(float32_t peak_voltage, float32_t low_voltage)
{
set_satwtooth_DAC1(peak_voltage, low_voltage);
}
/////
// NGND
......@@ -259,6 +266,24 @@ void HardwareConfiguration::initIndependentModeCenterAligned(leg_operation_t leg
hrtim_init_independent_mode_center_aligned(leg1_mode, leg2_mode);
}
void HardwareConfiguration::initBuckCurrentMode()
{
if(HardwareConfiguration::hardware_version == TWIST_v_1_1_2)
{
hrtim_init_CurrentMode(false,true,TIMA,TIMC);
dac_config_dac3_current_mode_init(TIMA);
dac_config_dac1_current_mode_init(TIMC);
}
else
{
hrtim_init_CurrentMode(true,true,TIMA,TIMB);
dac_config_dac3_current_mode_init(TIMA);
dac_config_dac1_current_mode_init(TIMB);
}
comparator_initialization();
}
void HardwareConfiguration::setInterleavedDutyCycle(float32_t duty_cycle)
{
hrtim_interleaved_pwm_update(duty_cycle);
......
/*
* Copyright (c) 2022 LAAS-CNRS
* Copyright (c) 2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,7 +18,7 @@
*/
/**
* @date 2022
* @date 2023
*
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Luiz Villa <luiz.villa@laas.fr>
......@@ -81,9 +81,10 @@ public:
static void setBoardVersion(hardware_version_t hardware_version);
// DAC
static void initDac1Dac3CurrentMode();
static void initDacConstValue(uint8_t dac_number);
static void setDacConstValue(uint8_t dac_number, uint8_t channel, uint32_t const_value);
static void slopeCompensationLeg1(float32_t peak_voltage, float32_t low_voltage);
static void slopeCompensationLeg2(float32_t peak_voltage, float32_t low_voltage);
// NGND
static void setNgndOn();
......@@ -109,6 +110,7 @@ public:
static void initFullBridgeBoostModeCenterAligned();
static void initIndependentMode(leg_operation_t leg1_operation_type, leg_operation_t leg2_operation_type);
static void initIndependentModeCenterAligned(leg_operation_t leg1_operation_type, leg_operation_t leg2_operation_type);
static void initBuckCurrentMode();
static void setInterleavedDutyCycle(float32_t duty_cycle);
static void setFullBridgeBuckDutyCycle(float32_t duty_cycle);
......
/*
* Copyright (c) 2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGLPV2.1
*/
/**
* @date 2023
*
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
// OwnTech api
#include "comparator.h"
#include "comparator_configuration.h"
void comparator_initialization(){
comparator_init();
}
/*
* Copyright (c) 2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGLPV2.1
*/
/**
* @date 2023
*
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
#ifndef COMPARATOR_CONFIGURATION_H_
#define COMPARATOR_CONFIGURATION_H_
void comparator_initialization();
#endif // COMPARATOR_CONFIGURATION_H_
/*
* Copyright (c) 2021-2022 LAAS-CNRS
* Copyright (c) 2021-2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,54 +18,31 @@
*/
/**
* @date 2022
* @date 2023
*
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Luiz Villa <luiz.villa@laas.fr>
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
// Zephyr
#include <zephyr.h>
// Owntech driver
#include "dac.h"
// Header
#include "dac_configuration.h"
// Define the voltage reference used for ADC.
// It depends on the board used (On nucleo, choose Vref = 2.48V).
#define VREF 2.048f
static const struct device* dac1 = DEVICE_DT_GET(DAC1_DEVICE);
static const struct device* dac2 = DEVICE_DT_GET(DAC2_DEVICE);
static const struct device* dac3 = DEVICE_DT_GET(DAC3_DEVICE);
void dac_config_dac1_dac3_current_mode_init()
{
if ( (device_is_ready(dac1) == true) && (device_is_ready(dac3) == true) )
{
// DAC 1
dac_function_config_t function_config =
{
.dac_function = dac_function_sawtooth,
.reset_trigger_source = hrtim_trig1,
.step_trigger_source = hrtim_trig1,
.polarity = dac_polarity_decrement,
.reset_data = 4000,
.step_data = 200
};
dac_set_function(dac1, 1, &function_config);
dac_pin_configure(dac1, 1, dac_pin_internal);
dac_start(dac1, 1);
// DAC 3
function_config.reset_trigger_source = hrtim_trig2;
function_config.step_trigger_source = hrtim_trig2;
dac_set_function(dac3, 1, &function_config);
dac_pin_configure(dac3, 1, dac_pin_internal);
dac_start(dac3, 1);
}
}
void dac_config_const_value_init(uint8_t dac_number)
{
const struct device* dac_dev;
......@@ -80,12 +57,12 @@ void dac_config_const_value_init(uint8_t dac_number)
}
else
{
dac_dev = dac2; //sets the dac 2 as default
dac_dev = dac2; // sets the dac 2 as default
}
if (device_is_ready(dac_dev) == true)
{
dac_set_const_value(dac_dev,1,0);
dac_set_const_value(dac_dev, 1, 0);
dac_pin_configure(dac_dev, 1, dac_pin_external);
dac_start(dac_dev, 1);
}
......@@ -105,11 +82,158 @@ void dac_set_const_value(uint8_t dac_number, uint8_t channel, uint32_t const_val
}
else
{
dac_dev = dac2; //sets the dac 2 as default
dac_dev = dac2; // sets the dac 2 as default
}
if (device_is_ready(dac_dev) == true)
{
dac_set_const_value(dac_dev,channel,const_value);
dac_set_const_value(dac_dev, channel, const_value);
}
}
void dac_config_dac1_current_mode_init(hrtim_tu_t tu_src)
{
// DAC 1
dac_function_config_t function_config =
{
.dac_function = dac_function_sawtooth,
.reset_trigger_source = hrtim_trig1,
.step_trigger_source = hrtim_trig1,
.polarity = dac_polarity_decrement,
.reset_data = 4000,
.step_data = 200};
switch (tu_src)
{
case TIMB:
function_config.reset_trigger_source = hrtim_trig2;
function_config.step_trigger_source = hrtim_trig2;
break;
case TIMC:
function_config.reset_trigger_source = hrtim_trig3;
function_config.step_trigger_source = hrtim_trig3;
break;
case TIMD:
function_config.reset_trigger_source = hrtim_trig4;
function_config.step_trigger_source = hrtim_trig4;
break;
case TIME:
function_config.reset_trigger_source = hrtim_trig5;
function_config.step_trigger_source = hrtim_trig5;
break;
case TIMF:
function_config.reset_trigger_source = hrtim_trig6;
function_config.step_trigger_source = hrtim_trig6;
break;
default:
break;
}
dac_set_function(dac1, 1, &function_config);
dac_pin_configure(dac1, 1, dac_pin_internal_and_external);
dac_start(dac1, 1);
}
void dac_config_dac3_current_mode_init(hrtim_tu_t tu_src)
{
// DAC 3
dac_function_config_t function_config =
{
.dac_function = dac_function_sawtooth,
.reset_trigger_source = hrtim_trig1,
.step_trigger_source = hrtim_trig1,
.polarity = dac_polarity_decrement,
.reset_data = 4000,
.step_data = 200};
switch (tu_src)
{
case TIMB:
function_config.reset_trigger_source = hrtim_trig2;
function_config.step_trigger_source = hrtim_trig2;
break;
case TIMC:
function_config.reset_trigger_source = hrtim_trig3;
function_config.step_trigger_source = hrtim_trig3;
break;
case TIMD:
function_config.reset_trigger_source = hrtim_trig4;
function_config.step_trigger_source = hrtim_trig4;
break;
case TIME:
function_config.reset_trigger_source = hrtim_trig5;
function_config.step_trigger_source = hrtim_trig5;
break;
case TIMF:
function_config.reset_trigger_source = hrtim_trig6;
function_config.step_trigger_source = hrtim_trig6;
break;
default:
break;
}
dac_set_function(dac3, 1, &function_config);
dac_pin_configure(dac3, 1, dac_pin_internal);
dac_start(dac3, 1);
}
void set_satwtooth_DAC3(float32_t set_voltage, float32_t reset_voltage)
{
float32_t Dv = set_voltage - reset_voltage;
if (Dv < 0)
Dv = 0;
if (Dv > set_voltage)
{
Dv = set_voltage;
if (Dv > VREF)
Dv = VREF;
}
uint32_t set_data = (uint32_t)(4096U * set_voltage) / (VREF);
if (set_data > 4095U)
set_data = 4095U;
dac_function_update_reset(dac3, 1, set_data);
uint32_t reset_data = (uint32_t)(Dv * 65536) / (VREF * 100); // divided by 100 because we have 100 voltage steps
dac_function_update_step(dac3, 1, reset_data);
}
void set_satwtooth_DAC1(float32_t set_voltage, float32_t reset_voltage)
{
float32_t Dv = set_voltage - reset_voltage;
if (Dv < 0)
Dv = 0;
if (Dv > set_voltage)
Dv = set_voltage;
if (Dv > VREF)
Dv = VREF;
uint32_t set_data = (uint32_t)(4096U * set_voltage) / (VREF);
if (set_data > 4095U)
set_data = 4095U;
dac_function_update_reset(dac1, 1, set_data);
uint32_t reset_data = (uint32_t)(Dv * 65536U) / (VREF * 100); // divided by 100 because we have 100 voltage steps
dac_function_update_step(dac1, 1, reset_data);
}
/*
* Copyright (c) 2022 LAAS-CNRS
* Copyright (c) 2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,9 +18,10 @@
*/
/**
* @date 2022
* @date 2023
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Luiz Villa <luiz.villa@laas.fr>
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
......@@ -30,10 +31,18 @@
// Stdlib
#include <stdint.h>
//ARM_MATH
#include <arm_math.h>
// hrtim.h is important to configure the DAC for current mode
#include "hrtim.h"
void dac_config_dac1_dac3_current_mode_init();
void dac_config_const_value_init(uint8_t dac_number);
void dac_set_const_value(uint8_t dac_number, uint8_t channel, uint32_t const_value);
void dac_config_dac3_current_mode_init(hrtim_tu_t tu_src);
void dac_config_dac1_current_mode_init(hrtim_tu_t tu_src);
void set_satwtooth_DAC3(float32_t set_voltage, float32_t reset_voltage);
void set_satwtooth_DAC1(float32_t set_voltage, float32_t reset_voltage);
#endif // DAC_CONFIGURATION_H_
/*
* Copyright (c) 2021-2022 LAAS-CNRS
* Copyright (c) 2021-2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,7 +18,7 @@
*/
/**
* @date 2022
* @date 2023
* @author Luiz Villa <luiz.villa@laas.fr>
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
......@@ -188,6 +188,19 @@ void hrtim_init_full_bridge_buck_mode_center_aligned(bool bipolar_mode,bool SPIN
}
/**
* This function initializes both legs in Current Mode configuration
*/
void hrtim_init_CurrentMode(bool leg1_buck, bool leg2_buck, hrtim_tu_t leg1_tu, hrtim_tu_t leg2_tu)
{
hrtim_init_current(leg1_buck, leg2_buck, leg1_tu, leg2_tu);
pwm_period = leg_period();
pwm_phase_shift = 0;
CM_leg_set(leg1_tu, 0);
CM_leg_set(leg2_tu, pwm_phase_shift);
}
/**
* This function transfer the calculated PWM value to the
* HRTIM peripheral and make sure it is between saturation
......
/*
* Copyright (c) 2021-2022 LAAS-CNRS
* Copyright (c) 2021-2023 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
......@@ -18,9 +18,10 @@
*/
/**
* @date 2022
* @date 2023
* @author Luiz Villa <luiz.villa@laas.fr>
* @author Clément Foucher <clement.foucher@laas.fr>
* @author Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
*/
#ifndef HRTIM_CONFIGURATION_H_
......@@ -94,6 +95,29 @@ void hrtim_init_independent_mode(bool leg1_buck_mode, bool leg2_buck_mode);
*/
void hrtim_init_independent_mode_center_aligned(bool leg1_buck_mode, bool leg2_buck_mode);
/**
* @brief initialize the converter in current mode
* @param[in] leg1_buck bool parameter, 0->leg1 in boost mode 1->leg1 in buck mode
* @param[in] leg2_buck bool parameter, 0->leg2 in boost mode 1->leg2 in buck mode
* @param[in] leg1_tu one of the timing unit, from TIMA to TIMF :
* @arg @ref TIMA
* @arg @ref TIMB
* @arg @ref TIMC
* @arg @ref TIMD
* @arg @ref TIME
* @arg @ref TIMF
* @param[in] leg2_tu one of the timing unit, from TIMA to TIMF :
* @arg @ref TIMA
* @arg @ref TIMB
* @arg @ref TIMC
* @arg @ref TIMD
* @arg @ref TIME
* @arg @ref TIMF
*/
void hrtim_init_CurrentMode(bool leg1_buck, bool leg2_buck, hrtim_tu_t leg1_tu, hrtim_tu_t leg2_tu);
/**
* @brief This function transfer the calculated PWM value to the
* HRTIM peripheral and make sure it is between saturation
......
......@@ -85,7 +85,7 @@ void hrtim_pwm_set(hrtim_t dev, hrtim_tu_t tu, uint16_t value, uint16_t shift);
void hrtim_init_current();
void hrtim_init_current(bool leg1_convention, bool leg2_convention, hrtim_tu_t leg1_tu, hrtim_tu_t leg2_tu);
void hrtim_init_voltage_buck(hrtim_tu_t leg1_tu, hrtim_tu_t leg2_tu);
void hrtim_init_voltage_buck_center_aligned(hrtim_tu_t leg1_tu, hrtim_tu_t leg2_tu);
void hrtim_init_voltage_boost(hrtim_tu_t leg1_tu, hrtim_tu_t leg2_tu);
......
......@@ -165,6 +165,25 @@ void leg_set_min_duty_cycle(float32_t duty_cycle);
*/
void leg_set_max_duty_cycle(float32_t duty_cycle);
/**
* @brief Set the timer and phase shift for given leg device with current mode initialization
*
* @param[in] timing_unit timing_unit from TIMA to TIMF
* @param[in] pulse_width pulse width to set
* @param[in] phase_shift phase shift
*/
void CM_leg_set(hrtim_tu_t timing_unit, uint16_t phase_shift);
/**
* @brief Initializes all the configured devices with the chosen switch convention with current mode initialization
*
* @param[in] leg1_upper_switch_convention Choice of the switch convention for leg 1
* @param[in] leg2_upper_switch_convention Choice of the switch convention for leg 2
*
* @return HRTIM period
*/
uint16_t leg_init_CM(bool leg1_upper_switch_convention, bool leg2_upper_switch_convention, hrtim_tu_t leg1_tu, hrtim_tu_t leg2_tu);
#ifdef __cplusplus
}
......