SAMV71 Xplained Ultra Software Package 1.4

pwmc.h File Reference

#include "chip.h"
#include <stdint.h>

Go to the source code of this file.

Functions

void PWMC_ConfigureChannel (Pwm *pPwm, uint8_t channel, uint32_t prescaler, uint32_t alignment, uint32_t polarity)
 Configures PWM a channel with the given parameters, basic configure function.
void PWMC_ConfigureChannelExt (Pwm *pPwm, uint8_t channel, uint32_t prescaler, uint32_t alignment, uint32_t polarity, uint32_t countEventSelect, uint32_t DTEnable, uint32_t DTHInverte, uint32_t DTLInverte)
 Configures PWM a channel with the given parameters, extend configure function. The PWM controller must have been clocked in the PMC prior to calling this function. Beware: this function disables the channel. It waits until disable is effective.
void PWMC_ConfigureClocks (Pwm *pPwm, uint32_t clka, uint32_t clkb, uint32_t mck)
 Configures PWM clocks A & B to run at the given frequencies.
void PWMC_SetPeriod (Pwm *pPwm, uint8_t channel, uint16_t period)
 Sets the period value used by a PWM channel.
void PWMC_SetDutyCycle (Pwm *pPwm, uint8_t channel, uint16_t duty)
 Sets the duty cycle used by a PWM channel. This function writes directly to the CDTY register if the channel is disabled; otherwise it uses the update register CDTYUPD. Note that the duty cycle must always be inferior or equal to the channel period.
void PWMC_SetDeadTime (Pwm *pPwm, uint8_t channel, uint16_t timeH, uint16_t timeL)
 Sets the dead time used by a PWM channel. This function writes directly to the DT register if the channel is disabled; otherwise it uses the update register DTUPD. Note that the dead time must always be inferior or equal to the channel period.
void PWMC_ConfigureSyncChannel (Pwm *pPwm, uint32_t channels, uint32_t updateMode, uint32_t requestMode, uint32_t requestComparisonSelect)
 Configures Synchronous channel with the given parameters. Beware: At this time, the channels should be disabled.
void PWMC_SetSyncChannelUpdatePeriod (Pwm *pPwm, uint8_t period)
 Sets the update period of the synchronous channels. This function writes directly to the SCUP register if the channel #0 is disabled; otherwise it uses the update register SCUPUPD.
void PWMC_SetSyncChannelUpdateUnlock (Pwm *pPwm)
 Sets synchronous channels update unlock.
void PWMC_EnableChannel (Pwm *pPwm, uint8_t channel)
 Enables the given PWM channel.
void PWMC_DisableChannel (Pwm *pPwm, uint8_t channel)
 Disables the given PWM channel.
void PWMC_EnableChannelIt (Pwm *pPwm, uint8_t channel)
 Enables the period interrupt for the given PWM channel.
void PWMC_DisableChannelIt (Pwm *pPwm, uint8_t channel)
 Disables the period interrupt for the given PWM channel.
void PWMC_EnableIt (Pwm *pPwm, uint32_t sources1, uint32_t sources2)
 Enables the selected interrupts sources on a PWMC peripheral.
void PWMC_DisableIt (Pwm *pPwm, uint32_t sources1, uint32_t sources2)
 Disables the selected interrupts sources on a PWMC peripheral.
uint8_t PWMC_WriteBuffer (Pwm *pwmc, void *buffer, uint32_t length)
void PWMC_SetOverrideValue (Pwm *pPwm, uint32_t value)
 Set PWM output override value.
void PWMC_EnableOverrideOutput (Pwm *pPwm, uint32_t value, uint32_t sync)
 Enable override output.
void PWMC_OutputOverrideSelection (Pwm *pPwm, uint32_t value)
 Output Selection for override PWM output.
void PWMC_DisableOverrideOutput (Pwm *pPwm, uint32_t value, uint32_t sync)
 Disable override output.
void PWMC_SetFaultMode (Pwm *pPwm, uint32_t mode)
 Set PWM fault mode.
void PWMC_FaultClear (Pwm *pPwm, uint32_t fault)
 PWM fault clear.
void PWMC_SetFaultProtectionValue (Pwm *pPwm, uint32_t value)
 Set PWM fault protection value.
void PWMC_EnableFaultProtection (Pwm *pPwm, uint32_t value)
 Enable PWM fault protection.
void PWMC_ConfigureComparisonUnit (Pwm *pPwm, uint32_t x, uint32_t value, uint32_t mode)
 Configure comparison unit.
void PWMC_ConfigureEventLineMode (Pwm *pPwm, uint32_t x, uint32_t mode)
 Configure event line mode.
uint32_t PWMC_GetStatus2 (Pwm *pPwm)
 Return PWM Interrupt Status2 Register.

Detailed Description

Purpose

Interface for configuration the Pulse Width Modulation Controller (PWM) peripheral.

