Microchip® Advanced Software Framework

pwm.h File Reference

Pulse Width Modulation (PWM) driver for SAM.

Copyright (c) 2011-2019 Microchip Technology Inc. and its subsidiaries.

#include "compiler.h"

Data Structures

struct  pwm_channel_t
 Input parameters when configuring a PWM channel mode. More...
 
struct  pwm_clock_t
 Input parameters when initializing PWM. More...
 
struct  pwm_cmp_t
 Configurations of PWM comparison. More...
 
struct  pwm_fault_t
 Configuration of PWM fault input behaviors. More...
 
struct  pwm_output_t
 Configurations of a PWM channel output. More...
 
struct  pwm_protect_t
 Structure of PWM write-protect information. More...
 

Macros

#define PWM_INVALID_ARGUMENT   0xFFFF
 

Typedefs

typedef enum _pwm_ch_t pwm_ch_t
 Definitions for PWM channel number. More...
 

Enumerations

enum  _pwm_ch_t {
  PWM_CHANNEL_0 = 0,
  PWM_CHANNEL_1 = 1,
  PWM_CHANNEL_2 = 2,
  PWM_CHANNEL_3 = 3,
  PWM_CHANNEL_4 = 4,
  PWM_CHANNEL_5 = 5,
  PWM_CHANNEL_6 = 6,
  PWM_CHANNEL_7 = 7
}
 Definitions for PWM channel number. More...
 
enum  pmc_cmp_unit_t {
  PWM_CMP_UNIT_0 = 0,
  PWM_CMP_UNIT_1 = 1,
  PWM_CMP_UNIT_2 = 2,
  PWM_CMP_UNIT_3 = 3,
  PWM_CMP_UNIT_4 = 4,
  PWM_CMP_UNIT_5 = 5,
  PWM_CMP_UNIT_6 = 6,
  PWM_CMP_UNIT_7 = 7
}
 Definitions for PWM comparison unit. More...
 
enum  pwm_align_t {
  PWM_ALIGN_LEFT = (0 << 8),
  PWM_ALIGN_CENTER = (1 << 8)
}
 Definitions for PWM channel alignment. More...
 
enum  pwm_cmp_interrupt_t {
  PWM_CMP_MATCH = 8,
  PWM_CMP_UPDATE = 16
}
 Definitions for PWM comparison interrupt. More...
 
enum  pwm_counter_event_t {
  PWM_EVENT_PERIOD_END = (0 << 10),
  PWM_EVENT_PERIOD_HALF_END = (1 << 10)
}
 Definitions for PWM event. More...
 
enum  pwm_fault_id_t {
  PWM_FAULT_MAINOSC = (1 << 0),
  PWM_FAULT_PWMFI2 = (1 << 1),
  PWM_FAULT_PWMFI0 = (1 << 2),
  PWM_FAULT_PWMFI1 = (1 << 3)
}
 Definitions for PWM fault input ID. More...
 
enum  pwm_leading_edge_blanking_mode_t {
  PWM_LEADING_EDGE1_MODE_LINC = PWM_LEBR1_PWMLFEN,
  PWM_LEADING_EDGE1_MODE_LDEC = PWM_LEBR1_PWMLREN,
  PWM_LEADING_EDGE1_MODE_HINC = PWM_LEBR1_PWMHFEN,
  PWM_LEADING_EDGE1_MODE_HDEC = PWM_LEBR1_PWMHREN,
  PWM_LEADING_EDGE2_MODE_LINC = PWM_LEBR2_PWMLFEN,
  PWM_LEADING_EDGE2_MODE_LDEC = PWM_LEBR2_PWMLREN,
  PWM_LEADING_EDGE2_MODE_HINC = PWM_LEBR2_PWMHFEN,
  PWM_LEADING_EDGE2_MODE_HDEC = PWM_LEBR2_PWMHREN
}
 
enum  pwm_level_t {
  PWM_LOW = LOW,
  PWM_HIGH = HIGH,
  PWM_HIGHZ
}
 Definitions for PWM level. More...
 
enum  pwm_pdc_interrupt_t {
  PWM_PDC_TX_END = (1 << 1),
  PWM_PDC_TX_EMPTY = (1 << 2)
}
 Definitions for PWM PDC transfer interrupt. More...
 
