Buck 2 Measurements - owntech-foundation/Tutorials GitHub Wiki

Objective

The goal of this tutorial is to activate the measurements on the O2 board, acquire them and display them. We will start from the Buck 1 tutorial.

We will measure the low-side voltage 1 and 2, the low-side currents 1 and 2, the high-side voltage and the high-side current. All will be observed using the SerialPlot application.

image

Converter on Buck mode: in red are the currents and the black arrows are the voltages

Required hardware

  • O2 v_1_1_2
  • STLinkV3
  • PC 64-bits (windows or linux)
  • DC power supply (40 V, 2 A)
  • Oscilloscope or multimeter

Required software

  • Git
  • Visual Studio Code with PlatformIO (see Blinky tutorial)
  • SerialPlot (see SerialPlot tutorial)

Create the project

  1. We will create the project by copying the Buck 1 tutorial in a new branch, that will be called measurements. In the bottom menu, click on the New Terminal icon new_terminal_icon. This will open a new terminal into which you can write the following commands to create a new git branch.
git status
git add --all
git commit -m "work done on the buck_1"
git branch buck_2
git checkout buck_2
  1. In the bottom menu, check that you are now in the buck_2 branch.

buck_2_branch

Step-by-step implementation

  1. Define the variables

In src/main.cpp, in the section USER VARIABLE DECLARATIONS, add the variables that will hold the values of the measurements. Keep the previous variables as well.

//--------------USER VARIABLES DECLARATIONS----------------------

static float32_t V1_low_value; //store value of V1_low (app task)
static float32_t V2_low_value; //store value of V2_low (app task)
static float32_t Vhigh_value; //store value of Vhigh (app task)

static float32_t i1_low_value; //store value of i1_low (app task)
static float32_t i2_low_value; //store value of i2_low (app task)
static float32_t ihigh_value; //store value of ihigh (app task)

static float32_t meas_data; //temp storage meas value (ctrl task)
  1. Configure the hardware peripherals

In src/main.cpp, in the setup_hardware() function, paste the code below. It sets the version of the board, initializes all the mesurements in default mode and initializes the buck interleaved mode. The O2 converter has a total of six measurements, which are here activated on their default setup where all voltages are on ADC1, all currents on ADC2 and all measurements triggered at the beginning of the period of the HRTim A. It uses the lastest version of the code, which is compatible with the Twist board.

void setup_hardware(){
    hwConfig.setBoardVersion(O2_v_1_1_2);
    hwConfig.initInterleavedBuckMode();
    hwConfig.setHrtimAdcTrigInterleaved(0.06);
    dataAcquisition.enableTwistDefaultChannels();
    console_init();
}
  1. Configure the software scheduling

In src/main.cpp, in the function setup_software(), paste the code below. It starts the control task, the communication task and the application task. Due to its time criticity, the control task has a precise period and not a priority as the others.

void setup_software()
{
    dataAcquisition.setParameters(V1_LOW,0.045022,-91.679);
    dataAcquisition.setParameters(V2_LOW,0.044907,-91.430);
    dataAcquisition.setParameters(V_HIGH,0.066457,-0.279);
    dataAcquisition.setParameters(I1_LOW,0.004563,-9.367);
    dataAcquisition.setParameters(I2_LOW,0.005507,-11.351);
    dataAcquisition.setParameters(I_HIGH,0.005171,-10.597);

    application_task_number = scheduling.defineAsynchronousTask(loop_application_task);
    communication_task_number = scheduling.defineAsynchronousTask(loop_communication_task);
    scheduling.defineUninterruptibleSynchronousTask(&loop_control_task,control_task_period);

    scheduling.startAsynchronousTask(application_task_number);
    scheduling.startAsynchronousTask(communication_task_number);
    scheduling.startUninterruptibleSynchronousTask();
}
  1. Define the communication task

In src/main.cpp, in the function loop_communication_task(), do not modify anything.

  1. Define the application task

In src/main.cpp, in the function loop_application_task(), paste the following code. The IDLEMODE stops the power flow, the transmission of data and turns the LED1 off. The SERIALMODE only turns on the LED1. The POWERMODE turns the LED1 is ON and prints the values of all the variables and the duty_cycle on the Serial Interface.

void loop_application_task()
{
    if(mode==IDLEMODE) {
        hwConfig.setLedOff();
    }else if(mode==SERIALMODE) {
        hwConfig.setLedOn();
    }else if(mode==POWERMODE) {
        hwConfig.setLedOn();
    }        
    printk("%f:", duty_cycle);
    printk("%f:", Vhigh_value);
    printk("%f:", V1_low_value);
    printk("%f:", V2_low_value);
    printk("%f:", ihigh_value);
    printk("%f:", i1_low_value);
    printk("%f\n", i2_low_value);
    scheduling.suspendCurrentTaskMs(100);     
}
  1. Define the control task

