1 Data Visualizer Run Time (DVRT) Library Overview

The MCC Melody Data Visualizer Run Time (DVRT) Library supports the DVRT functionality of the MPLAB® Data Visualizer on a host computer. The DVRT Library allows the user to "watch" and plot project variables at run time on the Data Visualizer plugin window.

1.1 Data Visualizer Run Time Basics

The DVRT functionality on the MPLAB Data Visualizer, running on a host computer, is supported by an MCC Melody Library, communicating with the Data Visualizer via a Universal Asynchronous Receiver/Transmitter (UART) connected to your computer's COM port.
Tip: The COM Port may be via a USB/serial bridge, or available on a development board, such as on the Curiosity Nano platform.
Figure 1-1. The DV Run Time protocol system, implemented across both microcontroller (MCU) and MPLAB Data Vizualizer (Host PC)
Figure 1-2. Introduction to the Data Visualizer Run Time (DVRT) protocol, for the MPLAB Data Visualizer
Figure 1-3. The MCU side of the DV Run Time Protocol, here implemented by the MCC Melody DV Run Time Library
Tip: Note the UART and Timer dependencies of the MCC Melody DV run time library.
Figure 1-4. DV Run Time Configuration Instructions:
Note: See the next section for more details on these steps.
Tip: Any timer PLIB (Peripheral Library) can be chosen.
Tip: When selecting a UART, one needs to select a UART connected to a CDC UART on the PC. If using a Curiosity Nano, its USB/serial bridge, facilitates a connection between a UART on the Target MCU and a virtual COM port on your PC, e.g., to connect to the MPLAB Data Visualizer. See: DV Run Time Implementation

1.1.1 MCC Melody DV Run Time Configuration

1.1.1.1 MCC Content Manager: Add Melody Data Streamer Library

Since the Data Streamer is not default content, it may be missing from Device Resources.

In this case, click the button to open the MCC Content Manager.

CAUTION: Note that the MCC Content Manager Icon, next to the icon is to open the standalone version of the MCC Content Manger, i.e., where one can see all MCC content. If attempting to open this when MCC is running, the below message will be triggered:

1.1.1.2 Builder: Add DV Run Time Library

Application Builder: Click 'Add Component'.

Filter on 'Data' then click the icon to add the DV Run Time.

Tip: When added to the Builder, components can be considered to be in their default configuration.
CAUTION: If not in its default configuration, a Driver or Library component's configuration can be reset by removing the component and adding it back again.
Once added, the DV Run Time will be added to the MCC Builder.
Tip: Clicking the UART (None) or Timer (None) will bring the UART or the Timer Driver to focus, respectively, where a dependency can be selected.
  1. Timer Dependency Selection: Select any available timer. The Timer driver default of 1 ms, with interrupts enabled is used.
  2. UART Dependency Selection: Determine the UART instance connected to your computer's COM port, which could be a Virtual Serial Port (CDC). Check the board layout schematic on the MCU side to find the UART instance and the Device Manager for Windows or on a Mac terminal type ls /dev/tty.* to find which serial port the UART is connected to.
    Note: CDC refers to USB Communications Class Device.
    Note: For Curiosity Nano boards, this is usually the UART instance connected to the debugger. Using USB-to-Serial bridges will also work. Here, the Data Visualizer will automatically detect the COM port of the connected kit.
    Note: UART Software Receive Buffer Size is calculated by the DV Run Time Library: Receive buffer for DVRT Frame needs to fit the largest command, i.e., UpdateVariablePtrTableCmd, which is 28 bytes by default, when NumVars is 8. Frame calculation: Start_Byte + Cmd_Byte + NumVars_Byte + (NumVars * 3 Bytes) + End_Byte.

1.1.1.3 Connecting MPLAB Data Visualizer DvrtProtocol options to Melody Library fields

The image below shows the MPLAB Data Visualizer integrated into MPLAB X IDE, with an DVRT Protocol Session on the left hand side and the configuration options for the MCC Melody DV Run Time library on the right hand side.

