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

Last modified by Microchip on 2023/11/15 12:49

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 Device Resources tab, expand Peripherals > PDEC. Double-click or drag and drop PDEC to add the PDEC Peripheral Library (PLIB) to the project graph.

Add PDEC

Once it is successfully added, PDEC will be listed under Project Resources tab.

After Adding PDEC

 

Back to top


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

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

Clock PDEC

Back to top


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.

PDEC config

Back to top


Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration.

PDEC pin config

Back to top


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

PDEC pin settings

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 choosepin

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.

Back to top


Configure TCC0 Peripheral Library and TCC0 Pins

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

Add TCC0

Back to top


 As mentioned in "Configure PDEC Peripheral Library and PDEC Pins", once TCC0 is successfully added, it will be listed under the Project Resources tab.

When a module is added to the project graph, MCC 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.

Back to top


 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.

config TCC0

Back to top


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

TCC0 pinchoose

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.

Back to top


Configure ADC0 Peripheral Library

Under the Device Resources tab, expand Peripheral > ADC > ADC0. Double click on ADC0 to add the ADC instance 0 to the project.

add ADC

Back to top


As mentioned in "Configure PDEC Peripheral Library and PDEC Pins", ADC0 is successfully added and it will be listed under Project Resources tab.

When a module is added to the project graph, MCC 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.

Back to top


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

config ADC

ADC AIN6 (Channel 6) is selected here because the potentiometer signal of MCLV2 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.

Back to top


Configure TC0 and TC1 Instances in TC Peripheral Library

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

add TC

Back to top


As mentioned in "Configure PDEC Peripheral Library and PDEC Pins", once TC0 is successfully added, it will be listed under the Project Resources tab.

When a module is added to the project graph, MCC 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:

TC clockconfig

Back to top


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

TC config

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

Back to top


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

add TC1

Back to top


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.

Back to top


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

Config TC1

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.

Back to top


Configure Event System Peripheral Library

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

Back to top


Open the Event Configurator tabs by clicking Project Graph > Plugins > Event Configurator.

add EVEsys

Back to top


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

Back to top


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

config EVEsys

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).

Back to top