5.2 Plot Graph In MPLAB® Data Visualizer

The MPLAB® Data Visualizer is a program used to process and visualize data from a running embedded target. The program may be accessed as an MPLAB X IDE plugin or a stand-alone program. In this assignment, the Data Visualizer will be configured to graph the input and output of OP0 received over USART. The configuration is done through a saved workspace, and the basics of how to display the data are explained. To find out how to set up your own workspace, a detailed guide can be found by clicking on the Documentation button in MPLAB Data Visualizer.

Todo: Configure MPLAB Data Visualizer to graph received OP0 input and output samples.
  1. Open the program and plug in an already flashed device. Make sure the COM-port used for USART communication is not already in use. The start screen will be similar to Figure 5-2.
    Figure 5-2. Assignment 3: MPLAB® Data Visualizer Starting Page
  2. Load the workspace. Press the Load Workspace button and add the workspace-file called Assignment3.json. All the workspaces for this training can be found in DataVisualizer. Two axes appear in the graph. These can be configured on the panel on the right-hand side, as illustrated in Figure 5-3.
    Figure 5-3. Assignment 3: Data Visualizer Loaded Work Space
  3. Choose the COM-port on the left-hand side panel seen in Figure 5-3 to plot the data. Make sure the Baud Rate is 115200 and press the Apply button to set the baud rate. Press the Play button next to the COM field shown in Figure   2. Press the Variable Streamers button to connect the decoder to the USART data stream. Set the COM port as input to Decoder 1, as shown in Figure   3.
    Figure 5-4. Assignment 3: Variable Streamers
  4. Press Show Live Data to start plotting live data from the device.
Result: The data streamed to the PC over USART are plotted in the MPLAB® Data Visualizer, as shown in Figure   4. The red waveform is the output from the DAC, while the green is the output from the op amp. As expected, we can see that the output of the op amp closely follows the input to the op amp.
Figure 5-5. Assignment 3: Result
Info: The DAC outputs a 50 Hz sinusoidal wave with 256 mVpp and 256 mV DC offset. The sinusoidal wave is pre-calculated at startup in the sine_wave_table_init() function, and DAC updated with values upon TCB0 ISR (SINE_WAVE_TIMER_vect).
void sine_wave_table_init(void)
{
    for(uint16_t i = 0; i < SINE_WAVE_STEPS; i++)
    {
        sine_wave[i] = SINE_DC_OFFSET + SINE_AMPLITUDE * sin(i * M_2PI / SINE_WAVE_STEPS);
    }
}
ISR(SINE_WAVE_TIMER_vect) {
    volatile static uint16_t sine_wave_index = 0
    
    data_stream.dacVal = sine_wave[sine_wave_index];
    DAC0_setVal(data_stream.dacVal);
    sine_wave_index++;
    sine_wave_index = sine_wave_index % SINE_WAVE_STEPS;

    /* Clear interrupt flag */
    SINE_WAVE_TIMER.INTFLAGS = TCB_CAPT_bm;
}