The default configurations will work, but this section will help to understand the use of the DVRT protocol.
  1. API Prefix: This text will be the prefix for all API associated with the DVRT.
  2. Number of Dynamic Variables: This number has to be higher or equal to (>=) the number of variables in the DVRT Streaming Table in the Data Visualizer. On the Data Visualizer side, this is configured by setting the number of Streaming Slots.
    Figure 1-5. MPLAB Data Visualizer DvrtProtocol Session (PC side, on left) with DV Run Time Library (MCU side, on right)
  3. Project FW Code: Can be used to distinguish between different projects. The Data Visualizer compares the Firmware Code read from the target to an expected value. A warning is displayed if the values don't match.
    Note: The default value of the Project Firmware Code matches the Expected FM Code in the Data Visualizer.
    Note: This Project Firmware Code is used in the DVRunTime_Config.h.
    Note: In the DVRT library, the U suffix (e.g., 8U, 20U, 200U) denotes an unsigned integer constant, ensuring MISRA-compliant type clarity and safe use with types like uint8_t or uint16_t.

1.1.2 DV Run Time Implementation

Responsibilities: MCU Side and HOST PC Side

The figure below shows how the DVRT works in the main Streaming mode. It is composed of two sides, an MCU side (DVRT_M) and a PC Host application (DVRT_H) communicating through a bi-directional UART protocol.
  1. MPLAB X IDE MCU Project is compiled and an .elf file produced.
  2. The .elf file is loaded in the Data Visualizer.
    Note: Choose the debug or production version of the .elf, matching your compilation settings.
  3. A Parser script is used to generate a list of variables.
    Note: For volatile variables, this .elf file contains their name, address and type (length in bytes), i.e., at compile time, it is known where volatile variables will be located in the Microcontroller's RAM.
  4. DVRT Streaming Table is used to select variables of interest to watch at run time.
  5. As variables are selected, the DVRT command UPDATE_VARIABLE_POINTER_TABLE is sent to the microcontroller to add these variables to a Dynamic Variables Pointer Monitor Table (DVPMT).
    Note: For each variable, this is the address of the variable in the MCU's RAM, and the number of bytes is saved.
  6. The values of variables are fetched from specific locations in RAM and the Dynamic Output Buffer now contains updated values of each variable in the DVRT Streaming Table.
  7. Data Output Buffer sent over UART to Data Visualizer.
  8. Variable values updated in the DVRT Streaming Table.

Data Stream Protocol Format

The DV Run Time at the lowest level implements the Data Stream protocol to send data to the Data Visualizer.

The Data Stream Format is processed in the same order as the variables specified in the Variable Streamer. All data must be given as little-endian values, meaning sending the lowest byte first. Additionally, the Data Streamer Protocol requires a start byte and an end byte which are each other's complement (~). For example, if the startByte is: 0b0000 0011, the endByte will be 0b1111 1100. This wrapper, consisting of one byte before and one byte after the data stream variables, is used by the interpreter to synchronize it to the data stream. The start byte can be arbitrary, but the end byte must be the inverse of the start byte.

Figure 1-6. Data Streamer

1.1.3 Data Visualizer Setup for DV Run Time

When using the MCC Melody DV Run Time Library, this section describes the steps needed to set up the DV Run Time in the MPLAB Data Visualizer.
Figure 1-7. I2C Host Proximity Sensor Example, using the DV Run Time Example Visualization
Tip: The steps below are for an example that is correctly configured in MCC Melody and that the button is pressed to generate the code.
Tip: For the Data Streamer, application variables to be plotted must be added to the Data Streamer Table. The DV Run Time is different in that variables, in the form of debug symbols, are exposed by loading an appropriate .elf file. To increase the likelihood that a variable's debug symbol can be found, set the variable to volatile and/or static.
Tip: For volatile variables, this .elf file contains their name, address and type (length in bytes), i.e., at compile time, it is known where volatile variables will be located in the Microcontroller's RAM.
  1. Within MPLAB X click the icon to open the MPLAB Data Visualizer.
  2. Click the button to see the current DVRT session or to start a new one.
    Tip: A new DVRT session will open as follows: ->.
  3. Next one needs to select a data source matching the DVRT protocol format. This will be the COM port (UART) that was configured as a dependency to the MCC Melody DV Run Time Library.
  4. Configure the Data Visualizer COM Settings (PC side) to match what was configured in the MCC Melody DV Run Time Library (MCU side).
  5. Next, load the .elf debug symbols file.
    Attention: Choose between the debug and the production version of the .elf whichever matches the compilation settings.
    • Debug, if you are in a debug session
    • Production, if you have simply programmed your MCU
  6. Add variables to DVRT Streaming Table.
    Tip: The volatile and static variables will show up in the symbols file.
  7. Reposition DVRT Streaming Table.
    Tip: One can drag the DVRT Streaming Table to the bottom pannel of the Data Visualizer, to view this table at the same time as the Time Plot of variables.
  8. Once the Plot all variables button is clicked, the DVRT Procol starts streaming and the Time Plot starts rolling.

