4.18 WEX - Waveform Extension

4.18.1 Introduction

The Waveform Extension (WEX) provides extra functions to the timer/counter in Waveform Generation (WG) modes. It is primarily intended for use in different types of motor control and other power control applications.

4.18.2 Supported Device Families

AVR® EB

4.18.3 Required header files:


#include "mcc_generated_files/timer/wex[X].h"
Note: Replace [X] with the selected instance number of the WEX module.

4.18.4 Module Documentation

4.18.4.1 WEX0

This document contains the implementation of the public and private functions for the Waveform Extension (WEX0) module.

4.18.4.1.1 Module description

This document contains the implementation of the public and private functions for the Waveform Extension (WEX0) module.

This document contains the API prototypes and the data types for the WEX0 driver.

Version: WEX0 Driver Version 1.0.0
Typedefs
  • typedef void(* WEX0_cb_t) (void)

    This is the function pointer that accesses the callback function, whenever an interrupt occurs or a fault is detected.

Definitions
  • #define WEX0_NS_TO_TICKS(VALUE, F_CLOCK, WEX_PRESCALER) (uint8_t)( (float)(VALUE) / ( (1000000000.0 / (F_CLOCK) ) * (WEX_PRESCALER) ) + 0.5)

    Defines the macro associated with the conversion from ns(nanoseconds) to clock increments.  

    Used for setting the dead time or blanking time.  

    The user must specify the desired value in ns(nanoseconds), the clock speed and the prescaler.

Functions
Variables
  • static WEX0_cb_t WEX0_FAULT_isr_cb = NULL

    This is the function pointer that accesses the callback, when an interrupt occurs or a fault is detected.

4.18.4.1.2 Definition Documentation

WEX0_NS_TO_TICKS

#define WEX0_NS_TO_TICKS( VALUE, F_CLOCK, WEX_PRESCALER) (uint8_t)( (float)(VALUE) / ( (1000000000.0 / (F_CLOCK) ) * (WEX_PRESCALER) ) + 0.5)

Defines the macro associated with the conversion from ns(nanoseconds) to clock increments.  

Used for setting the dead time or blanking time.  

The user must specify the desired value in ns(nanoseconds), the clock speed and the prescaler.

The macro arguments:
  • VALUE must be a constant number rather than a variable

  • F_CLOCK is the WEX peripheral clock

  • WEX_PRESCALER can be 1, 2, 4, 8, 16, 64, 256, 1024

4.18.4.1.3 Typedef Documentation

WEX0_cb_t

void * WEX0_cb_t

This is the function pointer that accesses the callback function, whenever an interrupt occurs or a fault is detected.

Parameters:

4.18.4.1.4 Function Documentation

ISR()

ISR (WEX0_FAULT_vect )

Fault Interrupt Service Routine (ISR) routine.

WEX0_BlankingPrescaler()

void WEX0_BlankingPrescaler (WEX_BLANKPRESC_t prescaler)

Sets the blanking prescaler for the WEX0 peripheral.

Precondition:

None.

Parameters:
WEX_BLANKPRESC_t

pre - enum that specifies the value of the prescaler, which can be 1, 4, 16 or 64.

Returns:

None.

WEX0_BlankingTimeGet()

uint8_t WEX0_BlankingTimeGet (void )

Gets the blanking time for the WEX0 peripheral.

Precondition:

None.

Parameters:
None.
Returns:

uint8_t - the blanking time that was previously set.

WEX0_BlankingTimeSet()

void WEX0_BlankingTimeSet (uint8_t cnt)

Sets the blanking time for the WEX0 peripheral. If prescaler is used this time can be extended.

Precondition:

None.

Parameters:
uint8_t

cnt - uint8_t that represents the blanking time given in a number of clock ticks, with a range between 0 and 255.

Returns:

None.

WEX0_BlankingTrigger()

void WEX0_BlankingTrigger (WEX_BLANKTRIG_t trig)

Sets the blanking trigger command for the WEX0 peripheral. It can be software of hardware.

Precondition:

None.

Parameters:
WEX_BLANKTRIG_t

trig - enum that specifies the blanking trigger source, which can be on timer update condition, on compare channels match, or software.

Returns:

None.

WEX0_BlankingTriggerSource()

void WEX0_BlankingTriggerSource (WEX_BLANKSRC_t source)

Sets the blanking trigger source for the WEX0 peripheral.

Precondition:

None.

Parameters:
WEX_BLANKSRC_t

source - enum that specifies the blanking trigger source - source is PWM0, false - source is PWM1.

Returns:

None.

WEX0_DeadTimeBothSidesBufferSet()

void WEX0_DeadTimeBothSidesBufferSet (uint8_t buff)

Sets the dead time on both sides of the output signals using a buffer register on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

buff - specifies the value of the dead time inserted on both sides of the output signals using a buffer given in clock ticks.