In src/main.cpp, in the function loop_control_task(), add the following code. We want to retrieve all measurements by calling the dataAcquisition.getLatest(XXXX); where XXXX is replaced by the name of the variable of interest. There are six possible names :

  • V_HIGH - For the high-side voltage
  • V1_LOW - For the low-side 1 voltage
  • V2_LOW - For the low-side 2 voltage
  • I_HIGH - For the high-side current
  • I1_LOW - For the low-side 1 current
  • I2_LOW - For the low-side 2 current

When making a measurement, it may happen that the value is incorrect. In this case, the function returns a NO_VALUE, which is equivalent of -10000. Thus it is necessary to check the integrity of the measurement prior to its use.

After the data is retrieved, it is treated depending on the active mode.

void loop_control_task()
{
    meas_data = dataAcquisition.getLatest(V_HIGH);
    if(meas_data!=NO_VALUE) Vhigh_value = meas_data;

    meas_data = dataAcquisition.getLatest(V1_LOW);
    if(meas_data!=NO_VALUE) V1_low_value = meas_data;

    meas_data = dataAcquisition.getLatest(V2_LOW);
    if(meas_data!=NO_VALUE) V2_low_value= meas_data;

    meas_data = dataAcquisition.getLatest(I_HIGH);
    if(meas_data!=NO_VALUE) ihigh_value = meas_data;

    meas_data = dataAcquisition.getLatest(I1_LOW);
    if(meas_data!=NO_VALUE) i1_low_value = meas_data;

    meas_data = dataAcquisition.getLatest(I2_LOW);
    if(meas_data!=NO_VALUE) i2_low_value = meas_data;

    if(mode==IDLEMODE || mode==SERIALMODE) {
         pwm_enable = false;
         hwConfig.setInterleavedOff();

    }else if(mode==POWERMODE) {

        if(!pwm_enable) {
            pwm_enable = true;
            hwConfig.setInterleavedOn();
        }

        //Sends the PWM to the switches
	hwConfig.setInterleavedDutyCycle(duty_cycle);
    }
}
  1. Connect hardware

Now we will connect OwnTech’s O2 to the power supply and to the PC.

  • :warning: Make sure that the jumper JP4 is open.
  • Connect the USB power supply cable. The LED2 of the O2 should be ON.
  • Connect the pins Vhigh and GND of the O2 to the DC power supply (set the current limitation at 1 A).
  • Connect the micro-JTAG connector of the O2 to the PC thanks to the STLinkV3.
  • Switch ON the DC power supply. Choose a voltage between 0 and 48 V.

step6

  1. Build and Upload (build_icon+ flash_icon).

  2. In the bottom toolbar, click on the Serial Monitor icon serial_icon. Select it and press the h key. Press the p button, you should see some data show on the terminal:

data_upload

Expected outputs

  • Press i to switch to IDLEMODE: stops printing the data and turns the LED1 OFF.
  • Press the p to switch to POWERMODE: prints all the data, turns the LED1 ON.
  • Press the u to increase the duty_cycle.
  • Press the d to decrease the duty_cycle.

You can measure the DC output voltage thanks to an oscilloscope or a multimeter.

OwnPlot Visualization

We will now plot all the variables and the duty_cycle on a graph, instead of printing it in the Serial Monitor.

  1. First kill the Serial Monitor by clicking on the trash button on the right hand side of the window as shown in the image below.

Kill serial monitor

  1. Launch OwnPlot. In Port tab, choose the STLinkV3. Click on the Closed button to open the port.

:warning: The Port might have a different name depending on your operating system.

open_port_running

  1. In OwnPlot, Settings tab, set the # of channels to 7.

ownplot_settings_buck-2

  1. In OwnPlot, in the Chart tab, change the same of the datasets as shown below:

ownplot_chart_buck-2

  1. In OwnPlot, in the Send tab, add the commands below by typing the command name and its associated character.

ownplot_send_buck-2

  1. In OwnPlot click on the Power button corresponding to the p command to switch to POWERMODE and turn the LED1 ON. You should see the values of all the measurements change on your OwnPlot window and their received value on the terminal below. You can increase and decrease the duty cycle, by clicking on Up and Down buttons. OwnPlot will automatically update the size of the window as you change the value of the variable.

ownplot_counter_up_down

  1. In OwnPlot, click on the Idle button corresponding to the i command to switch to IDLEMODE and turn the LED1 OFF.

That’s it!

That’s it!

Contributors

  • 2021.11.04: Romain Delpoux, Loïc Quéval, Adrien Prévost
  • 2021.11.07: Luiz Villa, Antoine Boche
  • 2022.01.24: Luiz Villa, Loïc Quéval
  • 2022.02.01: Luiz Villa
  • 2022.02.22: Luiz Villa
  • 2022.03.13: Luiz Villa
  • 2022.06.24: Loïc Quéval