enum  pwm_pdc_request_mode_t {
  PWM_PDC_UPDATE_PERIOD_ELAPSED = (0 << 20),
  PWM_PDC_COMPARISON_MATCH = (1 << 20)
}
 Definitions for PWM PDC transfer request mode. More...
 
enum  pwm_protect_reg_group_t {
  PWM_GROUP_CLOCK = (1 << 0),
  PWM_GROUP_DISABLE = (1 << 1),
  PWM_GROUP_MODE = (1 << 2),
  PWM_GROUP_PERIOD = (1 << 3),
  PWM_GROUP_DEAD_TIME = (1 << 4),
  PWM_GROUP_FAULT = (1 << 5)
}
 Definitions of PWM register group. More...
 
enum  pwm_spread_spectrum_mode_t {
  PWM_SPREAD_SPECTRUM_MODE_TRIANGULAR = 0,
  PWM_SPREAD_SPECTRUM_MODE_RANDOM
}
 
enum  pwm_stepper_motor_pair_t {
  PWM_STEPPER_MOTOR_CH_0_1 = 0,
  PWM_STEPPER_MOTOR_CH_2_3 = 1,
  PWM_STEPPER_MOTOR_CH_4_5 = 2,
  PWM_STEPPER_MOTOR_CH_6_7 = 3
}
 Definitions for PWM channels used by motor stepper. More...
 
enum  pwm_sync_interrupt_t {
  PWM_SYNC_WRITE_READY = (1 << 0),
  PWM_SYNC_UNDERRUN = (1 << 3)
}
 Definitions for PWM synchronous channels interrupt. More...
 
enum  pwm_sync_update_mode_t {
  PWM_SYNC_UPDATE_MODE_0 = PWM_SCM_UPDM_MODE0,
  PWM_SYNC_UPDATE_MODE_1 = PWM_SCM_UPDM_MODE1,
  PWM_SYNC_UPDATE_MODE_2 = PWM_SCM_UPDM_MODE2
}
 Definitions for PWM synchronous channels update mode. More...
 

Functions

void pwm_channel_disable (Pwm *p_pwm, uint32_t ul_channel)
 Disable the PWM channel. More...
 
void pwm_channel_disable_interrupt (Pwm *p_pwm, uint32_t ul_event, uint32_t ul_fault)
 Disable the interrupt of a channel counter event and fault protection. More...
 
void pwm_channel_enable (Pwm *p_pwm, uint32_t ul_channel)
 Enable the PWM channel. More...
 
void pwm_channel_enable_interrupt (Pwm *p_pwm, uint32_t ul_event, uint32_t ul_fault)
 Enable the interrupt of a channel counter event and fault protection. More...
 
uint32_t pwm_channel_get_counter (Pwm *p_pwm, pwm_channel_t *p_channel)
 Return channel counter value. More...
 
uint32_t pwm_channel_get_interrupt_mask (Pwm *p_pwm)
 Get channel counter event and fault protection trigger interrupt mask. More...
 
uint32_t pwm_channel_get_interrupt_status (Pwm *p_pwm)
 Get channel counter event and fault protection trigger interrupt status. More...
 
uint32_t pwm_channel_get_status (Pwm *p_pwm)
 Check which PWM channel is enabled. More...
 
uint32_t pwm_channel_init (Pwm *p_pwm, pwm_channel_t *p_channel)
 Initialize one PWM channel. More...
 
void pwm_channel_update_dead_time (Pwm *p_pwm, pwm_channel_t *p_channel, uint16_t us_deadtime_pwmh, uint16_t us_deadtime_pwml)
 Change dead-time value for PWM outputs. More...
 
uint32_t pwm_channel_update_duty (Pwm *p_pwm, pwm_channel_t *p_channel, uint32_t ul_duty)
 Change the duty cycle of the PWM channel. More...
 
void pwm_channel_update_output (Pwm *p_pwm, pwm_channel_t *p_channel, pwm_output_t *p_output, bool b_sync)
 Change output selection of the PWM channel. More...
 
uint32_t pwm_channel_update_period (Pwm *p_pwm, pwm_channel_t *p_channel, uint32_t ul_period)
 Change the period of the PWM channel. More...
 