Returns:

None.

WEX0_DeadTimeBothSidesSet()

void WEX0_DeadTimeBothSidesSet (uint8_t cnt)

Sets the dead time on both sides of the side output signals on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

cnt - represents the value of the dead time on both sides, with a range between 0 and 255.

Returns:

None.

WEX0_DeadTimeHighSideBufferSet()

void WEX0_DeadTimeHighSideBufferSet (uint8_t buff)

Sets the dead time on the high side of the output signals using a buffer register on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

buff - specifies the value of the dead time inserted on the high side of the output signals using a buffer, given in clock ticks.

Returns:

None.

WEX0_DeadTimeHighSideSet()

void WEX0_DeadTimeHighSideSet (uint8_t cnt)

Sets the dead time on the high side of the output signals on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

cnt - represents the value of the dead time on the high side, with a range between 0 and 255.

Returns:

None.

WEX0_DeadTimeInsertionSet()

void WEX0_DeadTimeInsertionSet (uint8_t channels)

Used to enable the dead time insertion on each of the waveform output channels.

Precondition:

None.

Parameters:
uint8_t

channels - represents the channels that will have the dead time insertion enabled.

Returns:

None.

WEX0_DeadTimeLowSideBufferSet()

void WEX0_DeadTimeLowSideBufferSet (uint8_t buff)

Sets the dead time on the low side of the output signals using a buffer register on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

buff - specifies the value of the dead time inserted on the low side of the output signals using a buffer, given in clock ticks.

Returns:

None.

WEX0_DeadTimeLowSideSet()

void WEX0_DeadTimeLowSideSet (uint8_t cnt)

Sets the dead time on the low side of the output signals on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

cnt - represents the value of the dead time on the low side, with a range between 0 and 255.

Returns:

None.

WEX0_Deinitialize()

void WEX0_Deinitialize (void )

Deinitializes the WEX0 module.

Precondition:

None.

Parameters:
None.
Returns:

None.

WEX0_FaultAEventBlankingEnable()

void WEX0_FaultAEventBlankingEnable (bool en)

Enables fault blanking time on event A for the WEX0 peripheral.

Precondition:

None.

Parameters:
bool

en - boolean value is true if enabled, and false if disabled.

Returns:

None.

WEX0_FaultAEventFilter()

void WEX0_FaultAEventFilter (WEX_FILTER_t samples)

Filters event input A of the WEX0 peripheral.

Precondition:

None.

Parameters:
WEX_FILTER_t

samples - enum that represents the number of samples filtered for an event to go through, with a range between 0 and 7 samples.

Returns:

None.

WEX0_FaultAEventInputEnable()

void WEX0_FaultAEventInputEnable (bool en)

Enables event input A for the WEX0 peripheral.

Precondition:

None.

Parameters:
bool

en - boolean that has value true if enabled, false if disabled.

Returns:

None.

WEX0_FaultBEventBlankingEnable()

void WEX0_FaultBEventBlankingEnable (bool en)

Enables fault blanking time on event B for the WEX0 peripheral.

Precondition:

None.

Parameters:
bool

en - boolean value is true if enabled, and false if disabled.

Returns:

None.

WEX0_FaultBEventFilter()

void WEX0_FaultBEventFilter (WEX_FILTER_t samples)

Filters event input B of the WEX0 peripheral.

Precondition:

None.

Parameters:
WEX_FILTER_t

samples - enum that represents the number of samples filtered for an event to go through, with a range between 0 and 7 samples.

Returns:

None.

WEX0_FaultBEventInputEnable()

void WEX0_FaultBEventInputEnable (bool en)

Enables event input B for the WEX0 peripheral.

Precondition:

None.

Parameters:
bool

en - boolean that has value true if enabled, false if disabled.

Returns:

None.

WEX0_FaultCEventBlankingEnable()

void WEX0_FaultCEventBlankingEnable (bool en)

Enables fault blanking time on event C for the WEX0 peripheral.

Precondition:

None.

Parameters:
bool

en - boolean value is true if enabled, and false if disabled.

Returns:

None.

WEX0_FaultCEventFilter()

void WEX0_FaultCEventFilter (WEX_FILTER_t samples)

Filters event input C of the WEX0 peripheral.

Precondition:

None.

Parameters:
WEX_FILTER_t

samples - enum that represents the number of samples filtered for an event to go through, with a range between 0 and 7 samples.

Returns:

None.

WEX0_FaultCEventInputEnable()

void WEX0_FaultCEventInputEnable (bool en)

Enables event input C for the WEX0 peripheral.

Precondition:

None.

Parameters:
bool

en - boolean that has value true if enabled, false if disabled.

Returns:

None.

WEX0_FaultDetectionAction()

void WEX0_FaultDetectionAction (WEX_FDACT_t action)

Selects the action to be taken when a fault detect occurs.

Precondition:

None.

Parameters:
WEX_FDACT_t

act - enum that specifies how are the output signals driven in case of a fault.

Returns:

None.

WEX0_FaultDetectionDebugBreak()

void WEX0_FaultDetectionDebugBreak (WEX_FDDBD_t mode)

Sets fault detect on debug break detect for the WEX0 peripheral.

Precondition:

None.

Parameters:
WEX_FDDBD_t

mode - enum that specifies the fault detection on debug break detection.

Returns:

None.

WEX0_FaultDetectionRestartMode()

void WEX0_FaultDetectionRestartMode (WEX_FDMODE_t mode)

Resets the WEX0 peripheral from Fault mode.

Precondition:

None.

Parameters:
WEX_FDMODE_t

mode - enum that specifies the Restart mode from fault, it can be latched or cycle-by-cycle.

Returns:

None.

WEX0_FaultDisable()

void WEX0_FaultDisable (void )

Disables fault interrupt on the WEX0 interface.

Precondition:

None.

Parameters:
None.
Returns:

None.

WEX0_FaultDriveSet()

void WEX0_FaultDriveSet (uint8_t channels)

Selects if an output signal is in tri-state or overwritten by the custom fault value defined by the user in case a fault is detected.

Precondition:

None.

Parameters:
uint8_t

channels - represents which of the 8 waveform signals are affected by fault drive, the bits between 0 and 7 have a one-to-one relationship with the waveform signals from 0 to 7.

Returns:

None.

WEX0_FaultEnable()

void WEX0_FaultEnable (void )

Enables fault interrupt on the WEX0 interface.

Precondition:

None.

Parameters:
None.
Returns:

None.

WEX0_FaultFlagsClear()

void WEX0_FaultFlagsClear (uint8_t flags)

Clears interrupt flags on the WEX0 interface.

Precondition:

None.

Parameters:
flags

- uint8_t that represents the 4 fault flags, which are the fault interrupt flags, and the fault event input detection flags .

Returns:

None.

WEX0_FaultFlagsGet()

uint8_t WEX0_FaultFlagsGet (void )

Checks which interrupt flags are set on the WEX0 interface.

Precondition:

None.

Parameters:
None.
Returns:

uint8_t - using only the bits 0, 2, 3 and 4, the bit 0 is the fault interrupt flag, the bit 2 is event input A flag, the bit 3 is event input B flag, and the bit 4 is event input C flag.

WEX0_FAULTIsrCallbackRegister()

void WEX0_FAULTIsrCallbackRegister (WEX0_cb_t cb)

Function used to register the ISR callback function.

Precondition:

None.

Parameters:
WEX0_cb_t

cb - a function pointer.

Returns:

None.

WEX0_FaultOutputSet()

void WEX0_FaultOutputSet (uint8_t channels)

Sets the output values of the signals in case of a fault detection.

Precondition:

None.

Parameters:
uint8_t

channels - represents which value will have each of the waveform signals if the custom drive option is selected,the bits between 0 and 7 have a one-to-one relationship with the waveform signals from 0 to 7 .

Returns:

None.

WEX0_Initialize()

void WEX0_Initialize (void )

Initializes the WEX0 module.

Precondition:

None.

Parameters:
None.
Returns:

None.

WEX0_InputMatrixSet()

void WEX0_InputMatrixSet (WEX_INMX_t config)

Selects the Input Matrix mode of the WEX0 interface.

Precondition:

None.

Parameters:
WEX_INMX_t

config - enum that specifies the routing matrix for the waveform generation outputs to the port pins.

Returns:

None.

WEX0_IsFaultEnabled()

bool WEX0_IsFaultEnabled (void )

Checks if fault interrupt is enabled on the WEX0 interface.

Precondition:

None.

Parameters:
None.
Returns:

bool - true if enabled, false if disabled.

WEX0_IsPatternGenerationSet()

bool WEX0_IsPatternGenerationSet (void )

Checks the Pattern Generation mode status of the WEX0 interface.

Precondition:

None.

Parameters:
None.
Returns:

bool - true if enabled, false if disabled.

WEX0_OutputOverrideEnable()

void WEX0_OutputOverrideEnable (uint8_t channels)

Enables output signals and allows them to be overridden.

Precondition:

None.

Parameters:
uint8_t

channels - specifies which of the output signals can be overridden, can change their state, the bits between 0 and 7 have a one-to-one relationship with the waveform output signals from 0 to 7.

Returns:

None.

WEX0_PatternGenerationMode()

void WEX0_PatternGenerationMode (bool mode)

Sets the Pattern Generation mode of the WEX0 interface.

Precondition:

None.

Parameters:
bool

mode - boolean that has value true if enabled, false if disabled.

Returns:

None.

WEX0_PatternGenerationOutputBufferSet()

void WEX0_PatternGenerationOutputBufferSet (uint8_t buff)

Sets the Pattern Generation mode output values buffer on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

buff - specifies the value each waveform output signal will have, the bits between 0 and 7 have a one-to-one relationship with the waveform output signals from 0 to 7.

Returns:

None.

WEX0_PatternGenerationOutputSet()

void WEX0_PatternGenerationOutputSet (uint8_t channels)

Sets the output values of the signals in Pattern Generation mode.

Precondition:

None.

Parameters:
uint8_t

channels - specifies the value each waveform output signal will have, the bits between 0 and 7 have a one-to-one relationship with the waveform output signals from 0 to 7.

Returns:

None.

WEX0_PatternGenerationOverrideBufferSet()

void WEX0_PatternGenerationOverrideBufferSet (uint8_t buff)

Sets the Pattern Generation mode override buffer on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

buff - represents which of the 8 waveform signals can be enabled to be overriden, the bits between 0 and 7 have a one-to-one relationship with the waveform output signals from 0 to 7.

Returns:

None.

WEX0_PatternGenerationOverrideSet()

void WEX0_PatternGenerationOverrideSet (uint8_t channels)

Selects which output waveform signals can be overridden in Pattern Generation mode on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

channels - represents which of the 8 waveform signals can be enabled to be overriden, the bits between 0 and 7 have a one-to-one relationship with the waveform output signals from 0 to 7.

Returns:

None.

WEX0_SoftwareCommand()

void WEX0_SoftwareCommand (WEX_CMD_t command)

Gives software commands to the WEX0 peripheral. Commands can be: None, Update, FaultSet, FaultCLR, BlankSet, BlankCLR.

Precondition:

None.

Parameters:
WEX_CMD_t

com - enum that specify software commands used by WEX0 peripheral.

Returns:

None.

WEX0_StatusRegisterGet()

uint8_t WEX0_StatusRegisterGet (void )

Used to get the status of the WEX0's blanking/fault detection.

Precondition:

None.

Parameters:
None.
Returns:

uint8_t - the WEX0's running status.

WEX0_SwapChannelBufferSet()

void WEX0_SwapChannelBufferSet (uint8_t buff)

Sets the swap buffer of the output signal pairs on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

buff - specifies the desired channels to swap their low side and high side signals, the first 0-3 bits are used and they have a one-to-one relatioship with the 0-3 channels.

Returns:

None.

WEX0_SwapChannelSet()

void WEX0_SwapChannelSet (uint8_t channels)

Swaps the high-side and low side output signals from a complementary waveform pair of signals on the WEX0 interface.

Precondition:

None.

Parameters:
uint8_t

channels - specifies the desired channels to swap their low side and high-side signals, the first 0-3 bits are used and they have a one-to-one relatioship with the 0-3 channels.

Returns:

None.

WEX0_UpdateSourceSet()

void WEX0_UpdateSourceSet (WEX_UPDSRC_t config)

Selects the update source for the WEX0 peripheral. This can be a PWM update or a condition where no hardware update is required.

Precondition:

None.

Parameters:
WEX_UPDSRC_t

config - enum that specifies the trigger source for the update condition.

Returns:

None.

4.18.4.1.5 Variable Documentation

WEX0_FAULT_isr_cb

WEX0_cb_t WEX0_FAULT_isr_cb = NULL[static]

This is the function pointer that accesses the callback, when an interrupt occurs or a fault is detected.

Section: Included files

4.18.5 File Documentation

4.18.5.1 source/wex0.c File Reference

#include <stddef.h>
#include <avr/interrupt.h>
#include <util/atomic.h>
#include "wex0.h"

4.18.5.1.1 Functions

4.18.5.1.2 Variables

  • static WEX0_cb_t WEX0_FAULT_isr_cb = NULL

    This is the function pointer that accesses the callback, when an interrupt occurs or a fault is detected.

4.18.5.1.3 Detailed Description

WEX0 Generated Driver API SOURCE File

4.18.5.2 source/wex0.h File Reference

#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>

4.18.5.2.1 Functions

4.18.5.2.2 Macros

  • #define WEX0_NS_TO_TICKS(VALUE, F_CLOCK, WEX_PRESCALER) (uint8_t)( (float)(VALUE) / ( (1000000000.0 / (F_CLOCK) ) * (WEX_PRESCALER) ) + 0.5)

    Defines the macro associated with the conversion from ns(nanoseconds) to clock increments.  

    Used for setting the dead time or blanking time.  

    The user must specify the desired value in ns(nanoseconds), the clock speed and the prescaler.

4.18.5.2.3 Typedefs

  • typedef void(* WEX0_cb_t) (void)

    This is the function pointer that accesses the callback function, whenever an interrupt occurs or a fault is detected.

4.18.5.2.4 Detailed Description

WEX0 Generated Driver API Header File