1.3 Supported Device Families

All Supported 8- and 16-bit devices in Melody.

1.4 Required Header Files:

#include "mcc_generated_files/DVRT/DVRunTime.h"

1.5 How to Use the Data Visualizer Run Time Library

Instructions common for all code snippets: DV Run Time Library Use Case Code Snippet Instructions
Note: MPLAB® Data Visualizer Training: These use cases assume basic knowledge of the Data Visualizer. For installation instructions and a more thorough introduction to the MPLAB Data Visualizer, see the following Microchip University course: Visual Debugging with MPLAB® Data Visualizer.

DVRT Hello World: LED Toggle and Count Variables (Timer)
A LED is toggled after LED_period_ms (period of LED toggling in ms). LED_ON holds the state of the LED pin, meaning that when it is set to 0, an active low LED is on, and vice versa.
  • Count_msTicksSinceToggle is incremented up to toggle_ms, when LED_ON is toggled
Table 1-1. Running the DV Run Time Use Cases
Running Use Case 1: DVRT Hello World: LED Toggle and Count Variables (Timer) The Data Visualizer Run Time (DVRT) Streaming Table can be dragged down below the Time Plot. This makes it possible to see both the plot the current numerical value of the variable.
Note: Double click into the value field to enter a new variable value.

1.6 DV Run Time API Reference

1.6.1 Module Documentation

1.6.1.1 DV Run Time

 

1.6.1.1.1 Module description

 

This file contains the API prototypes for the dvruntime driver module.

Version: dvruntime Version 2.0.0.
Data structures
  • struct DVRT_interface_t

    Structure containing the function pointers to the DV Run Time driver APIs.

  • struct DVRT_VariablePointerTableEntry

    Defines one entry of the Variable Pointer Table.

  • struct DVRT_StreamUpdates

    Defines the data structure for updating the stream of variables sent to the Data Visualizer.

  • struct DVRT_VariableUpdate

    Defines the data structure needed to update the Variable Pointer Table (DVPMT).

  • struct DVRT_StreamIntervalUpdate

    Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.

  • struct DVRT_CommandTemplate

    Typedef for struct containing the elements needed for a generic DVRT command.  

Functions
  • void DVRT_UART_WriteByte (uint8_t txData)

    This blocking function writes a byte of data to the selected UART.

  • void DVRT_Initialize (void)

    Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.

  • void DVRT_Process (void)

    Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data, if required. Finally, it executes one-shot readings and ping commands.

1.6.1.1.2 Function Documentation
DVRT_Initialize()

void DVRT_Initialize (void )

Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.

Parameters:
None.
Returns:

None.

DVRT_Process()

void DVRT_Process (void )

Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data if required. Finally, it executes one-shot readings and ping commands.

Parameters:
None.
Returns:

None.

DVRT_UART_WriteByte()

void DVRT_UART_WriteByte (uint8_t txData)

This blocking function writes a byte of data to the selected UART.

Precondition:

The transfer status is checked to see if the transmitter is ready to accept a byte before UART->Write()

Parameters:
txData

- Data byte to write to the TX FIFO

Returns:

None.

1.6.1.1.3 Variable Documentation
DVRT

const DVRT_interface_t DVRT

Declaration of the DVRT interface and its function pointers.

Section: Included Files Section: Data Type Definitions

1.6.2 Data Structure Documentation

1.6.2.1 DVCmds Union Reference

1.6.2.1.2 Field Documentation

The documentation for this union was generated from the following file:

source/

DVRunTime.c

DVCmdArray

uint8_t DVCmdArray[sizeof(DVRT_StreamUpdates_t)]

generic

DVRT_CommandTemplate_t generic

interval

DVRT_StreamIntervalUpdate_t interval

stream

DVRT_StreamUpdates_t stream

Var

DVRT_VariableUpdate_t Var

1.6.2.2 DVRT_CommandTemplate Struct Reference

Typedef for struct containing the elements needed for a generic DVRT command.  

1.6.2.2.1 Detailed Description

Typedef for struct containing the elements needed for a generic DVRT command.  

#include <DVRunTime_types.h>

1.6.2.2.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

DVRunTime_types.h

command

uint8_t command

data

uint8_t data

endOfFrame

uint8_t endOfFrame

startOfFrame

uint8_t startOfFrame

1.6.2.3 DVRT_interface_t Struct Reference

Structure containing the function pointers to the DV Run Time driver APIs.