void pwm_channel_update_polarity_mode (Pwm *p_pwm, pwm_channel_t *p_channel, bool polarity_inversion_flag, pwm_level_t polarity_value)
 Change polarity mode. More...
 
void pwm_channel_update_spread (Pwm *p_pwm, pwm_channel_t *p_channel, uint32_t ul_spread)
 Change spread spectrum value. More...
 
uint32_t pwm_cmp_change_setting (Pwm *p_pwm, pwm_cmp_t *p_cmp)
 Change the setting of PWM comparison. More...
 
void pwm_cmp_disable_interrupt (Pwm *p_pwm, uint32_t ul_sources, pwm_cmp_interrupt_t type)
 Disable the interrupt of comparison. More...
 
void pwm_cmp_enable_interrupt (Pwm *p_pwm, uint32_t ul_sources, pwm_cmp_interrupt_t type)
 Enable the interrupt of comparison. More...
 
uint32_t pwm_cmp_get_period_counter (Pwm *p_pwm, uint32_t ul_cmp_unit)
 Report the value of the comparison period counter. More...
 
uint32_t pwm_cmp_get_update_counter (Pwm *p_pwm, uint32_t ul_cmp_unit)
 Report the value of the comparison update period counter. More...
 
uint32_t pwm_cmp_init (Pwm *p_pwm, pwm_cmp_t *p_cmp)
 Initialize PWM comparison unit. More...
 
void pwm_disable_protect (Pwm *p_pwm, uint32_t ul_group)
 Disable PWM write protect. More...
 
void pwm_enable_protect (Pwm *p_pwm, uint32_t ul_group, bool b_sw)
 Enable PWM write protect. More...
 
void pwm_fault_clear_status (Pwm *p_pwm, pwm_fault_id_t id)
 Clear a fault input. More...
 
pwm_level_t pwm_fault_get_input_level (Pwm *p_pwm, pwm_fault_id_t id)
 Get the level of a fault input. More...
 
uint32_t pwm_fault_get_status (Pwm *p_pwm)
 Get fault status. More...
 
uint32_t pwm_fault_init (Pwm *p_pwm, pwm_fault_t *p_fault)
 Initialize the behavior of a fault input. More...
 
uint32_t pwm_get_interrupt_mask (Pwm *p_pwm)
 Get interrupt mask of PDC transfer, synchronous channels and comparison. More...
 
uint32_t pwm_get_interrupt_status (Pwm *p_pwm)
 Get interrupt status of PDC transfer, synchronous channels and comparison. More...
 
bool pwm_get_protect_status (Pwm *p_pwm, pwm_protect_t *p_protect)
 Get PWM write protect status. More...
 
uint32_t pwm_init (Pwm *p_pwm, pwm_clock_t *clock_config)
 Initialize the PWM source clock (clock A and clock B). More...
 
void pwm_pdc_disable_interrupt (Pwm *p_pwm, uint32_t ul_sources)
 Disable the interrupt of PDC transfer. More...
 
void pwm_pdc_enable_interrupt (Pwm *p_pwm, uint32_t ul_sources)
 Enable the interrupt of PDC transfer. More...
 
void pwm_pdc_set_request_mode (Pwm *p_pwm, pwm_pdc_request_mode_t request_mode, uint32_t ul_cmp_unit)
 Set PDC transfer request mode. More...
 
void pwm_set_dma_duty (Pwm *p_pwm, uint32_t ul_dma_duty_value)
 Set dma duty. More...
 
void pwm_set_ext_trigger_mode (Pwm *p_pwm, pwm_channel_t *p_channel, uint32_t ul_mode)
 set external trigger mode. More...
 
void pwm_stepper_motor_init (Pwm *p_pwm, pwm_stepper_motor_pair_t pair, bool b_enable_gray, bool b_down)
 Initialize PWM stepper motor mode. More...
 
void pwm_sync_change_period (Pwm *p_pwm, uint32_t ul_update_period)
 Change the wanted time between each update of the synchronous channels. More...
 
void pwm_sync_disable_interrupt (Pwm *p_pwm, uint32_t ul_sources)
 Disable the interrupt of synchronous channels. More...
 
