Measuring Power Consumption with PAC1934 Step 3: Configure MCU Resources with MCC

Last modified by Microchip on 2023/11/09 08:59

Launch MCC

Open the MCC plugin by clicking Tools > Embedded > MPLAB Code Configurator v4: Open/Close.

Opening the MCC from the Tools menu

Or, you may click the MCC logo in the toolbar.

MPLAB X toolbar with the MCC Icon highlighted

Use the same method to close MCC.

Note: MCC may take a while to load the first time it is launched. Upon loading for the first time, a window will pop up to save the MCC configuration file. Click Save.

Saving the MCC Configuration File

Back to Top

Configure System Module

Now you can start configuring the settings.

Click System Module in the upper left window.

Selecting System Module in the Project Resources window

For the System Module, we will use the FRC Oscillator as the Clock Source which is the default configuration. In this example code, we use a faster system clock by enabling the PLL. Enable the PLL by clicking the PLL Enable checkbox.

Click on the Prescaler drop-down menu and select 4:1. The Fosc value should be 32 MHz.

Setting Fosc Prescaler to 4:1 in System Module configuration window

Scroll down the System Module and go to the ICD section. Select Communicate on PGEC2 and PGED2 for the Emulator Pin Placement. These are the ICSP pins used in the PKOB on-board debugger/programmer.

ICD section of the System Module with 'Communicate on PGEC2 and PGED2' option selected

Back to Top

Configure GPIO

GPIO needs to be configured to drive LEDs and read switch values on the demonstration board.

Select Pin Manager: Grid View in the bottom right window. Click each pin with a green lock as either an input or output as shown in the figure below.

Using Pin Manager: Grid View to set IO pins as input or output

2 In the Pin Module window, at the top right corner, select the Easy Setup tab and configure the selected GPIO as follows.

Note: The Custom Name must match the table below for the libraries to build successfully. You may copy the Custom Name from the table below and paste it into the Pin Module Custom Name fields.

Pin NameFunctionCustom NameStart HighDirectionInterrupt-on-change
RA8GPIOLED_01NoOutputNone
RA9GPIOLED_02NoOutputNone
RA10GPIOOLED_CSNoOutputNone
RA11GPIOSWITCH_CHNoInputNegative Edge
RA12GPIOSWITCH_DEBUGNoInputNegative Edge
RA13GPIOMETER_RSTYesOutputNone
RA14GPIOOLED_RSTNoOutputNone
RC4GPIOOLED_DCNoOutputNone
RC8GPIOMETER_SLOWYesOutputNone

The Pin Module settings should look like the image below:

Setting IO pin names in Pin Module window

Back to Top

Configure UART

Now we will add the peripherals needed for the project and configure the PAC1934 MCC library. The UART will be configured to send information to the MCP2221A Breakout Module and display data on Tera Term.

Add UART1 by opening the UART folder in the Device Resources window and clicking the + icon for UART1 [PIC24/dsPIC33/PIC32MM MCUs by Microchip Technology, Inc.].

Adding UART1 from the UART folder in Device Resources window

In the UART1 configuration window, click the checkbox next to Redirect Printf to UART. This is used to display information to Tera Term.

UART1 configuration window

Back to Top

Configure Timer2

Timer2 is used to maintain state machine timing.

Add TMR2 by opening the Timer folder in the Device Resources window and clicking the + icon for TMR2.

Adding TMR2 peripheral from the Timer folder in Device Resources window

Update the TMR2 configuration window as follows:

  • Disable the TMR, this is needed for the customer callback in the application
  • Change the Prescaler to 1:64 to increase the Timer Period value
  • Change Timer Period value to 200 ms
  • Enable Timer Interrupt

Timer2 configuration window

Configure SPI

SPI is used to transfer information to be displayed on the OLED W Click.

Add SPI1 by opening the SPI folder in the Device Resources windows and clicking the + icon for SPI1 [PIC24/dsPIC33/PIC32MM MCUs by Microchip Technology, Inc.].

Adding SPI1 peripheral from SPI folder in Device Resources window

Verify Clock Edge is set to “Idle to Active” in the SPI1 configuration window.

SPI1 configuration window

Back to Top

Configure I2C

The I2C peripheral is used to communicate with the PAC1934 Click board. Both measurement data and control signals will be shared between the PIC24FJ256GA705 MCU and the PAC1934 metering IC using this communication channel.

Add I2C2 by opening the I2C folder in the Device Resources and clicking the + icon for I2C2 [PIC24/dsPIC33/PIC32MM MCUs by Microchip Technology, Inc.].

Adding I2C peripheral (I2C2) from the I2C folder in Device Resources window

Change the baud rate to 400000 Hz (400 kHz) to match the I2C2 configuration window below.

Setting baud rate to 400 kHz in I2C2 configuration window

Back to Top

Configure Interrupt Priorities

It is necessary to set up the interrupt priorities to ensure concurrent resource requests are resolved in the correct order.

Select the Interrupt Module in the Project Resource window.

Selecting Interrupt Module in Project Resources window

Disable I2C Slave Events and change the priority of Timer2 interrupt to 4 to match the example below.

MCC Interrupt Module Easy Setup: Changing TMR2 priority to 4

Back to Top

Configure Peripheral Pins

These assignments ensure the peripherals communicate using the correct pins on the demonstration board.

In the Pin Manager: Grid View window, in the lower right window tab, lock the following Modules to their assigned pins by clicking on the blue unlock symbol to turn it to a green lock:

  • SPI1: SCK1OUT to RC6
  • SPI1: SDI1 to RB9
  • SPI1: SDO1 to RC2
  • UART1: U1RX to RB8
  • UART1: U1TX to RB7

Once complete, the Pin Manager: Grid View window will look like this:

MCC Pin Manager: Grid View

Click Pin Module in the Project Resources window to check for consistency.

Note: Click the Function Column to sort the list according to Function for easier verification.

MCC Pin Module opened view to verify correct IO settings

Back to Top