1.6.2.3.1 Detailed Description

Structure containing the function pointers to the DV Run Time driver APIs.

Section: Included Files Selecion: Data Type Definitions

#include <DVRunTime_interface.h>

1.6.2.3.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

DVRunTime_interface.h

Initialize

void(* Initialize) (void)

Process

void(* Process) (void)

1.6.2.4 DVRT_StreamIntervalUpdate Struct Reference

Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.

1.6.2.4.1 Detailed Description

Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.

#include <DVRunTime_types.h>

1.6.2.4.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

DVRunTime_types.h

command

uint8_t command

endOfFrame

uint8_t endOfFrame

period

uint16_t period

startOfFrame

uint8_t startOfFrame

1.6.2.5 DVRT_StreamUpdates Struct Reference

Defines the data structure for updating the stream of variables sent to the Data Visualizer.

1.6.2.5.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

DVRunTime_types.h

command

uint8_t command

DVPMT

DVRT_VariablePointerTableEntry_t DVPMT[DYNAMIC_VAR_PTR_COUNT]

endOfFrame

uint8_t endOfFrame

size

uint8_t size

startOfFrame

uint8_t startOfFrame

1.6.2.6 DVRT_VariablePointerTableEntry Struct Reference

Defines one entry of the Variable Pointer Table.

1.6.2.6.1 Detailed Description

Defines one entry of the Variable Pointer Table.

Defines one entry of the Variable Pointer Table.

#include <DVRunTime_types.h>

1.6.2.6.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

DVRunTime_types.h

address

uint8_t* address

size

uint8_t size

1.6.2.7 DVRT_VariableUpdate Struct Reference

Defines the data structure needed to update the Variable Pointer Table (DVPMT).

1.6.2.7.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

DVRunTime_types.h

command

uint8_t command

endOfFrame

uint8_t endOfFrame

startOfFrame

uint8_t startOfFrame

variableAddress

uint8_t* variableAddress

variablePointerTableSize

uint8_t variablePointerTableSize

variableValue

uint8_t variableValue[5]

1.6.2.8 flagS Struct Reference

1.6.2.8.1 Data Fields
1.6.2.8.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

DVRunTime.c

osr

unsigned osr

ping

unsigned ping

streamOn

unsigned streamOn

1.6.3 File Documentation

1.6.3.1 source/DVRunTime.c File Reference

This file contains the driver implementation for the dvruntime driver module.

#include "../../DVRT/DVRunTime.h"
#include "../../uart/uart2.h"
1.6.3.1.2 Functions
  • void DVRT_UART_RX_CallBack (void)

  • void DVRT_HandleCommand (void)

  • void DVRT_UART_WriteByte (uint8_t txData)

    This blocking function writes a byte of data to the selected UART.

  • void DVRT_WritePacket (void)

  • void DVRT_Error_Callback (void)

  • void DVRT_Initialize (void)

    Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.

  • void DVRT_Process (void)

    Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data, if required. Finally, it executes one-shot readings and ping commands.

1.6.3.1.3 Variables
1.6.3.1.4 Detailed Description

This file contains the driver implementation for the dvruntime driver module.

dvruntime Generated Driver Source File

Version: dvruntime Version 2.0.0.
1.6.3.1.5 Function Documentation
DVRT_Error_Callback()

void DVRT_Error_Callback (void )

DVRT_HandleCommand()

void DVRT_HandleCommand (void )

DVRT_UART_RX_CallBack()

void DVRT_UART_RX_CallBack (void )

Section: Driver Interface

DVRT_WritePacket()

void DVRT_WritePacket (void )

1.6.3.1.6 Variable Documentation
DVCmdInterval

uint16_t DVCmdInterval

DVCmdInterval_Counter

uint16_t DVCmdInterval_Counter

DVflag

struct flagS DVflag[static]

DVFrameCounter

volatile uint8_t DVFrameCounter[static]

dvIdFw

const volatile uint16_t dvIdFw = DV_FW_CODE

DVPMT

DVRT_VariablePointerTableEntry_t DVPMT[DYNAMIC_VAR_PTR_COUNT]

Section: Variables

DVRT_ReceivedCmd

volatile union DVCmds DVRT_ReceivedCmd

DVStreamInterval

uint16_t DVStreamInterval

DVStreamInterval_Counter

uint16_t DVStreamInterval_Counter

error

DVRT_error_t error

rxBufPtr

volatile uint8_t rxBufPtr

TIMER_DVRT

