Measurements - owntech-foundation/Tutorials GitHub Wiki

Objective

The goal of this tutorial is to activate the measurements on the TWIST board, acquire and display them.

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 OwnPlot application.

Converter measurements

Converter on Buck mode: in red are the currents and the voltages are measured by the capacitors

Required hardware

  • TWIST v_1_3
  • PC 64-bits (windows or linux)
  • DC power supply (40 V, 2 A)
  • Resistive load
  • Oscilloscope or multimeter

Required software

  • Git
  • Visual Studio Code with PlatformIO
  • OwnPlot

Create the project

  1. We save our progress by committing our work.

  2. In the side menu, click on the Source Control button, which will open a new menu.

source_control_button

You can see that the only changes on your code are located at the 'main.cpp' file. We are going to commit these changes as to keep track of our progress.

  1. Click on the + button on the right side of the main.cpp file to "stage" the changes. You can add a comment to explain what these changes are useful for. It is good practice to describe your changes when you commit them in git. Click on the + Commit button. Your work has now been committed. We can come back to it later if necessary.

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 all the previous variables as well.

//--------------USER VARIABLES DECLARATIONS----------------------
static float32_t duty_cycle = 0.5; //[-] duty cycle (comm task)
static float32_t duty_cycle_step = 0.05; //[-] duty cycle step (comm task)
static bool pwm_enable = false; //[bool] state of the PWM (ctrl task)
static uint32_t control_task_period = 50; //[us] period of the control task

//Measurement variables
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 setup routine

In src/main.cpp, in the setup_routine() function, paste the code below. It sets the version of the board, initializes all the measurements channels in default mode, initializes the buck interleaved mode and activates a trigger between the two. It also creates and starts all the tasks.

The TWIST converter has a total of six measurements, which are here activated on the setup shown in table 1.

ADC1 ADC2
ILow1 ILow2
VLow1 VLow2
VHigh IHigh

Table 1: Measurements default setup

void setup_routine(){
    console_init();

    // Setup the hardware first
    spin.version.setBoardVersion(SPIN_v_1_0);
     twist.setVersion(shield_TWIST_V1_3);

    //Enable all twist default channels
    data.enableTwistDefaultChannels();


    // Buck mode initialization
    twist.initAllBuck();

    // Then declare tasks
    uint32_t app_task_number = task.createBackground(loop_application_task);
    uint32_t comm_task_number = task.createBackground(loop_communication_task);
    task.createCritical(loop_critical_task, 500); // Uncomment if you use the critical task

    // Finally, start tasks
    task.startBackground(app_task_number);
    task.startBackground(comm_task_number);
    task.startCritical(); // Uncomment if you use the critical task

}
  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 and turns the LED1 off. The SERIALMODE only turns on the LED1. The POWERMODE turns the LED1 to toggle mode and the power on. The values of all the variables and the duty_cycle are constantly printed on the Serial Interface.

void loop_application_task()
{
    if(mode==IDLEMODE) {
        spin.led.turnOff();
    }else if(mode==SERIALMODE) {
        spin.led.turnOn();
    }else if(mode==POWERMODE) {
        spin.led.toggle();
    }        
    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);

    task.suspendBackgroundMs(100);     
}
  1. Define the critical task

In src/main.cpp, in the function loop_critical_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.

Since this is an open-loop mode, the data is not used to control the duty cycle.

void loop_critical_task()
{
    meas_data = data.getLatest(V1_LOW);
    if (meas_data != NO_VALUE)
        V1_low_value = meas_data;

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

    meas_data = data.getLatest(V_HIGH);
    if (meas_data != NO_VALUE)
        Vhigh_value = meas_data;

    meas_data = data.getLatest(I1_LOW);
    if (meas_data != NO_VALUE)
        I1_low_value = meas_data;

    meas_data = data.getLatest(I2_LOW);
    if (meas_data != NO_VALUE)
        I2_low_value = meas_data;

    meas_data = data.getLatest(I_HIGH);
    if (meas_data != NO_VALUE)
        Ihigh_value = meas_data;


    if(mode==IDLEMODE || mode==SERIALMODE) {
         pwm_enable = false;
         twist.stopAll();

    }else if(mode==POWERMODE) {

        if(!pwm_enable) {
            pwm_enable = true;
            twist.startAll();
        }

        //Sends the PWM to the switches
	twist.setAllDutyCycle(duty_cycle);
    }
}

  1. Connect hardware

Now we will connect your TWIST board to the power supply and to the PC via the STLink.

  • Connect the pins Vhigh and GND of the TWIST to the DC power supply (set its current limitation at 1 A).
  • Connect the pins VLow1, Vlow2 and GND of the TWIST to a resistive load.
  • Connect the micro-JTAG connector of the SPIN to the PC thanks to the STLinkV3.
  • Switch ON the DC power supply. Choose a voltage between 0 and 48 V.

Twist_setup_buck_mode

  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 the power flow and turns the LED1 OFF.
  • Press the p to switch to POWERMODE: starts the power flow and 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!

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
  • 2023.07.10: Luiz Villa