Create Your First Motor Control Application Using MPLAB® Harmony v3: Step 2
Description on PDEC (HALL mode) in SAME54
- 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).
- MC0 and MC1 Interrupt Flag bit is set (INTFLAG.MC[x]), if COUNT MSB register matches with CC[x] MSB.
- OVF interrupt will rise on match of CC0 LSB register against COUNT LSB register, which contains current hall code.
- Velocity Interrupt (VLC) will rise on whenever Hall state (values) changes.
- 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.
- If there is any change in the direction of the hall pattern, the DIR interrupt flag becomes active.
- 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.
Once it is successfully added, PDEC will be listed under 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).
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.
Open the Pin Configuration tab by clicking on MHC > Tools > Pin Configuration.
Select the MHC Pin Settings tab and sort the entries by Ports as shown:
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)
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.
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.
Select the MHC Pin Settings tab and select the waveform output pins as shown:
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.
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.
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.
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:
Go back to the project graph and check the 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.
Go back to the project graph and configure TC1 as shown:
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
Open the Event System Configuration tab by clicking on MHC > Tools > Event System Configuration.
Select TCC0_OVF as Event Generator and ADC0_START as USER as shown:
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).