const struct TIMER_INTERFACE* TIMER_DVRT = &Timer0[static]

UART_DV

const uart_drv_interface_t* UART_DV = &UART3

Section: Included Files Section: Macro Declarations

USART_Error

size_t USART_Error[static]

1.6.3.2 source/DVRunTime.h File Reference

#include <stdbool.h>
#include <stdint.h>
#include "DVRunTime_interface.h"
#include "DVRunTime_types.h"
#include "DVRunTime_config.h"
1.6.3.2.1 Functions
  • void DVRT_Initialize (void)

    Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.

  • void DVRT_Process (void)

    Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data, if required. Finally, it executes one-shot readings and ping commands.

1.6.3.2.2 Macros
1.6.3.2.3 Variables
1.6.3.2.4 Detailed Description

dvruntime Generated Driver Header File

1.6.3.2.5 Macro Definition Documentation
EXTERN

#define EXTERN extern

1.6.3.3 source/DVRunTime_config.h File Reference

This file contains the macros for the configuration of the dvruntime module.

1.6.3.3.1 Macros
1.6.3.3.2 Detailed Description

This file contains the macros for the configuration of the dvruntime module.

dvruntime Generated Configuration Header File

Version: dvruntime Version 2.0.0.
1.6.3.3.3 Macro Definition Documentation
DV_END_OF_FRAME

#define DV_END_OF_FRAME 0xFC /* End Frame Byte */

DV_FW_CODE

#define DV_FW_CODE (uint16_t)261 /* Project Firmware Code */

DV_RX_CMD_MIN_SIZE

#define DV_RX_CMD_MIN_SIZE 3 /* Minimun number of byte in a RX command */

DV_RX_CMD_TIMEOUT

#define DV_RX_CMD_TIMEOUT 200 /* Command timeout: Timeout after number of times DVRT_process() is called */

DV_START_OF_FRAME

#define DV_START_OF_FRAME 0x03 /* Start Frame Byte */

DV_STREAM_TIME

#define DV_STREAM_TIME 20 /* Streaming time interval (time dependent on main loop tick) */

DYNAMIC_VAR_PTR_COUNT

#define DYNAMIC_VAR_PTR_COUNT 8 /* Number of Dynamic Variables Pointers in the Monitor Table */

1.6.3.4 source/DVRunTime_interface.h File Reference

Contains the function pointers to the DV Run Time library component.

#include <stdbool.h>
#include <stdint.h>
1.6.3.4.1 Data structures
  • struct DVRT_interface_t

    Structure containing the function pointers to the DV Run Time driver APIs.

1.6.3.4.2 Detailed Description

Contains the function pointers to the DV Run Time library component.

dvruntime Generated Interface Header File

Version: dvruntime Version 2.0.0.

1.6.3.5 source/DVRunTime_types.h File Reference

This file contains the data types used for the operation of the dvruntime module.

#include <stdbool.h>
#include <stdint.h>
#include "../uart/usart3.h"
#include "DVRunTime_config.h"
1.6.3.5.1 Data structures
  • struct DVRT_VariablePointerTableEntry

    Defines one entry of the Variable Pointer Table.

  • struct DVRT_StreamUpdates

    Defines the data structure for updating the stream of variables sent to the Data Visualizer.

  • struct DVRT_VariableUpdate

    Defines the data structure needed to update the Variable Pointer Table (DVPMT).

  • struct DVRT_StreamIntervalUpdate

    Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.

  • struct DVRT_CommandTemplate

    Typedef for struct containing the elements needed for a generic DVRT command.  

1.6.3.5.4 Detailed Description

This file contains the data types used for the operation of the dvruntime module.

dvruntime Generated Types Header File

Version: dvruntime Version 2.0.0.
1.6.3.5.5 Typedef Documentation
DVRT_CommandTemplate_t

typedef struct DVRT_CommandTemplate DVRT_CommandTemplate_t

DVRT_error_t

typedef size_t DVRT_error_t

DVRT_StreamIntervalUpdate_t

typedef struct DVRT_StreamIntervalUpdate DVRT_StreamIntervalUpdate_t

DVRT_StreamUpdates_t

typedef struct DVRT_StreamUpdates DVRT_StreamUpdates_t

DVRT_VariablePointerTableEntry_t

typedef struct DVRT_VariablePointerTableEntry DVRT_VariablePointerTableEntry_t

DVRT_VariableUpdate_t

typedef struct DVRT_VariableUpdate DVRT_VariableUpdate_t

1.6.3.5.6 Enumeration Type Documentation
anonymous enum