Usage
  1. Configures PWM clocks A & B to run at the given frequencies using PWMC_ConfigureClocks().
  2. Configure PWMC channel using PWMC_ConfigureChannel(), PWMC_ConfigureChannelExt() PWMC_SetPeriod(), PWMC_SetDutyCycle() and PWMC_SetDeadTime().
  3. Enable & disable channel using PWMC_EnableChannel() and PWMC_DisableChannel().
  4. Enable & disable the period interrupt for the given PWM channel using PWMC_EnableChannelIt() and PWMC_DisableChannelIt().
  5. Enable & disable the selected interrupts sources on a PWMC peripheral using PWMC_EnableIt() and PWMC_DisableIt().
  6. Control synchronous channel using PWMC_ConfigureSyncChannel(), PWMC_SetSyncChannelUpdatePeriod() and PWMC_SetSyncChannelUpdateUnlock().
  7. Control PWM override output using PWMC_SetOverrideValue(), PWMC_EnableOverrideOutput() and PWMC_DisableOverrideOutput().
  8. Send data through the transmitter using PWMC_WriteBuffer().

Definition in file pwmc.h.


Function Documentation

void PWMC_ConfigureChannel ( Pwm pPwm,
uint8_t  channel,
uint32_t  prescaler,
uint32_t  alignment,
uint32_t  polarity 
)

Configures PWM a channel with the given parameters, basic configure function.

The PWM controller must have been clocked in the PMC prior to calling this function. Beware: this function disables the channel. It waits until disable is effective.

Parameters:
channel Channel number.
prescaler Channel prescaler.
alignment Channel alignment.
polarity Channel polarity.

Definition at line 146 of file pwmc.c.

void PWMC_ConfigureChannelExt ( Pwm pPwm,
uint8_t  channel,
uint32_t  prescaler,
uint32_t  alignment,
uint32_t  polarity,
uint32_t  countEventSelect,
uint32_t  DTEnable,
uint32_t  DTHInverte,
uint32_t  DTLInverte 
)

Configures PWM a channel with the given parameters, extend configure function. The PWM controller must have been clocked in the PMC prior to calling this function. Beware: this function disables the channel. It waits until disable is effective.

Parameters:
channel Channel number.
prescaler Channel prescaler.
alignment Channel alignment.
polarity Channel polarity.
countEventSelect Channel counter event selection.
DTEnable Channel dead time generator enable.
DTHInverte Channel Dead-Time PWMHx output Inverted.
DTLInverte Channel Dead-Time PWMHx output Inverted.

Definition at line 185 of file pwmc.c.

void PWMC_ConfigureClocks ( Pwm pPwm,
uint32_t  clka,
uint32_t  clkb,
uint32_t  mck 
)

Configures PWM clocks A & B to run at the given frequencies.

This function finds the best MCK divisor and prescaler values automatically.

Parameters:
clka Desired clock A frequency (0 if not used).
clkb Desired clock B frequency (0 if not used).
mck Master clock frequency.

Definition at line 224 of file pwmc.c.

void PWMC_ConfigureComparisonUnit ( Pwm pPwm,
uint32_t  x,
uint32_t  value,
uint32_t  mode 
)

Configure comparison unit.

Parameters:
x comparison x index
value comparison x value.
mode comparison x mode

Definition at line 548 of file pwmc.c.

void PWMC_ConfigureEventLineMode ( Pwm pPwm,
uint32_t  x,
uint32_t  mode 
)

Configure event line mode.

Parameters:
x Line x
mode Bitwise OR of line mode selection

Definition at line 569 of file pwmc.c.

void PWMC_ConfigureSyncChannel ( Pwm pPwm,
uint32_t  channels,
uint32_t  updateMode,
uint32_t  requestMode,
uint32_t  requestComparisonSelect 
)

Configures Synchronous channel with the given parameters. Beware: At this time, the channels should be disabled.

Parameters:
channels Bitwise OR of Synchronous channels.
updateMode Synchronous channel update mode.
requestMode PDC transfer request mode.
requestComparisonSelect PDC transfer request comparison selection.

Definition at line 326 of file pwmc.c.

void PWMC_DisableChannel ( Pwm pPwm,
uint8_t  channel 
)

Disables the given PWM channel.

Beware, channel will be effectively disabled at the end of the current period. Application can check channel is disabled using the following wait loop: while ((PWM->PWM_SR & (1 << channel)) != 0);

Parameters:
channel Channel number.

Definition at line 390 of file pwmc.c.

void PWMC_DisableChannelIt ( Pwm pPwm,
uint8_t  channel 
)

Disables the period interrupt for the given PWM channel.

Parameters:
channel Channel number.

Definition at line 419 of file pwmc.c.

void PWMC_DisableIt ( Pwm pPwm,
uint32_t  sources1,
uint32_t  sources2 
)

Disables the selected interrupts sources on a PWMC peripheral.

Parameters:
sources1 Bitwise OR of selected interrupt sources of PWM_IDR1.
sources2 Bitwise OR of selected interrupt sources of PWM_IDR2.

Definition at line 442 of file pwmc.c.

