Create Your First Motor Control Application Using MPLAB® Harmony v3: Step 2

Last modified by Microchip on 2023/11/09 09:07

Description on PDEC (HALL mode) in SAME54

  1. In Hall mode, COUNT register, CC0 and CC1 are split into two parts (MSB and LSB registers). The current hall value is available in the COUNT LSB (2:0).
  2. MC0 and MC1 Interrupt Flag bit is set (INTFLAG.MC[x]), if COUNT MSB register matches with CC[x] MSB.
  3. OVF interrupt will rise on match of CC0 LSB register against COUNT LSB register, which contains current hall code.
  4. Velocity Interrupt (VLC) will rise on whenever Hall state (values) changes.
  5. The window counter is checked to be between CC0 [MSB] and CC1 [MSB] value and reset to 0 value. If an error is detected, the Window Error bit in Status register (STATUS.WINERR) is set.
  6. If there is any change in the direction of the hall pattern, the DIR interrupt flag becomes active.
  7. The COUNT MSB gives the count of the window counter which runs on the PDEC clock.
Configure PDEC Peripheral Library and PDEC Pins

Under the bottom left Available Components tab, expand Peripherals > PDEC.
Double-click or drag and drop PDEC to add the PDEC Peripheral Library (PLIB) to the project graph.

Available Components tab

Once it is successfully added, PDEC will be listed under Active Components tab.

Active Components tab

Verify that the PDEC is set to run at 60 MHz GCLK1.

When a module is added to the project graph, MPLAB® Harmony Configurator (MHC) automatically enables the clock to the module. The default PDEC source is Generic Clock Controller 1 (GCLK1).

The default PDEC source is Generic Clock Controller 1 (GCLK1)

Go back to the project graph and configure the PDEC PLIB to HALL mode and check the Enable Velocity Interrupt box to read the Hall pattern at that event.

Enable Velocity Interrupt box

Open the Pin Configuration tab by clicking on MHC > Tools > Pin Configuration.

Pin Configuration tab

Select the MHC Pin Settings tab and sort the entries by Ports as shown:

Pin Settings tab

Select the PDEC Hall pins as:

Enable PDEC Hall A pin (PDEC_QDI0) on PC16 (Pin #70)
Enable PDEC Hall B pin (PDEC_QDI1) on PC17 (Pin #71)
Enable PDEC Hall C pin (PDEC_QDI2) on PC18 (Pin #72)

PDEC Hall pins

These Hall pins details are available in Chapter 1, "PIM to MCU Mapping" of "ATSAME54 100-Pin Motor Control Plug-In Module Information Sheet".

This completes the configuration of the PDEC peripheral library. This application code will use the PDEC PLIB Application Peripheral Interfaces (APIs) to read Hall values from the Hall sensor.

Configure TCC0 Peripheral Library and TCC0 Pins

Under the Available Components tab, expand Peripheral > TCC.
Double-click on TCC0 to add the TCC instance 0 to the project.

Available Components tab

As mentioned in Step 2.1, once TCC0 is successfully added, it will be listed under the Active Components tab.

When a module is added to the project graph, MHC automatically enables the clock to the module. The default TCC0 source is Generic Clock Controller 1 (GCLK1). You can verify the clock source using Clock Configuration view.

Go back to the project graph and configure the TCC0 PLIB to generate three pairs of single PWM signals at frequency of 25 kHz in Single Slope PWM mode.

Single Slope PWM mode

Select the MHC Pin Settings tab and select the waveform output pins as shown:

 Pin Settings tab

This completes the configuration of the TCC0 peripheral library. This application code will use the TCC0 PLIB Application Peripheral Interfaces (APIs) to generate the commutation pattern.

Configure ADC0 Peripheral Library

Under the Available Components tab, expand Peripheral > ADC.
Double-click on ADC0 to add the ADC instance 0 to the project.

Available Components tab

As mentioned in Step 2.1, ADC0 is successfully added and it will be listed under Active Components tab.

When a module is added to the project graph, MHC automatically enables the clock to the module. The default ADC0 source is Generic Clock Controller 1 (GCLK1). You can verify the clock source using Clock Configuration view.

Go back to the project graph and configure the ADC0 PLIB.

Configuration Options

ADC AIN6 (Channel 6) is selected here because the potentiometer signal of MLCV2 board is connected to this specific ADC channel 6. This information is available in Chapter 1, "PIM to MCU Mapping" of "ATSAME54 100-Pin Motor Control Plug-In Module Information Sheet".

This completes the configuration of ADC0 peripheral library. This application code will use the ADC0 PLIB Application Peripheral Interfaces (APIs) to read the output voltage of the potentiometer to determine the speed.

Configure TC0 and TC1 Instances in TC Peripheral Library

Under the Available Components tab, expand Peripheral > TC.
Double-click on TC0 to add the TC instance 0 to the project.

Available Components tab

As mentioned in Step 2.1, once TC0 is successfully added, it will be listed under the Active Components tab.

When a module is added to the project graph, MHC automatically enables the clock to the module. The default TC0 clock source is Generic Clock Controller 1 (GCLK1).

From the default clock GCLK1, change the clock source of TC0 to GCLK3 (8 MHz) as shown:

Change the clock source of TC0 to GCLK3 (8 MHz)

Go back to the project graph and check the Enable Timer Period Overflow Event box.

Enable Timer Period Overflow Event box

This completes the configuration of the TC0 peripheral library. This application code will use the TC0 as an internal 1 mS timer counter.

Under the Available Components tab, expand Peripheral > TC.
Double-click on TC1 to add the TC instance 1 to the project.

Adding TC1

Since TC0 and TC1 share the same clock bus, TC1 is assigned to the same clock source as theTC0 configuration. TC1 clock source is GCLK3 (8 MHz), the same as TC0.

Go back to the project graph and configure TC1 as shown:

Configuration Options

This completes the configuration of the TC1 peripheral library. This application code will use TC1 to measure the time elapsed between two consecutive hall edges.

In order to measure the low speed, the timer period is set to maximum level.

Configure Event System Peripheral Library
Event System (EVSYS) is added to the Project Graph by default.

Open the Event System Configuration tab by clicking on MHC > Tools > Event System Configuration.

Event System Configuration tab

Add Event channel and User by clicking the Add Channel button and the Add User button.

Select TCC0_OVF as Event Generator and ADC0_START as USER as shown:

Event System Manager window

This completes the configuration of EVSYS peripheral library. This application code will use event system (EVSYS) as a traffic controller between TCC0 (event generator) and ADC0 (event user).