anonymous enum

UPDATE_VARIABLE_POINTER_TABLE
UPDATE_VARIABLE_VALUE
UPDATE_STREAMING_TICK
TURN_STREAMING_OFF
TURN_STREAMING_ON
ONE_SHOT_READ
PING

1.6.4 Module Documentation

1.6.4.1 DV Run Time Library Use Cases

1.6.4.1.1 DV Run Time Library Use Case Code Snippet Instructions

The use cases show example uses of the Data Visualizer Run Time feature, within an MCC Melody Project.

Add the following components and configure them as described in the specific example. Note: Fairly high system clock is required, but this can be lowered once done with the debugging/verification of application functionality with the DVRT.

Device Resources:
  1. Add DV Run Time.

System:
  • Clock Control:
    1. If DVRT does not work, try increasing system clock speed.

    2. Note: For AVRDx set main clock to at least 8 MHz main clock (default clock frequncy of 4 MHz is too slow).

  • Pins:
    1. Best practice: Enable (weak)pullup on UART Rx pin.  

1.6.4.1.2 DVRT Hello World: LED Toggle and Count Variables (Timer)
A LED is toggled after LED_period_ms (period of LED toggling in ms). LED_ON holds the state of the LED pin, meaning that when it is set to 0, an active low LED is on, and vice versa. Every 1 ms: DVRT_process( ) is called via a flag (msTick) set in the timer callback.
  • Count_msTicksSinceToggle is incremented up to toggle_ms, when LED_ON is toggled  

Device Resources:
  1. Add DV Run Time.

  2. Add a second Timer (besides the DVRT dependency).

DV Run Time:
  • Dependency Selector
    1. Select UART PLIB dependency: Check the schematic for the UART connected to the USB CDC UART (UART settings set by DVRT library).  

    2. Select Timer PLIB dependencies: Any timers can be chosen (leave in default configuration).

Second Timer:
  • Software Settings:
    1. Interrupt Driven: Yes (Timer default).

    2. Requested Timer Period: 1 ms (Timer default).

System Configuration:
  • Clock Control:
    1. If DVRT does not work, try increasing system clock speed.

    2. Note: For AVRDx set main clock to at least 8 MHz main clock (default clock frequncy of 4 MHz is too slow).

  • Pin Grid View:
    1. Select a LED pin (check schematic), and configure it as Output.

  • Pins View:
    1. LED pin: Custom name "IO_LED".

    2. UART Rx pin: Enable(weak) pullup.  

  • MCC Notifications:
    1. Check if any notifications, e.g. UART baud rate error less than 1%.

After configuring the components as described above click Generate to generate the code. Then add the following code snippets to your application:

DVRT Table:
  • Add the following variables:
    1. uint16_t Count_msTicksSinceToggle.

    2. uint16_t LED_period_ms.

    3. bool LED_ON.

/* Include for PIC16F/18F and AVR*/
#include "mcc_generated_files/system/system.h"
/* Includes for dsPIC and PIC24*/
#include "mcc_generated_files/system/system.h"
#include "mcc_generated_files/system/pins.h"
#include "mcc_generated_files/DVRT/DVRunTime.h"
#include "mcc_generated_files/timer/sccp1.h"   /* Replace with appropriate header from: .../timer/timerX.h */  
#include "mcc_generated_files/timer/sccp2.h"   /* Replace with appropriate header from: .../timer/timerX.h */  
#include <stdbool.h>
static volatile bool     LED_ON = false;
static volatile uint16_t LED_period_ms = 250U;
static volatile uint16_t Count_msTicksSinceToggle = 0U;
void Timer_Callback_1ms(void){
    Count_msTicksSinceToggle++;
    if(Count_msTicksSinceToggle >= LED_period_ms){
        LED_ON = !LED_ON;    // Toggle LED state variable
        IO_LED_Toggle();
        Count_msTicksSinceToggle = 0U;
    }
}
int main(void)
{
    SYSTEM_Initialize();
    INTERRUPT_GlobalInterruptEnable();   /* For PIC18F */
    /* Comment out for AVR: Enable Global IRQ in Interrupt Manager */
    /* Comment out for dsPIC, Global IRQs are enabled by default */
    
    /* Replace X with number of 2nd timer added */ 
    /* From name of const struct TIMER_INTERFACE, path: mcc_generated_files\timer\src\timerX.c */
    TimerX.TimeoutCallbackRegister(Timer_Callback_1ms); 

    while(1)
    {
    }    
}