void PWMC_DisableOverrideOutput ( Pwm pPwm,
uint32_t  value,
uint32_t  sync 
)

Disable override output.

Parameters:
value Bitwise OR of output selection.
sync 0: enable the output asynchronously, 1: enable it synchronously

Definition at line 490 of file pwmc.c.

void PWMC_EnableChannel ( Pwm pPwm,
uint8_t  channel 
)

Enables the given PWM channel.

This does NOT enable the corresponding pin;this must be done in the user code.

Parameters:
channel Channel number.

Definition at line 376 of file pwmc.c.

void PWMC_EnableChannelIt ( Pwm pPwm,
uint8_t  channel 
)

Enables the period interrupt for the given PWM channel.

Parameters:
channel Channel number.

Definition at line 400 of file pwmc.c.

void PWMC_EnableFaultProtection ( Pwm pPwm,
uint32_t  value 
)

Enable PWM fault protection.

Parameters:
value Bitwise OR of FPEx[y].

Definition at line 536 of file pwmc.c.

void PWMC_EnableIt ( Pwm pPwm,
uint32_t  sources1,
uint32_t  sources2 
)

Enables the selected interrupts sources on a PWMC peripheral.

Parameters:
sources1 Bitwise OR of selected interrupt sources of PWM_IER1.
sources2 Bitwise OR of selected interrupt sources of PWM_IER2.

Definition at line 430 of file pwmc.c.

void PWMC_EnableOverrideOutput ( Pwm pPwm,
uint32_t  value,
uint32_t  sync 
)

Enable override output.

Parameters:
value Bitwise OR of output selection.
sync 0: enable the output asynchronously, 1: enable it synchronously

Definition at line 464 of file pwmc.c.

void PWMC_FaultClear ( Pwm pPwm,
uint32_t  fault 
)

PWM fault clear.

Parameters:
fault Bitwise OR of fault to clear.

Definition at line 516 of file pwmc.c.

void PWMC_OutputOverrideSelection ( Pwm pPwm,
uint32_t  value 
)

Output Selection for override PWM output.

Parameters:
value Bitwise OR of output override value.

Definition at line 478 of file pwmc.c.

void PWMC_SetDeadTime ( Pwm pPwm,
uint8_t  channel,
uint16_t  timeH,
uint16_t  timeL 
)

Sets the dead time used by a PWM channel. This function writes directly to the DT register if the channel is disabled; otherwise it uses the update register DTUPD. Note that the dead time must always be inferior or equal to the channel period.

Parameters:
channel Channel number.
timeH Dead time value for PWMHx output.
timeL Dead time value for PWMLx output.

Definition at line 303 of file pwmc.c.

void PWMC_SetDutyCycle ( Pwm pPwm,
uint8_t  channel,
uint16_t  duty 
)

Sets the duty cycle used by a PWM channel. This function writes directly to the CDTY register if the channel is disabled; otherwise it uses the update register CDTYUPD. Note that the duty cycle must always be inferior or equal to the channel period.

Parameters:
channel Channel number.
duty Duty cycle value.

Definition at line 279 of file pwmc.c.

void PWMC_SetFaultMode ( Pwm pPwm,
uint32_t  mode 
)

Set PWM fault mode.

Parameters:
mode Bitwise OR of fault mode.

Definition at line 506 of file pwmc.c.

void PWMC_SetFaultProtectionValue ( Pwm pPwm,
uint32_t  value 
)

Set PWM fault protection value.

Parameters:
value Bitwise OR of fault protection value.

Definition at line 526 of file pwmc.c.

void PWMC_SetOverrideValue ( Pwm pPwm,
uint32_t  value 
)

Set PWM output override value.

Parameters:
value Bitwise OR of output override value.

Definition at line 453 of file pwmc.c.

void PWMC_SetPeriod ( Pwm pPwm,
uint8_t  channel,
uint16_t  period 
)

Sets the period value used by a PWM channel.

This function writes directly to the CPRD register if the channel is disabled; otherwise, it uses the update register CPRDUPD.

Parameters:
channel Channel number.
period Period value.

Definition at line 257 of file pwmc.c.

void PWMC_SetSyncChannelUpdatePeriod ( Pwm pPwm,
uint8_t  period 
)

Sets the update period of the synchronous channels. This function writes directly to the SCUP register if the channel #0 is disabled; otherwise it uses the update register SCUPUPD.

Parameters:
period update period.

Definition at line 342 of file pwmc.c.

void PWMC_SetSyncChannelUpdateUnlock ( Pwm pPwm  ) 

Sets synchronous channels update unlock.

Note: If the UPDM field is set to 0, writing the UPDULOCK bit to 1 triggers the update of the period value, the duty-cycle and the dead-time values of synchronous channels at the beginning of the next PWM period. If the field UPDM is set to 1 or 2, writing the UPDULOCK bit to 1 triggers only the update of the period value and of the dead-time values of synchronous channels. This bit is automatically reset when the update is done.

Definition at line 364 of file pwmc.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines