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

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.

Step 2.1 - Configure PDEC Peripheral Library and PDEC Pins

1

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.

Add_PDEC.png

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

afteradd_PDEC.png

2

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

clock_PDEC.png

3

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

4

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

PDEC_pinconfig.png

5

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

PDEC_pinsettings.png

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

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.

Step 2.2 - Configure TCC0 Peripheral Library and TCC0 Pins

1

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

Add_TCC0.png

2

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.

3

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

4

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

TCC0_pinchoose.png

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.

Step 2.3 - Configure ADC0 Peripheral Library

1

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

add_ADC.png

2

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.

3

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

config_ADC.png

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.

Step 2.4 - Configure TC0 and TC1 Instances in TC Peripheral Library

1

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

add_TC.png

2

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:

TC_clockconfig.png

3

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

TC_config.png

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

4

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

add_TC1.png

5

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.

6

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

Config_TC1.png

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.

Step 2.5- Configure Event System Peripheral Library

1

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

2

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

add_EVEsys.png

3

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

4

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

config_EVEsys.png

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



Next Step >

© 2020 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.