void pwm_sync_enable_interrupt (Pwm *p_pwm, uint32_t ul_sources)
 Enable the interrupt of synchronous channel. More...
 
uint32_t pwm_sync_get_period_counter (Pwm *p_pwm)
 Get the value of the synchronization update period counter. More...
 
uint32_t pwm_sync_init (Pwm *p_pwm, pwm_sync_update_mode_t mode, uint32_t ul_update_period)
 Initialize synchronous channels update mode and period. More...
 
void pwm_sync_unlock_update (Pwm *p_pwm)
 Unlock the update of synchronous channels. More...
 

#define PWM_INVALID_ARGUMENT   0xFFFF

typedef enum _pwm_ch_t pwm_ch_t

Definitions for PWM channel number.

enum _pwm_ch_t

Definitions for PWM channel number.

Enumerator
PWM_CHANNEL_0 
PWM_CHANNEL_1 
PWM_CHANNEL_2 
PWM_CHANNEL_3 
PWM_CHANNEL_4 
PWM_CHANNEL_5 
PWM_CHANNEL_6 
PWM_CHANNEL_7 

Definitions for PWM comparison unit.

Enumerator
PWM_CMP_UNIT_0 
PWM_CMP_UNIT_1 
PWM_CMP_UNIT_2 
PWM_CMP_UNIT_3 
PWM_CMP_UNIT_4 
PWM_CMP_UNIT_5 
PWM_CMP_UNIT_6 
PWM_CMP_UNIT_7 

Definitions for PWM channel alignment.

Enumerator
PWM_ALIGN_LEFT 
PWM_ALIGN_CENTER 

Definitions for PWM comparison interrupt.

Enumerator
PWM_CMP_MATCH 
PWM_CMP_UPDATE 

Definitions for PWM event.

Enumerator
PWM_EVENT_PERIOD_END 
PWM_EVENT_PERIOD_HALF_END 

Definitions for PWM fault input ID.

Enumerator
PWM_FAULT_MAINOSC 
PWM_FAULT_PWMFI2 
PWM_FAULT_PWMFI0 
PWM_FAULT_PWMFI1 
Enumerator
PWM_LEADING_EDGE1_MODE_LINC 
PWM_LEADING_EDGE1_MODE_LDEC 
PWM_LEADING_EDGE1_MODE_HINC 
PWM_LEADING_EDGE1_MODE_HDEC 
PWM_LEADING_EDGE2_MODE_LINC 
PWM_LEADING_EDGE2_MODE_LDEC 
PWM_LEADING_EDGE2_MODE_HINC 
PWM_LEADING_EDGE2_MODE_HDEC 

Definitions for PWM level.

Enumerator
PWM_LOW 
PWM_HIGH 
PWM_HIGHZ 

Definitions for PWM PDC transfer interrupt.

Enumerator
PWM_PDC_TX_END 
PWM_PDC_TX_EMPTY 

Definitions for PWM PDC transfer request mode.

Enumerator
PWM_PDC_UPDATE_PERIOD_ELAPSED 
PWM_PDC_COMPARISON_MATCH 

Definitions of PWM register group.

Enumerator
PWM_GROUP_CLOCK 
PWM_GROUP_DISABLE 
PWM_GROUP_MODE 
PWM_GROUP_PERIOD 
PWM_GROUP_DEAD_TIME 
PWM_GROUP_FAULT 
Enumerator
PWM_SPREAD_SPECTRUM_MODE_TRIANGULAR 
PWM_SPREAD_SPECTRUM_MODE_RANDOM 

Definitions for PWM channels used by motor stepper.

Enumerator
PWM_STEPPER_MOTOR_CH_0_1 
PWM_STEPPER_MOTOR_CH_2_3 
PWM_STEPPER_MOTOR_CH_4_5 
PWM_STEPPER_MOTOR_CH_6_7 

Definitions for PWM synchronous channels interrupt.

Enumerator
PWM_SYNC_WRITE_READY 
PWM_SYNC_UNDERRUN 

Definitions for PWM synchronous channels update mode.

Enumerator
PWM_SYNC_UPDATE_MODE_0 
PWM_SYNC_UPDATE_MODE_1 
PWM_SYNC_UPDATE_MODE_2