PWM: Data Structures

PWM
  • Home
  • Data Structures
  • Data Structure Index
  • Data Fields
Data Structures
Here are the data structures with brief descriptions:
\ C PWM_HandleType Initialization parameters of the PWM App


PWM: PWM_HandleType Struct Reference

PWM
  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields
PWM_HandleType Struct Reference
Data structures

Detailed Description

Initialization parameters of the PWM App.

Definition at line 191 of file PWM.h.

#include <PWM.h>

Data Fields

XMC_GPIO_PORT_t *const | gpio_out_port
const XMC_GPIO_CONFIG_t *const | gpio_out_config
uint32_t | compare_value
uint32_t | period_value
uint32_t | duty_cycle
uint32_t | shadow_mask
const PWM_TIMER_SLICE_t | timer_type
PWM_STATUS_t state
const uint8_t | gpio_out_pin
const uint8_t | kernel_number
const uint8_t | slice_number
const bool | start_control
const bool | period_match_enable
const bool | compare_match_enable
GLOBAL_CCU4_t *const | global_ccu4_handle
GLOBAL_CCU8_t *const | global_ccu8_handle
XMC_CCU4_MODULE_t *const | ccu4_kernel_ptr
XMC_CCU8_MODULE_t *const | ccu8_kernel_ptr
XMC_CCU4_SLICE_t *const | ccu4_slice_ptr
XMC_CCU8_SLICE_t *const | ccu8_slice_ptr
const
XMC_CCU4_SLICE_COMPARE_CONFIG_t
*const 		ccu4_slice_config_ptr
const
XMC_CCU8_SLICE_COMPARE_CONFIG_t
*const 		ccu8_slice_config_ptr
const XMC_CCU4_SLICE_SR_ID_t | ccu4_slice_period_match_node
const XMC_CCU8_SLICE_SR_ID_t | ccu8_slice_period_match_node
const XMC_CCU4_SLICE_SR_ID_t | ccu4_slice_compare_match_node
const XMC_CCU8_SLICE_SR_ID_t | ccu8_slice_compare_match_node

Field Documentation

XMC_CCU4_MODULE_t* const PWM_HandleType::ccu4_kernel_ptr

Pointer to CCU4 kernel

Definition at line 206 of file PWM.h.

Referenced by PWM_SetPassiveLevel(), and PWM_SetPeriodMatchValue().

const XMC_CCU4_SLICE_SR_ID_t PWM_HandleType::ccu4_slice_compare_match_node

SR node line for period match

Definition at line 262 of file PWM.h.

const XMC_CCU4_SLICE_COMPARE_CONFIG_t* const PWM_HandleType::ccu4_slice_config_ptr

Pointer to CCU4 configuration handle

Definition at line 226 of file PWM.h.

const XMC_CCU4_SLICE_SR_ID_t PWM_HandleType::ccu4_slice_period_match_node

SR node line for period match

Definition at line 252 of file PWM.h.

XMC_CCU4_SLICE_t* const PWM_HandleType::ccu4_slice_ptr

Pointer to CCU4 slice

Definition at line 216 of file PWM.h.

Referenced by PWM_ClearEvent(), PWM_GetInterruptStatus(), PWM_GetTimerStatus(), PWM_SetPassiveLevel(), and PWM_SetPeriodMatchValue().

XMC_CCU8_MODULE_t* const PWM_HandleType::ccu8_kernel_ptr

Pointer to CCU8 kernel

Definition at line 209 of file PWM.h.

Referenced by PWM_SetPassiveLevel(), and PWM_SetPeriodMatchValue().

const XMC_CCU8_SLICE_SR_ID_t PWM_HandleType::ccu8_slice_compare_match_node

SR node line for period match

Definition at line 265 of file PWM.h.

const XMC_CCU8_SLICE_COMPARE_CONFIG_t* const PWM_HandleType::ccu8_slice_config_ptr

Pointer to CCU8 configuration handle

Definition at line 229 of file PWM.h.

const XMC_CCU8_SLICE_SR_ID_t PWM_HandleType::ccu8_slice_period_match_node

SR node line for period match

Definition at line 255 of file PWM.h.

XMC_CCU8_SLICE_t* const PWM_HandleType::ccu8_slice_ptr

Pointer to CCU8 slice

Definition at line 219 of file PWM.h.

Referenced by PWM_ClearEvent(), PWM_GetInterruptStatus(), PWM_GetTimerStatus(), PWM_SetPassiveLevel(), and PWM_SetPeriodMatchValue().

const bool PWM_HandleType::compare_match_enable

Enable/Disable Compare match interrupt

Definition at line 279 of file PWM.h.

uint32_t PWM_HandleType::compare_value

Value that is pushed into the compare register

Definition at line 237 of file PWM.h.

Referenced by PWM_SetPeriodMatchValue().

uint32_t PWM_HandleType::duty_cycle

Value of duty cycle that is scaled with a factor 100

Definition at line 241 of file PWM.h.

Referenced by PWM_SetPeriodMatchValue().

GLOBAL_CCU4_t* const PWM_HandleType::global_ccu4_handle

GLOBAL_CCU4 App handle

Definition at line 196 of file PWM.h.

GLOBAL_CCU8_t* const PWM_HandleType::global_ccu8_handle

GLOBAL_CCU8 App handle

Definition at line 199 of file PWM.h.

const XMC_GPIO_CONFIG_t* const PWM_HandleType::gpio_out_config

Holds the pin configuration for the PWM output

Definition at line 235 of file PWM.h.

const uint8_t PWM_HandleType::gpio_out_pin

Holds the pin number for the PWM output

Definition at line 269 of file PWM.h.

XMC_GPIO_PORT_t* const PWM_HandleType::gpio_out_port

Holds the port number for the PWM output

Definition at line 233 of file PWM.h.

const uint8_t PWM_HandleType::kernel_number

Indicates the CCUx kernel number

Definition at line 271 of file PWM.h.

const bool PWM_HandleType::period_match_enable

Enable/Disable Period match interrupt

Definition at line 277 of file PWM.h.

uint32_t PWM_HandleType::period_value

Value that is pushed into the period register

Definition at line 239 of file PWM.h.

Referenced by PWM_SetPeriodMatchValue().

uint32_t PWM_HandleType::shadow_mask

Holds the required shadow mask.

Definition at line 243 of file PWM.h.

Referenced by PWM_SetPassiveLevel(), and PWM_SetPeriodMatchValue().

const uint8_t PWM_HandleType::slice_number

Indicates the CCUx slice number

Definition at line 273 of file PWM.h.

const bool PWM_HandleType::start_control

Enable/disable start of PWM after initialization

Definition at line 275 of file PWM.h.

PWM_STATUS_t PWM_HandleType::state

The current state of the PWM App instance

Definition at line 247 of file PWM.h.

Referenced by PWM_SetPeriodMatchValue().

const PWM_TIMER_SLICE_t PWM_HandleType::timer_type

Type of CCU selected for the PWM generation

Definition at line 245 of file PWM.h.

Referenced by PWM_ClearEvent(), PWM_GetInterruptStatus(), PWM_GetTimerStatus(), PWM_Init(), PWM_SetDutyCycle(), PWM_SetFreq(), PWM_SetFreqAndDutyCycle(), PWM_SetPassiveLevel(), PWM_SetPeriodMatchValue(), PWM_Start(), and PWM_Stop().

The documentation for this struct was generated from the following file:
  • PWM.h


PWM: Data Structure Index

PWM
  • Data Structures
  • Data Structure Index
  • Data Fields
Data Structure Index
P
P
PWM_HandleType
P


PWM: Data Fields

PWM
  • Data Structures
  • Data Structure Index
  • Data Fields
  • All
  • Variables
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
  • ccu4_kernel_ptr : PWM_HandleType
  • ccu4_slice_compare_match_node : PWM_HandleType
  • ccu4_slice_config_ptr : PWM_HandleType
  • ccu4_slice_period_match_node : PWM_HandleType
  • ccu4_slice_ptr : PWM_HandleType
  • ccu8_kernel_ptr : PWM_HandleType
  • ccu8_slice_compare_match_node : PWM_HandleType
  • ccu8_slice_config_ptr : PWM_HandleType
  • ccu8_slice_period_match_node : PWM_HandleType
  • ccu8_slice_ptr : PWM_HandleType
  • compare_match_enable : PWM_HandleType
  • compare_value : PWM_HandleType
  • duty_cycle : PWM_HandleType
  • global_ccu4_handle : PWM_HandleType
  • global_ccu8_handle : PWM_HandleType
  • gpio_out_config : PWM_HandleType
  • gpio_out_pin : PWM_HandleType
  • gpio_out_port : PWM_HandleType
  • kernel_number : PWM_HandleType
  • period_match_enable : PWM_HandleType
  • period_value : PWM_HandleType
  • shadow_mask : PWM_HandleType
  • slice_number : PWM_HandleType
  • start_control : PWM_HandleType
  • state : PWM_HandleType
  • timer_type : PWM_HandleType


PWM: Data Fields - Variables

PWM
  • Data Structures
  • Data Structure Index
  • Data Fields
  • All
  • Variables
  • ccu4_kernel_ptr : PWM_HandleType
  • ccu4_slice_compare_match_node : PWM_HandleType
  • ccu4_slice_config_ptr : PWM_HandleType
  • ccu4_slice_period_match_node : PWM_HandleType
  • ccu4_slice_ptr : PWM_HandleType
  • ccu8_kernel_ptr : PWM_HandleType
  • ccu8_slice_compare_match_node : PWM_HandleType
  • ccu8_slice_config_ptr : PWM_HandleType
  • ccu8_slice_period_match_node : PWM_HandleType
  • ccu8_slice_ptr : PWM_HandleType
  • compare_match_enable : PWM_HandleType
  • compare_value : PWM_HandleType
  • duty_cycle : PWM_HandleType
  • global_ccu4_handle : PWM_HandleType
  • global_ccu8_handle : PWM_HandleType
  • gpio_out_config : PWM_HandleType
  • gpio_out_pin : PWM_HandleType
  • gpio_out_port : PWM_HandleType
  • kernel_number : PWM_HandleType
  • period_match_enable : PWM_HandleType
  • period_value : PWM_HandleType
  • shadow_mask : PWM_HandleType
  • slice_number : PWM_HandleType
  • start_control : PWM_HandleType
  • state : PWM_HandleType
  • timer_type : PWM_HandleType


PWM: File List

PWM
  • File List
  • Globals
File List
Here is a list of all documented files with brief descriptions:


PWM: PWM.c File Reference

PWM
  • File List
  • Globals
  • Code
Functions
PWM.c File Reference

Detailed Description

Date
2016-07-28

NOTE: This file is generated by DAVE. Any manual modification done to this file will be lost when the code is regenerated.

Definition in file PWM.c.

Functions

DAVE_APP_VERSION_t | PWM_GetAppVersion (void)
Get PWM APP version. More...
PWM_STATUS_t | PWM_Init (PWM_t *const handle_ptr)
Initializes the PWM APP. More...
void | PWM_Start (PWM_t *const handle_ptr)
Starts the PWM generation. More...
void | PWM_Stop (PWM_t *const handle_ptr)
Stops the PWM generation. More...
PWM_STATUS_t | PWM_SetDutyCycle (PWM_t *const handle_ptr, uint32_t duty_cycle)
Configure the PWM duty cycle. More...
PWM_STATUS_t | PWM_SetFreq (PWM_t *const handle_ptr, uint32_t pwm_freq_hz)
Configures the PWM Frequency. More...
PWM_STATUS_t | PWM_SetFreqAndDutyCycle (PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle)
Configures the PWM Frequency and duty cycle. More...
bool | PWM_GetTimerStatus (PWM_t *const handle_ptr)
Gets the corresponding timer status. More...
bool | PWM_GetInterruptStatus (PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
Gets the corresponding interrupt status. More...
void | PWM_ClearEvent (PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
Clears the PWM related interrupt. More...
void | PWM_SetPassiveLevel (PWM_t *const handle_ptr, PWM_OUTPUT_PASSIVE_LEVEL_t pwm_output_passive_level)
Configure the passive level of the PWM output waveform. More...
PWM_STATUS_t | PWM_SetPeriodMatchValue (PWM_t *const handle_ptr, uint32_t period_match_value)
Loads the required period match value. More...

Function Documentation

void PWM_ClearEvent | ( | PWM_t *const | handle_ptr,
 |  | PWM_INTERRUPT_t | pwm_interrupt
 | ) |  |

Clears the PWM related interrupt.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
pwm_interrupt | Interrupt to acknowledge.
Returns
void
Description:
Clears the CCUx related interrupt. When an interrupt occurs it must be acknowledged by clearing the respective flag in the hardware. Clears the interrupt type PWM_INTERRUPT_t.
// Drag 2 INTERRUPT APPs into the project. In the PWM APPs UI editor enable compare match event and period
// match event. Goto the Signal connectivity window and connect the event_compare_match and event_period_match to
// the 2 different INTERRUPT APPs. Give the handler for the compare match interrupt as PWM_compare_match_interrupt
// and the handler for the period match interrupt as PWM_period_match_interrupt
#include "DAVE.h"
uint32_t period_count;
void PWM_period_match_interrupt(void)
{
static uint32_t frequency = 1000; //start frequency 1Khz
PWM_ClearEvent(&PWM_0, PWM_INTERRUPT_PERIODMATCH);
period_count++;
if (period_count == 35000) // wait to get 40K pwm cycles then increment the frequency by 2kHz
{
frequency += 2000;
PWM_SetFreq(&PWM_0, frequency);
period_count = 0;
if (frequency > 30000000)
{
frequency = 1000;
}
}
}
void PWM_compare_match_interrupt(void)
{
PWM_ClearEvent(&PWM_0, PWM_INTERRUPT_COMPAREMATCH);
}
int main(void)
{
DAVE_Init();
PWM_Start(&PWM_0);
while(1);
return 0;
}

Definition at line 943 of file PWM.c.

References PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_slice_ptr, and PWM_HandleType::timer_type.

bool PWM_GetInterruptStatus | ( | PWM_t *const | handle_ptr,
 |  | PWM_INTERRUPT_t | pwm_interrupt
 | ) |  |

Gets the corresponding interrupt status.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
pwm_interrupt | Interrupt to get status.
Returns
bool returns true if the pwm_interrupt has occured else returns false.
Description:
Returns the status of the corresponding interrupt. Reads the appropriate flag and would return true if the event was asserted.
// Drag 1 INTERRUPT APP into the project. In the PWM APPs UI editor enable compare match event and period
// match event. Goto the Signal connectivity window and connect the event_compare_match and event_period_match to
// the same INTERRUPT APP and give the handler as PWM_compare_period_match_interrupt.
#include "DAVE.h"
uint32_t period_count;
void PWM_compare_period_match_interrupt(void)
{
if (PWM_GetInterruptStatus(&PWM_0, PWM_INTERRUPT_PERIODMATCH))
{
PWM_Stop(&PWM_0); // A single shot PWM generated
}
PWM_ClearEvent(&PWM_0, PWM_INTERRUPT_COMPAREMATCH);
}
int main(void)
{
DAVE_Init();
PWM_Start(&PWM_0);
while(1);
return 0;
}

Definition at line 917 of file PWM.c.

References PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_slice_ptr, and PWM_HandleType::timer_type.

bool PWM_GetTimerStatus ( PWM_t *const handle_ptr )

Gets the corresponding timer status.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
bool
returns true if timer is running , false if the timer is idle.
Description:
Returns the state of the timer. Would return a false if the timer is not running. A call to this API results in invalid outputs if invoked before PWM_Init().
#include "DAVE.h"
int main(void)
{
DAVE_Init();
if (PWM_GetTimerStatus(&PWM_0))
{
PWM_Stop(&PWM_0);
}
while(1);
return 0;
}

Definition at line 891 of file PWM.c.

References PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_slice_ptr, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_Init ( PWM_t *const handle_ptr )

Initializes the PWM APP.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
PWM_STATUS_t status of the initialization.
Description:
Initializes the PWM APP. This initializes the CCUx slice to compare mode of operation. Configures required events, GPIO pin as output. It will configure CCU4 or CCU8 slice registers with the selected PWM parameters. If PWM generation is set to start after initialization then after the CCUx related initialization is completed the PWM output will start.
#include "DAVE.h"
int main(void)
{
DAVE_Init(); //PWM_Init() is called by DAVE_Init().
while(1);
return 0;
}

Definition at line 747 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetDutyCycle | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | duty_cycle
 | ) |  |

Configure the PWM duty cycle.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
duty_cycle Duty cycle in percentage.
The values are scaled by a factor of 100.
Range: [0(d) to 10000(d)] Where 1(d) represents 0.01% duty cycle
10000(d) represents 100% duty cycle
Returns
Returns PWM_STATUS_FAILURE if the duty_cycle exceeds the valid range.
Description:
Configure the PWM duty cycle by changing the compare match values. The API would configure the duty cycle for the given frequency. The duty_cycle is a scaled parameter where a single value change would result in a 0.01% change.
Note:
This is a fixed point implementation. It is expected that there are resolution losses due to scaling in the API. At higher frequencies it may not be possible to achieve the required duty cycle due to the hardware limitation.
#include "DAVE.h"
int main(void)
{
uint32_t Counter;
DAVE_Init();
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to 60.00%
if (PWM_SetDutyCycle(&PWM_0, 6000))
{
while(1);
}
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to 54.26%
if (PWM_SetDutyCycle(&PWM_0, 5426))
{
while(1);
}
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to an invalid duty 100.26%
if (PWM_SetDutyCycle(&PWM_0, 10026))
{
while(1);
}
while(1);
return 0;
}

Definition at line 816 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetFreq | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | pwm_freq_hz
 | ) |  |

Configures the PWM Frequency.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
PwmFreqHz Frequency value in Hz.
Range: [1(d) to 60000000(d)]
Returns
PWM_STATUS_t Would return PWM_STATUS_FAILURE if the PwmFreqHz exceeded the maximum frequency achievable.
Description:
Configures the frequency of the PWM signal. The PWM duty cycle remains unchanged. Calculates the least possible resolution(Prescaler) of the CCUx Timer. Using this Prescaler it would calculate the value for the period register and the compare register. Adjusts the compare match value according to the frequency and the existing duty cycle.
#include "DAVE.h"
int main(void)
{
PWM_STATUS_t pwm_setfreq_status;
DAVE_Init();
// Change duty cycle value to 20%.
PWM_SetDutyCycle(&PWM_0, 2000);
// Change PWM frequency to 100kHz
pwm_setfreq_status = PWM_SetFreq(&PWM_0,100000);
if (PWM_STATUS_FAILURE == pwm_setfreq_status)
{
// frequency couldn't be set
while(1);
}
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to 60%.
PWM_SetDutyCycle(&PWM_0, 6000);
while(1);
return 0;
}

Definition at line 841 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetFreqAndDutyCycle | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | pwm_freq_hz,
 |  | uint32_t | duty_cycle
 | ) |  |

Configures the PWM Frequency and duty cycle.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
PwmFreqHz Frequency value in Hz.
Range: [1(d) to 60000000(d)]
duty_cycle Duty cycle in percentage.
The values are scaled by a factor of 100.
Range: [0(d) to 10000(d)] Where 1(d) represents 0.01% duty cycle
10000(d) represents 100% duty cycle
Returns
Return PWM_STATUS_FAILURE if the PwmFreqHz exceeded the maximum frequency achievable.
Description:
Configures the frequency and duty cycle together. Calculates the least possible resolution(Prescaler) of the CCUx Timer. Using this Prescaler it would calculate the value for the period register. Using the duty_cycle the compare register values would be calculated.
Note:
This is a fixed point implementation for duty cycle. It is expected that there are resolution losses due to scaling of the duty cycle in the API. At higher frequencies it may not be possible to achieve the required duty cycle due to the hardware limitation. If the input frequency to the API is very high (> 30MHz) due to integer divisions, the desired frequency might not be set.
#include "DAVE.h"
int main(void)
{
PWM_STATUS_t pwm_setfreq_status;
DAVE_Init();
// Change duty cycle value to 90.90%.
PWM_SetDutyCycle(&PWM_0, 9090);
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change PWM frequency to 100kHz and duty to 20%
pwm_setfreq_status = PWM_SetFreqAndDutyCycle(&PWM_0,100000,2000);
if (PWM_STATUS_FAILURE == pwm_setfreq_status)
{
// frequency couldn't be set
while(1);
}
while(1);
return 0;
}

Definition at line 866 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

void PWM_SetPassiveLevel | ( | PWM_t *const | handle_ptr,
 |  | PWM_OUTPUT_PASSIVE_LEVEL_t | pwm_output_passive_level
 | ) |  |

Configure the passive level of the PWM output waveform.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
pwm_output_passive_level | Passive level LOW or HIGH.
Returns
void
Description:
Configure the passive level for the PWM signal. If ::PWM_OutputPassiveLevelType::PWM_OUTPUT_PASSIVE_LEVEL_HIGH is selected the output of the PWM will be high before the compare match occurs after that it would be set to low. If ::PWM_OutputPassiveLevelType::PWM_OUTPUT_PASSIVE_LEVEL_LOW is selected the output of the PWM will be low before the compare match occurs after that it would be set to high.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPassiveLevel(&PWM_0, PWM_OUTPUT_PASSIVE_LEVEL_HIGH);
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPassiveLevel(&PWM_0, PWM_OUTPUT_PASSIVE_LEVEL_LOW);
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
while(1);
return 0;
}

Definition at line 964 of file PWM.c.

References PWM_HandleType::ccu4_kernel_ptr, PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_kernel_ptr, PWM_HandleType::ccu8_slice_ptr, PWM_HandleType::shadow_mask, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetPeriodMatchValue | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | period_match_value
 | ) |  |

Loads the required period match value.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
period_match_value | value which needs to be loaded into the period register. Range: [0x0 to 0xFFFF]
Returns
void
Description:
Configures or loads the required period value into the period register. This API would also calculate the compare register value (w.r.t period_match_value ) to maintain the duty cycle.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
PWM_SetFreq(&PWM_0, 1U);// Set the required frequency as 1Hz
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPeriodMatchValue(&PWM_0, PWM_0.period_value / 2); // 2Hz
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPeriodMatchValue(&PWM_0, PWM_0.period_value * 2); // 1Hz
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
while(1);
return 0;
}

Definition at line 995 of file PWM.c.

References PWM_HandleType::ccu4_kernel_ptr, PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_kernel_ptr, PWM_HandleType::ccu8_slice_ptr, PWM_HandleType::compare_value, PWM_HandleType::duty_cycle, PWM_HandleType::period_value, PWM_STATUS_FAILURE, PWM_STATUS_SUCCESS, PWM_HandleType::shadow_mask, PWM_HandleType::state, and PWM_HandleType::timer_type.

void PWM_Start ( PWM_t *const handle_ptr )

Starts the PWM generation.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
void
Description:
Start the selected PWM generation. It is needed to be called if "Start after initialization" is unchecked in the UI. Enables the clock for the CCUx slice and also starts the timer operation. Invoke this API only after initialization and when the timer is not running. If invoked outside these conditions, the API will have no effect.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
//This needs to be called if "Start after initialization" is unchecked
if (!PWM_GetTimerStatus(&PWM_0))
{
PWM_Start(&PWM_0);
}
while(1);
return 0;
}

Definition at line 773 of file PWM.c.

References PWM_HandleType::timer_type.

void PWM_Stop ( PWM_t *const handle_ptr )

Stops the PWM generation.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
void
Description:
Stop the selected PWM generation. Disables the clock for the CCUx slice and also stops the timer operation. Invoke this API only after initialization and when the timer is running. If invoked outside these conditions, the API will have no effect.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
if (PWM_GetTimerStatus(&PWM_0))
{
PWM_Stop(&PWM_0);
}
while(1);
return 0;
}

Definition at line 794 of file PWM.c.

References PWM_HandleType::timer_type.

Go to the source code of this file.


PWM: PWM.h File Reference

PWM
  • File List
  • Globals
  • Code
Data Structures
PWM.h File Reference

Detailed Description

Date
2021-01-08

NOTE: This file is generated by DAVE. Any manual modification done to this file will be lost when the code is regenerated.

Definition in file PWM.h.

Data Structures

struct PWM_HandleType
Initialization parameters of the PWM App. More...

Typedefs

typedef struct PWM_HandleType PWM_t
Initialization parameters of the PWM App.

Functions

DAVE_APP_VERSION_t | PWM_GetAppVersion (void)
Get PWM APP version. More...
PWM_STATUS_t | PWM_Init (PWM_t *const handle_ptr)
Initializes the PWM APP. More...
void | PWM_Start (PWM_t *const handle_ptr)
Starts the PWM generation. More...
void | PWM_Stop (PWM_t *const handle_ptr)
Stops the PWM generation. More...
PWM_STATUS_t | PWM_SetFreq (PWM_t *const handle_ptr, uint32_t pwm_freq_hz)
Configures the PWM Frequency. More...
PWM_STATUS_t | PWM_SetFreqAndDutyCycle (PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle)
Configures the PWM Frequency and duty cycle. More...
void | PWM_ClearEvent (PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
Clears the PWM related interrupt. More...
bool | PWM_GetInterruptStatus (PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
Gets the corresponding interrupt status. More...
bool | PWM_GetTimerStatus (PWM_t *const handle_ptr)
Gets the corresponding timer status. More...
PWM_STATUS_t | PWM_SetDutyCycle (PWM_t *const handle_ptr, uint32_t duty_cycle)
Configure the PWM duty cycle. More...
void | PWM_SetPassiveLevel (PWM_t *const handle_ptr, PWM_OUTPUT_PASSIVE_LEVEL_t pwm_output_passive_level)
Configure the passive level of the PWM output waveform. More...
PWM_STATUS_t | PWM_SetPeriodMatchValue (PWM_t *const handle_ptr, uint32_t period_match_value)
Loads the required period match value. More...
enum | PWM_TIMER_SLICE
The type identifies the CCU4 or CCU8 timer selected.
enum | PWM_TIMER_STATUS
The type identifies the timer status.
enum | PWM_INTERRUPT { PWM_INTERRUPT_PERIODMATCH = 0U, PWM_INTERRUPT_COMPAREMATCH = 2U }
The type identifies the timer interrupts. More...
enum | PWM_OUTPUT_PASSIVE_LEVEL { PWM_OUTPUT_PASSIVE_LEVEL_LOW = 0, PWM_OUTPUT_PASSIVE_LEVEL_HIGH }
The type identifies the timer interrupts. More...
enum PWM_STATUS {
PWM_STATUS_SUCCESS = 0, PWM_STATUS_FAILURE, PWM_STATUS_UNINITIALIZED, PWM_STATUS_RUNNING,
PWM_STATUS_STOPPED
}
The type identifies App state. More...
enum | PWM_ERROR_CODES { PWM_OPER_NOT_ALLOWED_ERROR = 1, PWM_INVALID_PARAM_ERROR }
The type identifies the App Error Codes. More...
typedef enum PWM_TIMER_SLICE | PWM_TIMER_SLICE_t
The type identifies the CCU4 or CCU8 timer selected.
typedef enum PWM_TIMER_STATUS | PWM_TIMER_STATUS_t
The type identifies the timer status.
typedef enum PWM_INTERRUPT | PWM_INTERRUPT_t
The type identifies the timer interrupts.
typedef enum
PWM_OUTPUT_PASSIVE_LEVEL 		PWM_OUTPUT_PASSIVE_LEVEL_t
The type identifies the timer interrupts.
typedef enum PWM_STATUS | PWM_STATUS_t
The type identifies App state.
typedef enum PWM_ERROR_CODES | PWM_ERROR_CODES_t
The type identifies the App Error Codes.

Go to the source code of this file.


PWM: Globals

PWM
  • File List
  • Globals
  • All
  • Functions
  • Typedefs
  • Enumerations
  • Enumerator
  • p
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- p -

  • PWM_ClearEvent() : PWM.c , PWM.h
  • PWM_ERROR_CODES : PWM.h
  • PWM_ERROR_CODES_t : PWM.h
  • PWM_GetAppVersion() : PWM.c , PWM.h
  • PWM_GetInterruptStatus() : PWM.h , PWM.c
  • PWM_GetTimerStatus() : PWM.c , PWM.h
  • PWM_Init() : PWM.c , PWM.h
  • PWM_INTERRUPT : PWM.h
  • PWM_INTERRUPT_COMPAREMATCH : PWM.h
  • PWM_INTERRUPT_PERIODMATCH : PWM.h
  • PWM_INTERRUPT_t : PWM.h
  • PWM_INVALID_PARAM_ERROR : PWM.h
  • PWM_OPER_NOT_ALLOWED_ERROR : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL_HIGH : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL_LOW : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL_t : PWM.h
  • PWM_SetDutyCycle() : PWM.c , PWM.h
  • PWM_SetFreq() : PWM.c , PWM.h
  • PWM_SetFreqAndDutyCycle() : PWM.c , PWM.h
  • PWM_SetPassiveLevel() : PWM.c , PWM.h
  • PWM_SetPeriodMatchValue() : PWM.h , PWM.c
  • PWM_Start() : PWM.c , PWM.h
  • PWM_STATUS : PWM.h
  • PWM_STATUS_FAILURE : PWM.h
  • PWM_STATUS_RUNNING : PWM.h
  • PWM_STATUS_STOPPED : PWM.h
  • PWM_STATUS_SUCCESS : PWM.h
  • PWM_STATUS_t : PWM.h
  • PWM_STATUS_UNINITIALIZED : PWM.h
  • PWM_Stop() : PWM.h , PWM.c
  • PWM_t : PWM.h
  • PWM_TIMER_SLICE : PWM.h
  • PWM_TIMER_SLICE_t : PWM.h
  • PWM_TIMER_STATUS : PWM.h
  • PWM_TIMER_STATUS_t : PWM.h


PWM: Globals

PWM
  • File List
  • Globals
  • All
  • Functions
  • Typedefs
  • Enumerations
  • Enumerator
  • PWM_ClearEvent() : PWM.c , PWM.h
  • PWM_GetAppVersion() : PWM.h , PWM.c
  • PWM_GetInterruptStatus() : PWM.c , PWM.h
  • PWM_GetTimerStatus() : PWM.h , PWM.c
  • PWM_Init() : PWM.c , PWM.h
  • PWM_SetDutyCycle() : PWM.c , PWM.h
  • PWM_SetFreq() : PWM.c , PWM.h
  • PWM_SetFreqAndDutyCycle() : PWM.c , PWM.h
  • PWM_SetPassiveLevel() : PWM.c , PWM.h
  • PWM_SetPeriodMatchValue() : PWM.c , PWM.h
  • PWM_Start() : PWM.c , PWM.h
  • PWM_Stop() : PWM.h , PWM.c


PWM: Globals

PWM
  • File List
  • Globals
  • All
  • Functions
  • Typedefs
  • Enumerations
  • Enumerator
  • PWM_ERROR_CODES_t : PWM.h
  • PWM_INTERRUPT_t : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL_t : PWM.h
  • PWM_STATUS_t : PWM.h
  • PWM_t : PWM.h
  • PWM_TIMER_SLICE_t : PWM.h
  • PWM_TIMER_STATUS_t : PWM.h


PWM: Globals

PWM
  • File List
  • Globals
  • All
  • Functions
  • Typedefs
  • Enumerations
  • Enumerator
  • PWM_ERROR_CODES : PWM.h
  • PWM_INTERRUPT : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL : PWM.h
  • PWM_STATUS : PWM.h
  • PWM_TIMER_SLICE : PWM.h
  • PWM_TIMER_STATUS : PWM.h


PWM: Globals

PWM
  • File List
  • Globals
  • All
  • Functions
  • Typedefs
  • Enumerations
  • Enumerator
  • PWM_INTERRUPT_COMPAREMATCH : PWM.h
  • PWM_INTERRUPT_PERIODMATCH : PWM.h
  • PWM_INVALID_PARAM_ERROR : PWM.h
  • PWM_OPER_NOT_ALLOWED_ERROR : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL_HIGH : PWM.h
  • PWM_OUTPUT_PASSIVE_LEVEL_LOW : PWM.h
  • PWM_STATUS_FAILURE : PWM.h
  • PWM_STATUS_RUNNING : PWM.h
  • PWM_STATUS_STOPPED : PWM.h
  • PWM_STATUS_SUCCESS : PWM.h
  • PWM_STATUS_UNINITIALIZED : PWM.h


PWM: PWM.c Source File

PWM
  • File List
  • Globals
  • Code
PWM.c
Go to the documentation of this file.
1
76 /***********************************************************************************************************************
77 * HEADER FILES
78 **********************************************************************************************************************/
79 #include "pwm.h"
80
81 /**********************************************************************************************************************
82 * MACROS
83 **********************************************************************************************************************/
84 #define PWM_MAX_DUTY_CYCLE ((uint32_t)10000)
85 #define PWM_DUTY_CYCLE_SCALE ((uint32_t)100)
86 #define PWM_MAX_PRESCALER ((uint32_t)15)
87 #define PWM_MAX_PERIOD_VALUE ((uint32_t) 65535)
88
89 /***********************************************************************************************************************
90 * LOCAL ROUTINES
91 **********************************************************************************************************************/
92 #ifdef PWM_SLICE_USED_CCU4
93 /*Initialize the App and XMC_CCU4 slice. */
94 PWM_STATUS_t PWM_lCCU4_Init(PWM_t *const handle_ptr);
95
96 /*Initialize interrupts*/
97 void PWM_lCCU4_ConfigInterrupts(PWM_t *const handle_ptr);
98
99 /*Starts the CCU4 slice. */
100 void PWM_lCCU4_Start(PWM_t *const handle_ptr);
101
102 /*Stops the CCU4 slice. */
103 void PWM_lCCU4_Stop(PWM_t *const handle_ptr);
104
105 /*Sets the duty cycle for CCU4 slice. */
106 PWM_STATUS_t PWM_lCCU4_SetDutyCycle(PWM_t *const handle_ptr, uint32_t duty_cycle);
107
108 /*Sets the frequency for CCU4 slice. */
109 PWM_STATUS_t PWM_lCCU4_SetFreq(PWM_t *const handle_ptr, uint32_t pwm_freq_hz);
110
111 /*Sets the frequency and duty cycle for CCU4 slice. */
112 PWM_STATUS_t PWM_lCCU4_SetFreqAndDutyCycle(PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle);
113 #endif
114
115 #ifdef PWM_SLICE_USED_CCU8
116 /*Initialize the App and XMC_CCU8 slice. */
117 PWM_STATUS_t PWM_lCCU8_Init(PWM_t *const handle_ptr);
118
119 /*Initialize interrupts*/
120 void PWM_lCCU8_ConfigInterrupts(PWM_t *const handle_ptr);
121
122 /*Starts the CCU8 slice. */
123 void PWM_lCCU8_Start(PWM_t *const handle_ptr);
124
125 /*Stops the CCU8 slice. */
126 void PWM_lCCU8_Stop(PWM_t *const handle_ptr);
127
128 /*Sets the duty cycle for CCU8 slice. */
129 PWM_STATUS_t PWM_lCCU8_SetDutyCycle(PWM_t *const handle_ptr, uint32_t duty_cycle);
130
131 /*Sets the frequency for CCU8 slice. */
132 PWM_STATUS_t PWM_lCCU8_SetFreq(PWM_t *const handle_ptr, uint32_t pwm_freq_hz);
133
134 /*Sets the frequency and duty cycle for CCU8 slice. */
135 PWM_STATUS_t PWM_lCCU8_SetFreqAndDutyCycle(PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle);
136 #endif
137
138 #ifdef PWM_SLICE_USED_CCU4
139
140 /*Initialize the APP and CCU4 slice. */
141 PWM_STATUS_t PWM_lCCU4_Init(PWM_t *const handle_ptr)
142 {
143 PWM_STATUS_t status = PWM_STATUS_FAILURE;
144
145 XMC_ASSERT("PWM_lCCU4_Init:Invalid handle_ptr" , (handle_ptr != NULL))
146
147 if (PWM_STATUS_UNINITIALIZED == handle_ptr->state)
148 {
149 /* Initialize consumed Apps */
150 status = (PWM_STATUS_t)GLOBAL_CCU4_Init(handle_ptr->global_ccu4_handle);
151
152 /*Initialize CCU4 slice */
153 if (PWM_STATUS_SUCCESS == status)/*check GLOBAL_CCU4_Init status*/
154 {
155 XMC_DEBUG("PWM_lCCU4_Init:Initilizing Slice")
156 XMC_CCU4_SLICE_CompareInit(handle_ptr->ccu4_slice_ptr, handle_ptr->ccu4_slice_config_ptr);
157
158 /* Set the period and compare register values */
159 XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_ptr->ccu4_slice_ptr,
160 (uint16_t)handle_ptr->period_value);
161
162 XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr,
163 (uint16_t)handle_ptr->compare_value);
164
165 XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_kernel_ptr, handle_ptr->shadow_mask);
166
167 /* Initialize interrupts */
168 PWM_lCCU4_ConfigInterrupts(handle_ptr);
169
170 XMC_GPIO_Init(handle_ptr->gpio_out_port,handle_ptr->gpio_out_pin,
171 handle_ptr->gpio_out_config);
172
173 handle_ptr->state = PWM_STATUS_SUCCESS;
174
175 /* Start the PWM generation if start at initialization is enabled */
176 if ((bool) true == handle_ptr->start_control)
177 {
178 PWM_Start(handle_ptr);
179 }
180 status = PWM_STATUS_SUCCESS;
181 }
182 else
183 {
184 handle_ptr->state = PWM_STATUS_UNINITIALIZED;
185 }
186
187 }
188 return (status);
189 } /* end of PWM_lCCU4_Init() api */
190
191 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
192 /* Initialize interrupts */
193 void PWM_lCCU4_ConfigInterrupts(PWM_t *const handle_ptr)
194 {
195 if ((bool) true == handle_ptr->period_match_enable)
196 {
197 XMC_DEBUG("PWM_lCCU4_ConfigInterrupts:period match enable")
198 XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
199
200 /* Bind event to Service Request Node to period match event*/
201 XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH,
202 handle_ptr->ccu4_slice_period_match_node);
203 }
204
205 if ((bool) true == handle_ptr->compare_match_enable)
206 {
207 XMC_DEBUG("PWM_lCCU4_ConfigInterrupts:compare match enable")
208 XMC_CCU4_SLICE_EnableEvent(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP);
209
210 /* Bind event to Service Request Node to compare match event */
211 XMC_CCU4_SLICE_SetInterruptNode(handle_ptr->ccu4_slice_ptr, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP,
212 handle_ptr->ccu4_slice_compare_match_node);
213 }
214 }
215
216 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
217 /*Starts the CCU4 slice. */
218 void PWM_lCCU4_Start(PWM_t *const handle_ptr)
219 {
220 if ((PWM_STATUS_SUCCESS == handle_ptr->state) || (PWM_STATUS_STOPPED == handle_ptr->state))
221 {
222 /* Clears the IDLE mode for the slice */
223 XMC_CCU4_EnableClock(handle_ptr->ccu4_kernel_ptr,handle_ptr->slice_number);
224 XMC_CCU4_SLICE_StartTimer(handle_ptr->ccu4_slice_ptr);
225
226 handle_ptr->state = PWM_STATUS_RUNNING;
227 XMC_DEBUG("PWM_lCCU4_Start:start PWM")
228 }
229 } /* end of PWM_lCCU4_Start() api */
230
231 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
232 /*Stops the CCU4 slice. */
233 void PWM_lCCU4_Stop(PWM_t *const handle_ptr)
234 {
235 if (PWM_STATUS_UNINITIALIZED != handle_ptr->state)
236 {
237 XMC_CCU4_SLICE_StopTimer(handle_ptr->ccu4_slice_ptr);
238 XMC_CCU4_SLICE_ClearTimer(handle_ptr->ccu4_slice_ptr);
239 XMC_CCU4_DisableClock(handle_ptr->ccu4_kernel_ptr,handle_ptr->slice_number);
240
241 handle_ptr->state = PWM_STATUS_STOPPED;
242 XMC_DEBUG("PWM_lCCU4_Stop:stop PWM")
243 }
244 } /* end of PWM_lCCU4_Stop() api */
245
246 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
247 /*Sets the duty cycle for CCU4 slice. */
248 PWM_STATUS_t PWM_lCCU4_SetDutyCycle(PWM_t *const handle_ptr, uint32_t duty_cycle)
249 {
250 uint32_t period;
251 uint32_t compare;
252 PWM_STATUS_t status;
253
254 XMC_ASSERT("PWM_lCCU4_SetDutyCycle:Invalid duty_cycle " , ((duty_cycle >= 0) && (duty_cycle <= PWM_MAX_DUTY_CYCLE)))
255
256 status = PWM_STATUS_FAILURE;
257 if (PWM_STATUS_UNINITIALIZED != handle_ptr->state)
258 {
259 /* Duty cycle needs between 0 and 10000 */
260 if (duty_cycle <= PWM_MAX_DUTY_CYCLE)
261 {
262 /* period = (PR + 1) */
263 period = (uint32_t)handle_ptr->period_value + 1U;
264
265 /* Duty Cycle(symmetric) = (PR-CR1)+1 / period */
266 compare = ((period * (PWM_MAX_DUTY_CYCLE - duty_cycle)) / ((uint32_t) 100 * PWM_DUTY_CYCLE_SCALE));
267
268 handle_ptr->compare_value = compare;
269 handle_ptr->duty_cycle = duty_cycle;
270
271 XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)compare);
272 XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_kernel_ptr, handle_ptr->shadow_mask);
273 status = PWM_STATUS_SUCCESS;
274 }
275 }
276
277 XMC_DEBUG("PWM_lCCU4_SetDutyCycle:dutycycle set")
278 return (status);
279 } /* end of PWM_lCCU4_SetDutyCycle() api */
280
281 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
282 /*Sets the frequency for CCU4 slice. */
283 PWM_STATUS_t PWM_lCCU4_SetFreq(PWM_t *const handle_ptr, uint32_t pwm_freq_hz)
284 {
285 PWM_STATUS_t status;
286 uint32_t module_freq;
287 uint8_t prescaler;
288 uint32_t period_value;
289 uint32_t compare;
290
291 XMC_ASSERT("PWM_lCCU4_SetFreq:Invalid pwm_freq_hz " , (pwm_freq_hz != 0U))
292
293 status = handle_ptr->state;
294 prescaler = 0U;
295 period_value = 0U;
296
297 /* Can't set the frequency when the PWM is not yet initialized or when required frequency is 0*/
298 if ((status != PWM_STATUS_UNINITIALIZED) && ((uint32_t)0 != pwm_freq_hz))
299 {
300 status = PWM_STATUS_SUCCESS;
301 /*Get the Module frequency*/
302 module_freq = handle_ptr->global_ccu4_handle->module_frequency;
303
304 /*Calculate the prescaler and the period register values.*/
305 while (prescaler <= PWM_MAX_PRESCALER)
306 {
307 period_value = (uint32_t)((uint32_t)module_freq / (uint32_t)pwm_freq_hz) >> (uint32_t)prescaler;
308 /*If the prescaler selected is not big enough goto the next prescaler value else come out.*/
309 if (period_value <= PWM_MAX_TIMER_COUNT )
310 {
311 break;
312 }
313 prescaler++;
314 }
315
316 /*Can't set the frequency if the required value is too small or when the required frequency is too large.*/
317 if ((prescaler > PWM_MAX_PRESCALER) || ((uint32_t)0 == period_value))
318 {
319 XMC_DEBUG("PWM_lCCU4_SetFreq:Frequency could not be set")
320 status = PWM_STATUS_FAILURE;
321 }
322 else
323 {
324 /*Calculate the new compare values using new period values */
325 compare = (period_value * (PWM_MAX_DUTY_CYCLE - handle_ptr->duty_cycle))
326 / ((uint32_t) 100 * PWM_DUTY_CYCLE_SCALE);
327
328 XMC_CCU4_SLICE_SetPrescaler(handle_ptr->ccu4_slice_ptr, prescaler);
329
330 /* The period register is always one count less than calculated.*/
331 period_value = period_value - (uint32_t)1;
332 XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)(period_value));
333
334 XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)compare);
335
336 XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_kernel_ptr, handle_ptr->shadow_mask);
337
338 handle_ptr->compare_value = compare;
339 handle_ptr->period_value = period_value;
340 XMC_DEBUG("PWM_lCCU4_SetFreq:frequency set")
341 }
342 }
343 else
344 {
345 status = PWM_STATUS_FAILURE;
346 XMC_DEBUG("PWM_lCCU4_SetFreq:Frequency could not be set")
347 }
348
349
350 return status;
351 } /* end of PWM_lCCU4_SetFreq() api */
352
353 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
354 /*Sets the frequency and duty cycle for CCU4 slice. */
355 PWM_STATUS_t PWM_lCCU4_SetFreqAndDutyCycle(PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle)
356 {
357 PWM_STATUS_t status;
358 uint32_t module_freq;
359 uint8_t prescaler;
360 uint32_t period_value;
361 uint32_t compare;
362
363 XMC_ASSERT("PWM_lCCU4_SetFreqAndDutyCycle:Invalid pwm_freq_hz " , (pwm_freq_hz != 0U))
364 XMC_ASSERT("PWM_lCCU4_SetFreqAndDutyCycle:Invalid duty_cycle",((duty_cycle >= 0) &&
365 (duty_cycle <= PWM_MAX_DUTY_CYCLE)))
366
367 status = handle_ptr->state;
368 prescaler = 0U;
369 period_value = 0U;
370
371 /* Can't set the frequency when the PWM is not yet initialized or when required frequency is 0*/
372 if ((status != PWM_STATUS_UNINITIALIZED) && ((uint32_t)0 != pwm_freq_hz))
373 {
374 status = PWM_STATUS_SUCCESS;
375 /*Get the Module frequency*/
376 module_freq = handle_ptr->global_ccu4_handle->module_frequency;
377
378 /*Calculate the prescaler and the period register values.*/
379 while (prescaler <= PWM_MAX_PRESCALER)
380 {
381 period_value = (uint32_t)((uint32_t)module_freq / (uint32_t)pwm_freq_hz) >> (uint32_t)prescaler;
382 /*If the prescaler selected is not big enough goto the next prescaler value else come out.*/
383 if (period_value <= PWM_MAX_TIMER_COUNT )
384 {
385 break;
386 }
387
388 prescaler++;
389 }
390
391 /*Can't set the frequency if the required value is too small or when the required frequency is too large.*/
392 if ((prescaler > PWM_MAX_PRESCALER) || (duty_cycle > PWM_MAX_DUTY_CYCLE) || ((uint32_t)0 == period_value))
393 {
394 XMC_DEBUG("PWM_lCCU4_SetFreqAndDutyCycle:Frequency or duty cycle could not be set")
395 status = PWM_STATUS_FAILURE;
396 }
397 else
398 {
399 /*Calculate the new compare values using new period values */
400 compare = (period_value * ((uint32_t)PWM_MAX_DUTY_CYCLE - duty_cycle)) / ((uint32_t) 100 * PWM_DUTY_CYCLE_SCALE);
401
402 XMC_CCU4_SLICE_SetPrescaler(handle_ptr->ccu4_slice_ptr, prescaler);
403
404 /* The period register is always one count less than calculated.*/
405 period_value = period_value - (uint32_t)1;
406 XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)(period_value));
407
408 XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)compare);
409
410 XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_kernel_ptr, handle_ptr->shadow_mask);
411
412 handle_ptr->compare_value = compare;
413 handle_ptr->period_value = period_value;
414 handle_ptr->duty_cycle = duty_cycle;
415 XMC_DEBUG("PWM_lCCU4_SetFreqAndDutyCycle:frequency and duty cycle set")
416 }
417 }
418 else
419 {
420 status = PWM_STATUS_FAILURE;
421 XMC_DEBUG("PWM_lCCU4_SetFreqAndDutyCycle:Frequency or duty cycle could not be set")
422 }
423
424
425 return status;
426 } /* end of PWM_lCCU4_SetFreqAndDutyCycle() api */
427
428 #endif /* end of CCU4 function definitions */
429
430 #ifdef PWM_SLICE_USED_CCU8
431
432 /*Initialize the APP and CCU8 slice. */
433 PWM_STATUS_t PWM_lCCU8_Init(PWM_t *const handle_ptr)
434 {
435 PWM_STATUS_t status = PWM_STATUS_FAILURE;
436
437 if (PWM_STATUS_UNINITIALIZED == handle_ptr->state)
438 {
439 /* Initialize consumed Apps */
440 status = (PWM_STATUS_t)GLOBAL_CCU8_Init(handle_ptr->global_ccu8_handle);
441
442 /*Initialize CCU8 slice */
443 if (PWM_STATUS_SUCCESS == status)
444 {
445 XMC_DEBUG("PWM_lCCU8_Init:Initilizing Slice")
446 XMC_CCU8_SLICE_CompareInit(handle_ptr->ccu8_slice_ptr, handle_ptr->ccu8_slice_config_ptr);
447
448 /* Set the period and compare register values */
449 XMC_CCU8_SLICE_SetTimerPeriodMatch(handle_ptr->ccu8_slice_ptr,
450 (uint16_t)handle_ptr->period_value);
451
452 XMC_CCU8_SLICE_SetTimerCompareMatch(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_COMPARE_CHANNEL_1,
453 (uint16_t)handle_ptr->compare_value);
454
455 XMC_CCU8_EnableShadowTransfer(handle_ptr->ccu8_kernel_ptr, handle_ptr->shadow_mask);
456
457 /* Initialize interrupts */
458 PWM_lCCU8_ConfigInterrupts(handle_ptr);
459
460 XMC_GPIO_Init(handle_ptr->gpio_out_port,handle_ptr->gpio_out_pin,
461 handle_ptr->gpio_out_config);
462
463 handle_ptr->state = PWM_STATUS_SUCCESS;
464
465 /* Start the PWM generation if start at initialization is enabled */
466 if ((bool) true == handle_ptr->start_control)
467 {
468 PWM_Start(handle_ptr);
469 }
470 status = PWM_STATUS_SUCCESS;
471 }
472 else
473 {
474 handle_ptr->state = PWM_STATUS_UNINITIALIZED;
475 }
476
477 }
478 return(status);
479 } /* end of PWM_lCCU8_Init() api */
480
481 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
482 /* Initialize interrupts */
483 void PWM_lCCU8_ConfigInterrupts(PWM_t *const handle_ptr)
484 {
485 if ((bool) true == handle_ptr->period_match_enable)
486 {
487 XMC_DEBUG("PWM_lCCU8_ConfigInterrupts:period match event enable")
488
489 XMC_CCU8_SLICE_EnableEvent(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH);
490
491 /* Bind event to Service Request Node for period match event */
492 XMC_CCU8_SLICE_SetInterruptNode(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH,
493 handle_ptr->ccu8_slice_period_match_node);
494 }
495
496 if ((bool) true == handle_ptr->compare_match_enable)
497 {
498 XMC_DEBUG("PWM_lCCU8_ConfigInterrupts:compare match event enable ")
499
500 XMC_CCU8_SLICE_EnableEvent(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_UP_CH_1);
501 /* Bind event to Service Request Node for compare match event */
502 XMC_CCU8_SLICE_SetInterruptNode(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_UP_CH_1,
503 handle_ptr->ccu8_slice_compare_match_node);
504 }
505 }
506
507 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
508 /*Starts the CCU8 slice. */
509 void PWM_lCCU8_Start(PWM_t *const handle_ptr)
510 {
511 XMC_ASSERT("PWM_lCCU8_Start:Invalid handle_ptr" , (handle_ptr != NULL))
512
513 if ((PWM_STATUS_SUCCESS == handle_ptr->state) || (PWM_STATUS_STOPPED == handle_ptr->state))
514 {
515 /* Clears IDLE mode for the slice */
516 XMC_CCU8_EnableClock(handle_ptr->ccu8_kernel_ptr,handle_ptr->slice_number);
517 XMC_CCU8_SLICE_StartTimer(handle_ptr->ccu8_slice_ptr);
518
519 handle_ptr->state = PWM_STATUS_RUNNING;
520 XMC_DEBUG("PWM_lCCU8_Start:start PWM")
521 }
522 } /* end of PWM_lCCU8_Start() api */
523
524 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
525 /*Stops the CCU8 slice. */
526 void PWM_lCCU8_Stop(PWM_t *const handle_ptr)
527 {
528 XMC_ASSERT("PWM_lCCU8_Stop:Invalid handle_ptr" , (handle_ptr != NULL))
529
530 if (PWM_STATUS_UNINITIALIZED != handle_ptr->state)
531 {
532 XMC_CCU8_SLICE_StopTimer(handle_ptr->ccu8_slice_ptr);
533 XMC_CCU8_SLICE_ClearTimer(handle_ptr->ccu8_slice_ptr);
534 XMC_CCU8_DisableClock(handle_ptr->ccu8_kernel_ptr, handle_ptr->slice_number);
535
536 handle_ptr->state = PWM_STATUS_STOPPED;
537 XMC_DEBUG("PWM_lCCU8_Stop:stop PWM")
538 }
539 } /* end of PWM_lCCU8_Stop() api */
540
541 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
542 /*Sets the duty cycle for CCU8 slice. */
543 PWM_STATUS_t PWM_lCCU8_SetDutyCycle(PWM_t *const handle_ptr, uint32_t duty_cycle)
544 {
545 uint32_t period;
546 uint32_t compare;
547 PWM_STATUS_t status;
548
549 XMC_ASSERT("PWM_lCCU8_SetDutyCycle:Invalid handle_ptr" , (handle_ptr != NULL))
550 XMC_ASSERT("PWM_lCCU8_SetDutyCycle:Invalid duty_cycle",((duty_cycle >= 0) &&
551 (duty_cycle <= PWM_MAX_DUTY_CYCLE)))
552
553 status = PWM_STATUS_FAILURE;
554 if (handle_ptr->state != PWM_STATUS_UNINITIALIZED)
555 {
556 /* Duty cycle needs between 0 and 10000 */
557 if (duty_cycle <= PWM_MAX_DUTY_CYCLE)
558 {
559 period = (uint32_t)handle_ptr->period_value + 1U;
560
561 /* Duty Cycle(symmetric) = (PR-CR1)+1 / period */
562 compare = ((period * ((uint32_t) PWM_MAX_DUTY_CYCLE - duty_cycle)) / ((uint32_t) 100 * PWM_DUTY_CYCLE_SCALE));
563
564 handle_ptr->compare_value = compare;
565 handle_ptr->duty_cycle = duty_cycle;
566
567 XMC_CCU8_SLICE_SetTimerCompareMatch(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_COMPARE_CHANNEL_1,
568 (uint16_t)compare);
569
570 XMC_CCU8_EnableShadowTransfer(handle_ptr->ccu8_kernel_ptr, handle_ptr->shadow_mask);
571 status = PWM_STATUS_SUCCESS;
572 }
573 }
574
575 XMC_DEBUG("PWM_lCCU8_SetDutyCycle:dutycycle set")
576 return (status);
577 } /* end of PWM_lCCU8_SetDutyCycle() api */
578
579 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
580 /*Sets the frequency for CCU8 slice. */
581 PWM_STATUS_t PWM_lCCU8_SetFreq(PWM_t *const handle_ptr, uint32_t pwm_freq_hz)
582 {
583 PWM_STATUS_t status;
584 uint32_t module_freq;
585 uint8_t prescaler;
586 uint32_t period_value;
587 uint32_t compare;
588
589 XMC_ASSERT("PWM_lCCU8_SetFreq:Invalid pwm_freq_hz " , (pwm_freq_hz != 0U))
590
591 status = handle_ptr->state;
592 prescaler = 0U;
593 period_value = 0U;
594
595 /* Can't set the frequency when the PWM is not yet initialized or when required frequency is 0*/
596 if ((status != PWM_STATUS_UNINITIALIZED) && ((uint32_t)0 != pwm_freq_hz))
597 {
598 status = PWM_STATUS_SUCCESS;
599 /*Get the Module frequency*/
600 module_freq = handle_ptr->global_ccu8_handle->module_frequency;
601
602 /*Calculate the prescaler and the period register values.*/
603 while (prescaler <= PWM_MAX_PRESCALER)
604 {
605 period_value = (uint32_t)((uint32_t)module_freq / (uint32_t)pwm_freq_hz) >> (uint32_t)prescaler;
606 /*If the prescaler selected is not big enough goto the next prescaler value else come out.*/
607 if (period_value <= PWM_MAX_TIMER_COUNT)
608 {
609 break;
610 }
611
612 prescaler++;
613 }
614
615 /*Can't set the frequency if the required value is too small or when the required frequency is too large.*/
616 if ((prescaler > PWM_MAX_PRESCALER) || ((uint32_t)0 == period_value))
617 {
618 XMC_DEBUG("PWM_lCCU8_SetFreq:frequency could not be set")
619 status = PWM_STATUS_FAILURE;
620 }
621 else
622 {
623 /*Calculate the new compare values using new period values*/
624 compare = (period_value * (PWM_MAX_DUTY_CYCLE - handle_ptr->duty_cycle))
625 / ((uint32_t) 100 * PWM_DUTY_CYCLE_SCALE);
626
627 XMC_CCU8_SLICE_SetPrescaler(handle_ptr->ccu8_slice_ptr, prescaler);
628
629 /* The period register is always one count less than calculated.*/
630 period_value = period_value - (uint32_t)1;
631 XMC_CCU8_SLICE_SetTimerPeriodMatch(handle_ptr->ccu8_slice_ptr, (uint16_t)(period_value));
632
633 XMC_CCU8_SLICE_SetTimerCompareMatch(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_COMPARE_CHANNEL_1,
634 (uint16_t)compare);
635
636 XMC_CCU8_EnableShadowTransfer(handle_ptr->ccu8_kernel_ptr, handle_ptr->shadow_mask);
637
638 handle_ptr->compare_value = compare;
639 handle_ptr->period_value = period_value;
640 XMC_DEBUG("PWM_lCCU8_SetFreq:frequency set")
641 }
642 }
643 else
644 {
645 status = PWM_STATUS_FAILURE;
646 XMC_DEBUG("PWM_lCCU8_SetFreq:frequency could not be set")
647 }
648
649 return status;
650 } /* end of PWM_lCCU8_SetFreq() api */
651
652 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
653 /*Sets the frequency and duty cycle for CCU8 slice. */
654 PWM_STATUS_t PWM_lCCU8_SetFreqAndDutyCycle(PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle)
655 {
656 PWM_STATUS_t status;
657 uint32_t module_freq;
658 uint8_t prescaler;
659 uint32_t period_value;
660 uint32_t compare;
661
662 XMC_ASSERT("PWM_lCCU8_SetFreqAndDutyCycle:Invalid pwm_freq_hz " , (pwm_freq_hz != 0U))
663 XMC_ASSERT("PWM_lCCU8_SetFreqAndDutyCycle:Invalid duty_cycle",((duty_cycle >= 0) &&
664 (duty_cycle <= PWM_MAX_DUTY_CYCLE)))
665
666 status = handle_ptr->state;
667 prescaler = 0U;
668 period_value = 0U;
669
670 /* Can't set the frequency when the PWM is not yet initialized or when required frequency is 0*/
671 if ((status != PWM_STATUS_UNINITIALIZED) && ((uint32_t)0 != pwm_freq_hz))
672 {
673 status = PWM_STATUS_SUCCESS;
674 /*Get the Module frequency*/
675 module_freq = handle_ptr->global_ccu8_handle->module_frequency;
676
677 /*Calculate the prescaler and the period register values.*/
678 while (prescaler <= PWM_MAX_PRESCALER)
679 {
680 period_value = (uint32_t)((uint32_t)module_freq / (uint32_t)pwm_freq_hz) >> (uint32_t)prescaler;
681 /*If the prescaler selected is not big enough goto the next prescaler value else come out.*/
682 if (period_value <= PWM_MAX_TIMER_COUNT)
683 {
684 break;
685 }
686 prescaler++;
687 }
688
689 /*Can't set the frequency if the required value is too small or when the required frequency is too large.*/
690 if ((prescaler > PWM_MAX_PRESCALER) || (duty_cycle > PWM_MAX_DUTY_CYCLE) || ((uint32_t)0 == period_value))
691 {
692 XMC_DEBUG("PWM_lCCU8_SetFreqAndDutyCycle:Frequency or duty cycle could not be set")
693 status = PWM_STATUS_FAILURE;
694 }
695 else
696 {
697 /*Calculate the new compare values using new period values */
698 compare = (period_value * ((uint32_t)PWM_MAX_DUTY_CYCLE - duty_cycle)) / ((uint32_t) 100 * PWM_DUTY_CYCLE_SCALE);
699
700 XMC_CCU8_SLICE_SetPrescaler(handle_ptr->ccu8_slice_ptr, prescaler);
701
702 /* The period register is always one count less than calculated.*/
703 period_value = period_value - (uint32_t)1;
704 XMC_CCU8_SLICE_SetTimerPeriodMatch(handle_ptr->ccu8_slice_ptr, (uint16_t)(period_value));
705
706 XMC_CCU8_SLICE_SetTimerCompareMatch(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_COMPARE_CHANNEL_1,
707 (uint16_t)compare);
708
709 XMC_CCU8_EnableShadowTransfer(handle_ptr->ccu8_kernel_ptr, handle_ptr->shadow_mask);
710
711 handle_ptr->compare_value = compare;
712 handle_ptr->period_value = period_value;
713 handle_ptr->duty_cycle = duty_cycle;
714 XMC_DEBUG("PWM_lCCU8_SetFreqAndDutyCycle:Frequency and Duty cycle set")
715 }
716 }
717 else
718 {
719 status = PWM_STATUS_FAILURE;
720 XMC_DEBUG("PWM_lCCU8_SetFreqAndDutyCycle:Frequency and Duty cycle could not be set")
721 }
722
723
724 return status;
725 } /* end of PWM_lCCU8_SetFreqAndDutyCycle() api */
726
727 #endif /* end of CCU8 function definitions */
728
729 /**********************************************************************************************************************
730 * API IMPLEMENTATION
731 **********************************************************************************************************************/
732
733 /*This function returns the version of the PWM App*/
734 DAVE_APP_VERSION_t PWM_GetAppVersion(void)
735 {
736 DAVE_APP_VERSION_t version;
737
738 version.major = (uint8_t) PWM_MAJOR_VERSION;
739 version.minor = (uint8_t) PWM_MINOR_VERSION;
740 version.patch = (uint8_t) PWM_PATCH_VERSION;
741
742 return version;
743 }
744
745 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
746 /* This function initializes the app */
747 PWM_STATUS_t PWM_Init(PWM_t *const handle_ptr)
748 {
749 PWM_STATUS_t status;
750 status = PWM_STATUS_FAILURE;
751
752 XMC_ASSERT("PWM_Init:Invalid handle_ptr" , (handle_ptr != NULL))
753
754 #ifdef PWM_SLICE_USED_CCU4
755 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
756 {
757 status = PWM_lCCU4_Init(handle_ptr);
758 }
759 #endif
760
761 #ifdef PWM_SLICE_USED_CCU8
762 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
763 {
764 status = PWM_lCCU8_Init(handle_ptr);
765 }
766 #endif
767
768 return (status);
769 }
770
771 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
772 /* This function starts the PWM generation. This needs to be called even if external start is configured.*/
773 void PWM_Start(PWM_t *const handle_ptr)
774 {
775 XMC_ASSERT("PWM_Start:Invalid handle_ptr" , (handle_ptr != NULL))
776
777 #ifdef PWM_SLICE_USED_CCU4
778 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
779 {
780 PWM_lCCU4_Start(handle_ptr);
781 }
782 #endif
783
784 #ifdef PWM_SLICE_USED_CCU8
785 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
786 {
787 PWM_lCCU8_Start(handle_ptr);
788 }
789 #endif
790 }
791
792 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
793 /* This function stops the PWM generation. */
794 void PWM_Stop(PWM_t *const handle_ptr)
795 {
796
797 XMC_ASSERT("PWM_Stop:Invalid handle_ptr" , (handle_ptr != NULL))
798
799 #ifdef PWM_SLICE_USED_CCU4
800 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
801 {
802 PWM_lCCU4_Stop(handle_ptr);
803 }
804 #endif
805
806 #ifdef PWM_SLICE_USED_CCU8
807 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
808 {
809 PWM_lCCU8_Stop(handle_ptr);
810 }
811 #endif
812 }
813
814 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
815 /*This function is used to set the duty cycle (uint32_t) of the PWM waveform */
816 PWM_STATUS_t PWM_SetDutyCycle(PWM_t *const handle_ptr, uint32_t duty_cycle)
817 {
818 PWM_STATUS_t status;
819 status = PWM_STATUS_FAILURE;
820
821 XMC_ASSERT("PWM_SetDutyCycle:Invalid handle_ptr" , (handle_ptr != NULL))
822
823 #ifdef PWM_SLICE_USED_CCU4
824 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
825 {
826 status = PWM_lCCU4_SetDutyCycle(handle_ptr, duty_cycle);
827 }
828 #endif
829
830 #ifdef PWM_SLICE_USED_CCU8
831 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
832 {
833 status = PWM_lCCU8_SetDutyCycle(handle_ptr, duty_cycle);
834 }
835 #endif
836 return (status);
837 }
838
839 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
840 /*This function changes the PWM frequency. Input parameter is the frequency value in Hz */
841 PWM_STATUS_t PWM_SetFreq(PWM_t *const handle_ptr, uint32_t pwm_freq_hz)
842 {
843 PWM_STATUS_t status;
844 status = PWM_STATUS_FAILURE;
845
846 XMC_ASSERT("PWM_SetFreq:Invalid handle_ptr" , (handle_ptr != NULL))
847
848 #ifdef PWM_SLICE_USED_CCU4
849 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
850 {
851 status = PWM_lCCU4_SetFreq(handle_ptr, pwm_freq_hz);
852 }
853 #endif
854
855 #ifdef PWM_SLICE_USED_CCU8
856 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
857 {
858 status = PWM_lCCU8_SetFreq(handle_ptr, pwm_freq_hz);
859 }
860 #endif
861 return status;
862 }
863
864 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
865 /*This function sets frequency and the duty cycle */
866 PWM_STATUS_t PWM_SetFreqAndDutyCycle(PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle)
867 {
868 PWM_STATUS_t status;
869 status = PWM_STATUS_FAILURE;
870
871 XMC_ASSERT("PWM_SetFreqAndDutyCycle:Invalid handle_ptr" , (handle_ptr != NULL))
872
873 #ifdef PWM_SLICE_USED_CCU4
874 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
875 {
876 status = PWM_lCCU4_SetFreqAndDutyCycle(handle_ptr, pwm_freq_hz, duty_cycle);
877 }
878 #endif
879
880 #ifdef PWM_SLICE_USED_CCU8
881 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
882 {
883 status = PWM_lCCU8_SetFreqAndDutyCycle(handle_ptr, pwm_freq_hz, duty_cycle);
884 }
885 #endif
886 return status;
887 }
888
889 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
890 /*This function changes the PWM timer status_timer */
891 bool PWM_GetTimerStatus(PWM_t *const handle_ptr)
892 {
893 bool status_timer;
894 status_timer = (bool)false;
895
896 XMC_ASSERT("PWM_GetTimerStatus:Invalid handle_ptr" , (handle_ptr != NULL))
897
898 #ifdef PWM_SLICE_USED_CCU4
899 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
900 {
901 status_timer = XMC_CCU4_SLICE_IsTimerRunning(handle_ptr->ccu4_slice_ptr);
902 }
903 #endif
904
905 #ifdef PWM_SLICE_USED_CCU8
906 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
907 {
908 status_timer = XMC_CCU8_SLICE_IsTimerRunning(handle_ptr->ccu8_slice_ptr);
909 }
910 #endif
911
912 return (status_timer);
913 }
914
915 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
916 /*This function returns the interrupt status_timer */
917 bool PWM_GetInterruptStatus(PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
918 {
919 bool status;
920 status = (bool) false;
921
922 XMC_ASSERT("PWM_GetInterruptStatus:Invalid handle_ptr" , (handle_ptr != NULL))
923
924 #ifdef PWM_SLICE_USED_CCU4
925 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
926 {
927 status = XMC_CCU4_SLICE_GetEvent(handle_ptr->ccu4_slice_ptr, (XMC_CCU4_SLICE_IRQ_ID_t)pwm_interrupt);
928 }
929 #endif
930
931 #ifdef PWM_SLICE_USED_CCU8
932 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
933 {
934 status = XMC_CCU8_SLICE_GetEvent(handle_ptr->ccu8_slice_ptr, (XMC_CCU8_SLICE_IRQ_ID_t)pwm_interrupt);
935 }
936 #endif
937
938 return status;
939 }
940
941 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
942 /*This function Acknowledges the corresponding interrupt */
943 void PWM_ClearEvent(PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
944 {
945 XMC_ASSERT("PWM_ClearEvent:Invalid handle_ptr" , (handle_ptr != NULL))
946
947 #ifdef PWM_SLICE_USED_CCU4
948 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
949 {
950 XMC_CCU4_SLICE_ClearEvent(handle_ptr->ccu4_slice_ptr, (XMC_CCU4_SLICE_IRQ_ID_t) pwm_interrupt);
951 }
952 #endif
953
954 #ifdef PWM_SLICE_USED_CCU8
955 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
956 {
957 XMC_CCU8_SLICE_ClearEvent(handle_ptr->ccu8_slice_ptr, (XMC_CCU8_SLICE_IRQ_ID_t) pwm_interrupt);
958 }
959 #endif
960 }
961
962 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
963 /*This function sets the passive level of the PWM*/
964 void PWM_SetPassiveLevel(PWM_t *const handle_ptr, PWM_OUTPUT_PASSIVE_LEVEL_t pwm_output_passive_level)
965 {
966 XMC_ASSERT("PWM_SetPassiveLevel:Invalid handle_ptr" , (handle_ptr != NULL))
967 XMC_ASSERT("PWM_SetPassiveLevel:Invalid pwm_output_passive_level " ,
968 (pwm_output_passive_level < PWM_OUTPUT_PASSIVE_LEVEL_MAX));
969
970 #ifdef PWM_SLICE_USED_CCU4
971 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
972 {
973 XMC_CCU4_SLICE_SetPassiveLevel(handle_ptr->ccu4_slice_ptr,
974 (XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_t)pwm_output_passive_level);
975
976 XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_kernel_ptr, handle_ptr->shadow_mask);
977 XMC_DEBUG("PWM_SetPassiveLevel:CCU4 slice, passive level changed")
978 }
979 #endif
980
981 #ifdef PWM_SLICE_USED_CCU8
982 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
983 {
984 XMC_CCU8_SLICE_SetPassiveLevel(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_OUTPUT_0,
985 (XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_t)pwm_output_passive_level);
986
987 XMC_CCU8_EnableShadowTransfer(handle_ptr->ccu8_kernel_ptr, handle_ptr->shadow_mask);
988 XMC_DEBUG("PWM_SetPassiveLevel:CCU8 slice, passive level changed")
989 }
990 #endif
991 }
992
993 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
994 /*Configures the period register */
995 PWM_STATUS_t PWM_SetPeriodMatchValue(PWM_t *const handle_ptr, uint32_t period_match_value)
996 {
997 uint32_t compare;
998 PWM_STATUS_t status;
999
1000 XMC_ASSERT("PWM_SetPeriodMatchValue:Invalid handle_ptr" , (handle_ptr != NULL))
1001 XMC_ASSERT("PWM_SetPeriodMatchValue:Invalid period_match_value" , (period_match_value <= PWM_MAX_PERIOD_VALUE))
1002
1003 status = handle_ptr->state;
1004
1005 if ( (status != PWM_STATUS_UNINITIALIZED) && (PWM_MAX_PERIOD_VALUE >= period_match_value))
1006 {
1007 compare = (period_match_value * ((uint32_t)PWM_MAX_DUTY_CYCLE - handle_ptr->duty_cycle))
1008 / ((uint32_t) 100 * PWM_DUTY_CYCLE_SCALE);
1009
1010 #ifdef PWM_SLICE_USED_CCU4
1011 if (PWM_TIMER_SLICE_CCU4 == handle_ptr->timer_type)
1012 {
1013 XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)period_match_value);
1014
1015 XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr, (uint16_t)compare );
1016
1017 XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_kernel_ptr, handle_ptr->shadow_mask);
1018 }
1019 #endif
1020
1021 #ifdef PWM_SLICE_USED_CCU8
1022 if (PWM_TIMER_SLICE_CCU8 == handle_ptr->timer_type)
1023 {
1024 XMC_CCU8_SLICE_SetTimerPeriodMatch(handle_ptr->ccu8_slice_ptr, (uint16_t)period_match_value);
1025
1026 XMC_CCU8_SLICE_SetTimerCompareMatch(handle_ptr->ccu8_slice_ptr, XMC_CCU8_SLICE_COMPARE_CHANNEL_1,
1027 (uint16_t)compare);
1028
1029 XMC_CCU8_EnableShadowTransfer(handle_ptr->ccu8_kernel_ptr, handle_ptr->shadow_mask);
1030 }
1031 #endif
1032 handle_ptr->period_value = period_match_value;
1033 handle_ptr->compare_value = compare;
1034 status = PWM_STATUS_SUCCESS;
1035 }
1036 else
1037 {
1038 status = PWM_STATUS_FAILURE;
1039 }
1040
1041 return (status);
1042 }
1043 /*CODE_BLOCK_END*/
1044


PWM: PWM.h Source File

PWM
  • File List
  • Globals
  • Code
PWM.h
Go to the documentation of this file.
1
79 #ifndef PWM_H
80 #define PWM_H
81
82
83 /***********************************************************************************************************************
84 * HEADER FILES
85 **********************************************************************************************************************/
86 #include "xmc_gpio.h"
87 #include "pwm_conf.h"
88 #include "DAVE_Common.h"
89
90 /**********************************************************************************************************************
91 * MACROS
92 **********************************************************************************************************************/
93 #define PWM_XMC_LIB_MAJOR_VERSION 2
94 #define PWM_XMC_LIB_MINOR_VERSION 0
95 #define PWM_XMC_LIB_PATCH_VERSION 0
96
97 #if !((XMC_LIB_MAJOR_VERSION > PWM_XMC_LIB_MAJOR_VERSION) ||\
98 ((XMC_LIB_MAJOR_VERSION == PWM_XMC_LIB_MAJOR_VERSION) && (XMC_LIB_MINOR_VERSION > PWM_XMC_LIB_MINOR_VERSION)) ||\
99 ((XMC_LIB_MAJOR_VERSION == PWM_XMC_LIB_MAJOR_VERSION) && (XMC_LIB_MINOR_VERSION == PWM_XMC_LIB_MINOR_VERSION) && (XMC_LIB_PATCH_VERSION >= PWM_XMC_LIB_PATCH_VERSION)))
100 #error "PWM requires XMC Peripheral Library v2.0.0 or higher"
101 #endif
102
103 #define PWM_MAX_TIMER_COUNT (65535U)
105 /**********************************************************************************************************************
106 * ENUMS
107 **********************************************************************************************************************/
108
115 typedef enum PWM_TIMER_SLICE
116 {
117 PWM_TIMER_SLICE_CCU4 = 0U,
118 PWM_TIMER_SLICE_CCU8
119 } PWM_TIMER_SLICE_t;
120
124 typedef enum PWM_TIMER_STATUS
125 {
126 PWM_TIMER_IDLE = 0U,
127 PWM_TIMER_RUNNING
128 } PWM_TIMER_STATUS_t;
129
133 typedef enum PWM_INTERRUPT
134 {
135 PWM_INTERRUPT_PERIODMATCH = 0U,
136 PWM_INTERRUPT_COMPAREMATCH = 2U
137 } PWM_INTERRUPT_t;
138
142 typedef enum PWM_OUTPUT_PASSIVE_LEVEL
143 {
144 PWM_OUTPUT_PASSIVE_LEVEL_LOW = 0,
145 PWM_OUTPUT_PASSIVE_LEVEL_HIGH ,
146 PWM_OUTPUT_PASSIVE_LEVEL_MAX
147 } PWM_OUTPUT_PASSIVE_LEVEL_t;
148
152 typedef enum PWM_STATUS
153 {
154 PWM_STATUS_SUCCESS = 0,
155 PWM_STATUS_FAILURE,
156 PWM_STATUS_UNINITIALIZED,
157 PWM_STATUS_RUNNING,
158 PWM_STATUS_STOPPED,
159 } PWM_STATUS_t;
160
164 typedef enum PWM_ERROR_CODES
165 {
166 PWM_OPER_NOT_ALLOWED_ERROR = 1,
167 PWM_INVALID_PARAM_ERROR
168 } PWM_ERROR_CODES_t;
169
174 /**********************************************************************************************************************
175 * DATA STRUCTURES
176 **********************************************************************************************************************/
181 /*Anonymous structure/union guard start*/
182 #if defined(__CC_ARM)
183 #pragma push
184 #pragma anon_unions
185 #elif defined(__TASKING__)
186 #pragma warning 586
187 #endif
188
191 typedef struct PWM_HandleType
192 {
193 union
194 {
195 #ifdef PWM_SLICE_USED_CCU4
196 GLOBAL_CCU4_t *const global_ccu4_handle;
197 #endif
198 #ifdef PWM_SLICE_USED_CCU8
199 GLOBAL_CCU8_t *const global_ccu8_handle;
200 #endif
201 };
202
203 union
204 {
205 #ifdef PWM_SLICE_USED_CCU4
206 XMC_CCU4_MODULE_t *const ccu4_kernel_ptr;
207 #endif
208 #ifdef PWM_SLICE_USED_CCU8
209 XMC_CCU8_MODULE_t *const ccu8_kernel_ptr;
210 #endif
211 };
212
213 union
214 {
215 #ifdef PWM_SLICE_USED_CCU4
216 XMC_CCU4_SLICE_t *const ccu4_slice_ptr;
217 #endif
218 #ifdef PWM_SLICE_USED_CCU8
219 XMC_CCU8_SLICE_t *const ccu8_slice_ptr;
220 #endif
221 };
222
223 union
224 {
225 #ifdef PWM_SLICE_USED_CCU4
226 const XMC_CCU4_SLICE_COMPARE_CONFIG_t *const ccu4_slice_config_ptr;
227 #endif
228 #ifdef PWM_SLICE_USED_CCU8
229 const XMC_CCU8_SLICE_COMPARE_CONFIG_t *const ccu8_slice_config_ptr;
230 #endif
231 };
232
233 XMC_GPIO_PORT_t *const gpio_out_port;
235 const XMC_GPIO_CONFIG_t *const gpio_out_config;
237 uint32_t compare_value;
239 uint32_t period_value;
241 uint32_t duty_cycle;
243 uint32_t shadow_mask;
245 const PWM_TIMER_SLICE_t timer_type;
247 PWM_STATUS_t state;
249 union
250 {
251 #ifdef PWM_SLICE_USED_CCU4
252 const XMC_CCU4_SLICE_SR_ID_t ccu4_slice_period_match_node;
253 #endif
254 #ifdef PWM_SLICE_USED_CCU8
255 const XMC_CCU8_SLICE_SR_ID_t ccu8_slice_period_match_node;
256 #endif
257 };
258
259 union
260 {
261 #ifdef PWM_SLICE_USED_CCU4
262 const XMC_CCU4_SLICE_SR_ID_t ccu4_slice_compare_match_node;
263 #endif
264 #ifdef PWM_SLICE_USED_CCU8
265 const XMC_CCU8_SLICE_SR_ID_t ccu8_slice_compare_match_node;
266 #endif
267 };
268
269 const uint8_t gpio_out_pin;
271 const uint8_t kernel_number;
273 const uint8_t slice_number;
275 const bool start_control;
277 const bool period_match_enable;
279 const bool compare_match_enable;
281 } PWM_t;
282
286 /*Anonymous structure/union guard end*/
287 #if defined(__CC_ARM)
288 #pragma pop
289 #elif defined(__TASKING__)
290 #pragma warning restore
291 #endif
292
296 #ifdef __cplusplus
297 extern "C" {
298 #endif
299 /***********************************************************************************************************************
300 * API Prototypes
301 **********************************************************************************************************************/
338 DAVE_APP_VERSION_t PWM_GetAppVersion(void);
339
364 PWM_STATUS_t PWM_Init(PWM_t *const handle_ptr);
365
394 void PWM_Start(PWM_t *const handle_ptr);
395
422 void PWM_Stop(PWM_t *const handle_ptr);
423
471 PWM_STATUS_t PWM_SetFreq(PWM_t *const handle_ptr, uint32_t pwm_freq_hz);
472
529 PWM_STATUS_t PWM_SetFreqAndDutyCycle(PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle);
530
585 void PWM_ClearEvent(PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt);
586
625 bool PWM_GetInterruptStatus(PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt);
626
652 bool PWM_GetTimerStatus(PWM_t *const handle_ptr);
653
722 PWM_STATUS_t PWM_SetDutyCycle(PWM_t *const handle_ptr, uint32_t duty_cycle);
723
724
768 void PWM_SetPassiveLevel(PWM_t *const handle_ptr, PWM_OUTPUT_PASSIVE_LEVEL_t pwm_output_passive_level);
769
814 PWM_STATUS_t PWM_SetPeriodMatchValue(PWM_t *const handle_ptr, uint32_t period_match_value);
815
816 #include "PWM_Extern.h"
817
821 #ifdef __cplusplus
822 }
823 #endif
824
825 #endif /* PWM_H_ */


PWM: Code Directory Reference

PWM
  • Code
Code Directory Reference

Files

file | PWM.c [code]
file | PWM.h [code]


Control Name | Range/Items | Description
Compare match | Enable/Disable | Configures the compare match event. When selected, this connects the event to a Service Request line and enables the generation of an interrupt pulse each time a compare match (while counting up). Note: To enable generation of interrupt, user needs to connect this event to an INTERRUPT APP.
Period match | Enable/Disable | Configures the period match event. When selected, this connects the event to a Service Request line and enables the generation of an interrupt pulse each time a period match (while counting up). Note: To enable generation of interrupt, user needs to connect this event to an INTERRUPT APP.


Generated on 11-Jan-2021 09:27:08 for PWM Version 4.1.12


Control Name | Range/Items | Description
Select timer module CCU4
CCU8
         Select a valid CCU timer module to generate a PWM:
  • CCU4 : One slice from CCU4 module is used.
  • CCU8 : One slice from CCU8 module is used.
Frequency [Hz] 1 to MAX_VALUE Set desired frequency of PWM signal.
  • It decides the period register value of selected CCU timer.
  • Calculates the timer prescaler value to achieve best resolution.
  • Sets the parameter "period_value" of PWM_Dynamic_t configuration handle.
  • Configures the timer period, by writing CCU4 /CCU8 PRS register.
Duty cycle [%] 0 to 100.0 Set desired duty cycle of PWM signal:
  • It decides the compare register value of selected CCU timer.
  • Decides the proportion of ON time with the period value.
  • Sets the parameter "duty_cycle" of PWM_Dynamic_t configuration handle.
  • Calculates and updates the parameter "compare_value" of PWM_Dynamic_t configuration handle.
  • Configures the timer compare value, by writing CCU4 /CCU8 CRS register.
Resolution [nsec] | 8.33 to 273066.6 | This represents the resolution for timer operation. This is the actual minimum step for the timer.
Start after initialization Enable/Disable
         Enables the timer after initialization. This causes the PWM to be generated.
Enable single shot mode Enable/Disable
         Set the timer mode of operation. When enabled, timer operates in single shot mode and timer will stop after one cycle of the PWM.


PWM: Abbreviations and Definitions

PWM
Abbreviations and Definitions

Abbreviations and Definitions

Abbreviations:
DAVE™ | Digital Application Virtual Engineer
APP | DAVE™ Application
API | Application Programming Interface
GUI | Graphical User Interface
MCU | Microcontroller Unit
SW | Software
HW | Hardware
LLD | Low Level Driver
IO | Input Output
CCU4 | Capture Compare Unit 4
CCU8 | Capture Compare Unit 8
CCUx | Capture Compare Unit 4/Capture Compare Unit 8

Definitions:
Singleton | Only single instance of the APP is permitted
Sharable | Resource sharing with other APPs is permitted
initProvider | Provides the initialization routine
Physical connectivity | Hardware inter/intra peripheral (constant) signal connection
Conditional connectivity | Constrained hardware inter/intra peripheral signal connection
Aggregation | Indicates consumption of low level (dependent) DAVE APPs


PWM: Architecture Description

PWM
Architecture Description

Architecture Description

Figure 1 : Architecture of PWM APP

Figure 1 shows the internal software architecture of the PWM APP. The figure shows the consumed hardware resources, dependent APPs and various signals which are exported out. A PWM APP instance exists in a DAVE™ project with fixed attributes as shown in Figure 1 and uses the CCU peripheral for generating a PWM signal. This in addition requires the consumption of the GLOBAL_CCUx (x =4, 8) and CLOCK APPS for its configuration and functioning. The PWM APP also provides output signals for inter-peripheral connections.An instantiated APP (after code generation) generates a specific data structure with the GUI configuration. The name of this data structure can be modified by changing the APP instance label (e.g. change label from default PWM_0 to MY_PWM).Signals:
The following table presents the signals provided by the APP for connection. It also gives the flexibility to configure and extend the connectivity to other APPs.Table 1: APP I0 signals

Signal Name | Input/Output | Availability | Description
event_period_match | Output | Always | Period match interrupt signal: This can be connected to an INTERRUPT APP to generate the interrupt for each period match event.
event_compare_match | Output | Always | Compare match interrupt signal: This can be connected with INTERRUPT APP to generate the interrupt for each compare match event.
timer_status | Output | Always | Timer status (ST) signal: This is the slice comparison status value. It can be used as a trigger input to other peripheral modules (e.g. ADC, CCU4, CCU8).
pwm_output | Output | Always | Output (OUT) signal: The output PWM signal can be connected with any pad pin. The list of available pins are shown in "Manual Pin Allocator" tab in DAVE™
global_signal | Input | Always | Global signal connection Connected between the kernel and the respective slice. Used to constrain the slice to the kernel provided by GLOBAL_CCUx APP. Connected by default at instantiation.

Frequency and duty cycle

CCU in Edge aligned Symmetric Mode of operation.In this mode of operation we can use the compare registers to generate 1 output. The minimum duty that can be generated is 0% and maximum is 100%. Here the output is initially LOW until compare match happens. The output remains HIGH until the next one match happens.

Figure 2: Edge Aligned Symmetric Mode
Example:Let

Note: The value loaded to period register is (period - 1) i.e. 1199.


PWM: License Terms and Copyright Information

PWM
License Terms and Copyright Information

License Terms and Copyright Information

Copyright (c) 2015, Infineon Technologies AG All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with Infineon Technologies AG (dave@.nosp@m.infi.nosp@m.neon..nosp@m.com).


PWM: Overview

PWM
Overview

Overview

The PWM APP provides the following functionalities using CCU4 or CCU8 peripheral:

  1. It allows to enter the desired PWM frequency and the duty cycle.
  2. The APP tries to get the best PWM resolution (timer tick). It calculates Timer Tick, Period Value (PV) and Compare Value (CV). Note: The desired values may not be exactly possible. The timer is always used in 16bit mode with prescalar.
  3. PWM can be started after initialization or at a later time as required by calling the API PWM_Start()
  4. PWM can operate in single shot mode or continuous mode.
  5. Allows generation of period match or compare match events for interrupt generation (to be connected to an INTERRUPT APP).
  6. Connects the PWM output to a GPIO (open drain, push/pull) or to other peripherals via interconnect (timer status flag/ period match event / compare match event)
Figure 1 : Overview of PWM APP
Figure 1, shows the functional overview of the PWM APP. The CCU peripheral starts a internal counter which counts the clock pulses provided by the prescalar. When the count reaches the compare match value, the PWM output state will change from passive state (either a high state or low state) to active state(either a low state or high state). The timer will still continue to count even after the compare match event has occurred. When the count value reaches the Period match value, the PWM output state is returned to the passive state. Thus completing one cycle of the PWM. If Single-Shot mode is not selected, then this cycle would repeat continuously. If Single-Shot mode is selected, then the PWM will remain in the passive state and the timer will stop running.
Period match(PM) value is calculated based on the frequency and Compare match is calculated based on duty cycle. The PWM output state changes at period and compare match.
Figure 2 : Hardware and Software connectivity of PWM APP
Figure 2 shows how the APP is structured in DAVE™. XMC controllers provide the CCU4 or CCU8 module to generate the PWM waveforms. The LLD layer provides abstraction for these hardware modules. The PWM APP uses CCU4 or CCU8, SCU and GPIO LLDs and other dependent APPS like GLOBAL_CCUx (x =4, 8) and CLOCK_XMCx (x =4, 1) for the functionality.Limitations

  • This APP does not support coherent update of multiple channels (i.e. multiple instances of the APP). For this purpose, please use the functions available in CCU4/8 LLD.
  • Currently, in the PWM APP, API: PWM_SetFreq allows the user to set frequency for the appropriate prescaler value to be used. However, PSIV value is updated immediately and not during period match. Due to this, if the frequency requires the prescaler to be changed, there is a cycle (1 pulse) where the on/off time is different.
    Figure 3 : Limitation of the PWM APP
Supported Devices
The APP supports below devices:

  1. XMC4800 / XMC4700 Series
  2. XMC4500 Series
  3. XMC4400 Series
  4. XMC4200 / XMC4100 Series
  5. XMC1400 Series
  6. XMC1300 Series
  7. XMC1200 Series
  8. XMC1100 Series
Reference

  1. XMC4800 / XMC4700 Reference Manual
  2. XMC4500 Reference Manual
  3. XMC4400 Reference Manual
  4. XMC4200 / XMC4100 Reference Manual
  5. XMC1400 Reference Manual
  6. XMC1300 Reference Manual
  7. XMC1200 Reference Manual
  8. XMC1100 Reference Manual


PWM: Methods

PWM
Methods
DAVE_APP_VERSION_t | PWM_GetAppVersion (void)
 | Get PWM APP version. More...
PWM_STATUS_t | PWM_Init (PWM_t *const handle_ptr)
 | Initializes the PWM APP. More...
void | PWM_Start (PWM_t *const handle_ptr)
 | Starts the PWM generation. More...
void | PWM_Stop (PWM_t *const handle_ptr)
 | Stops the PWM generation. More...
PWM_STATUS_t | PWM_SetFreq (PWM_t *const handle_ptr, uint32_t pwm_freq_hz)
 | Configures the PWM Frequency. More...
PWM_STATUS_t | PWM_SetFreqAndDutyCycle (PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle)
 | Configures the PWM Frequency and duty cycle. More...
void | PWM_ClearEvent (PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
 | Clears the PWM related interrupt. More...
bool | PWM_GetInterruptStatus (PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt)
 | Gets the corresponding interrupt status. More...
bool | PWM_GetTimerStatus (PWM_t *const handle_ptr)
 | Gets the corresponding timer status. More...
PWM_STATUS_t | PWM_SetDutyCycle (PWM_t *const handle_ptr, uint32_t duty_cycle)
 | Configure the PWM duty cycle. More...
void | PWM_SetPassiveLevel (PWM_t *const handle_ptr, PWM_OUTPUT_PASSIVE_LEVEL_t pwm_output_passive_level)
 | Configure the passive level of the PWM output waveform. More...
PWM_STATUS_t | PWM_SetPeriodMatchValue (PWM_t *const handle_ptr, uint32_t period_match_value)
 | Loads the required period match value. More...

Detailed Description

Methods

Function Documentation

void PWM_ClearEvent | ( | PWM_t *const | handle_ptr,
 |  | PWM_INTERRUPT_t | pwm_interrupt
 | ) |  |

Clears the PWM related interrupt.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
pwm_interrupt | Interrupt to acknowledge.
Returns
void
Description:
Clears the CCUx related interrupt. When an interrupt occurs it must be acknowledged by clearing the respective flag in the hardware. Clears the interrupt type PWM_INTERRUPT_t.
// Drag 2 INTERRUPT APPs into the project. In the PWM APPs UI editor enable compare match event and period
// match event. Goto the Signal connectivity window and connect the event_compare_match and event_period_match to
// the 2 different INTERRUPT APPs. Give the handler for the compare match interrupt as PWM_compare_match_interrupt
// and the handler for the period match interrupt as PWM_period_match_interrupt
#include "DAVE.h"
uint32_t period_count;
void PWM_period_match_interrupt(void)
{
static uint32_t frequency = 1000; //start frequency 1Khz
PWM_ClearEvent(&PWM_0, PWM_INTERRUPT_PERIODMATCH);
period_count++;
if (period_count == 35000) // wait to get 40K pwm cycles then increment the frequency by 2kHz
{
frequency += 2000;
PWM_SetFreq(&PWM_0, frequency);
period_count = 0;
if (frequency > 30000000)
{
frequency = 1000;
}
}
}
void PWM_compare_match_interrupt(void)
{
PWM_ClearEvent(&PWM_0, PWM_INTERRUPT_COMPAREMATCH);
}
int main(void)
{
DAVE_Init();
PWM_Start(&PWM_0);
while(1);
return 0;
}

Definition at line 943 of file PWM.c.

References PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_slice_ptr, and PWM_HandleType::timer_type.

DAVE_APP_VERSION_t PWM_GetAppVersion ( void )

Get PWM APP version.

Returns
DAVE_APP_VERSION_t APP version information (major, minor and patch number)
Description:
The function can be used to check application software compatibility with a specific version of the APP.

Example Usage:

#include "DAVE.h"
int main(void)
{
DAVE_STATUS_t init_status;
DAVE_APP_VERSION_t version;
// Initialize PWM APP:
// PWM_Init() is called from within DAVE_Init().
init_status = DAVE_Init();
version = PWM_GetAppVersion();
if (version.major != 1U)
{
// Probably, not the right version.
}
// More code here
while(1) {
}
return (0);
}

Definition at line 734 of file PWM.c.

bool PWM_GetInterruptStatus | ( | PWM_t *const | handle_ptr,
 |  | PWM_INTERRUPT_t | pwm_interrupt
 | ) |  |

Gets the corresponding interrupt status.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
pwm_interrupt | Interrupt to get status.
Returns
bool returns true if the pwm_interrupt has occured else returns false.
Description:
Returns the status of the corresponding interrupt. Reads the appropriate flag and would return true if the event was asserted.
// Drag 1 INTERRUPT APP into the project. In the PWM APPs UI editor enable compare match event and period
// match event. Goto the Signal connectivity window and connect the event_compare_match and event_period_match to
// the same INTERRUPT APP and give the handler as PWM_compare_period_match_interrupt.
#include "DAVE.h"
uint32_t period_count;
void PWM_compare_period_match_interrupt(void)
{
if (PWM_GetInterruptStatus(&PWM_0, PWM_INTERRUPT_PERIODMATCH))
{
PWM_Stop(&PWM_0); // A single shot PWM generated
}
PWM_ClearEvent(&PWM_0, PWM_INTERRUPT_COMPAREMATCH);
}
int main(void)
{
DAVE_Init();
PWM_Start(&PWM_0);
while(1);
return 0;
}

Definition at line 917 of file PWM.c.

References PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_slice_ptr, and PWM_HandleType::timer_type.

bool PWM_GetTimerStatus ( PWM_t *const handle_ptr )

Gets the corresponding timer status.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
bool
returns true if timer is running , false if the timer is idle.
Description:
Returns the state of the timer. Would return a false if the timer is not running. A call to this API results in invalid outputs if invoked before PWM_Init().
#include "DAVE.h"
int main(void)
{
DAVE_Init();
if (PWM_GetTimerStatus(&PWM_0))
{
PWM_Stop(&PWM_0);
}
while(1);
return 0;
}

Definition at line 891 of file PWM.c.

References PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_slice_ptr, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_Init ( PWM_t *const handle_ptr )

Initializes the PWM APP.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
PWM_STATUS_t status of the initialization.
Description:
Initializes the PWM APP. This initializes the CCUx slice to compare mode of operation. Configures required events, GPIO pin as output. It will configure CCU4 or CCU8 slice registers with the selected PWM parameters. If PWM generation is set to start after initialization then after the CCUx related initialization is completed the PWM output will start.
#include "DAVE.h"
int main(void)
{
DAVE_Init(); //PWM_Init() is called by DAVE_Init().
while(1);
return 0;
}

Definition at line 747 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetDutyCycle | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | duty_cycle
 | ) |  |

Configure the PWM duty cycle.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
duty_cycle Duty cycle in percentage.
The values are scaled by a factor of 100.
Range: [0(d) to 10000(d)] Where 1(d) represents 0.01% duty cycle
10000(d) represents 100% duty cycle
Returns
Returns PWM_STATUS_FAILURE if the duty_cycle exceeds the valid range.
Description:
Configure the PWM duty cycle by changing the compare match values. The API would configure the duty cycle for the given frequency. The duty_cycle is a scaled parameter where a single value change would result in a 0.01% change.
Note:
This is a fixed point implementation. It is expected that there are resolution losses due to scaling in the API. At higher frequencies it may not be possible to achieve the required duty cycle due to the hardware limitation.
#include "DAVE.h"
int main(void)
{
uint32_t Counter;
DAVE_Init();
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to 60.00%
if (PWM_SetDutyCycle(&PWM_0, 6000))
{
while(1);
}
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to 54.26%
if (PWM_SetDutyCycle(&PWM_0, 5426))
{
while(1);
}
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to an invalid duty 100.26%
if (PWM_SetDutyCycle(&PWM_0, 10026))
{
while(1);
}
while(1);
return 0;
}

Definition at line 816 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetFreq | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | pwm_freq_hz
 | ) |  |

Configures the PWM Frequency.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
PwmFreqHz Frequency value in Hz.
Range: [1(d) to 60000000(d)]
Returns
PWM_STATUS_t Would return PWM_STATUS_FAILURE if the PwmFreqHz exceeded the maximum frequency achievable.
Description:
Configures the frequency of the PWM signal. The PWM duty cycle remains unchanged. Calculates the least possible resolution(Prescaler) of the CCUx Timer. Using this Prescaler it would calculate the value for the period register and the compare register. Adjusts the compare match value according to the frequency and the existing duty cycle.
#include "DAVE.h"
int main(void)
{
PWM_STATUS_t pwm_setfreq_status;
DAVE_Init();
// Change duty cycle value to 20%.
PWM_SetDutyCycle(&PWM_0, 2000);
// Change PWM frequency to 100kHz
pwm_setfreq_status = PWM_SetFreq(&PWM_0,100000);
if (PWM_STATUS_FAILURE == pwm_setfreq_status)
{
// frequency couldn't be set
while(1);
}
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change duty cycle value to 60%.
PWM_SetDutyCycle(&PWM_0, 6000);
while(1);
return 0;
}

Definition at line 841 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetFreqAndDutyCycle | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | pwm_freq_hz,
 |  | uint32_t | duty_cycle
 | ) |  |

Configures the PWM Frequency and duty cycle.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
PwmFreqHz Frequency value in Hz.
Range: [1(d) to 60000000(d)]
duty_cycle Duty cycle in percentage.
The values are scaled by a factor of 100.
Range: [0(d) to 10000(d)] Where 1(d) represents 0.01% duty cycle
10000(d) represents 100% duty cycle
Returns
Return PWM_STATUS_FAILURE if the PwmFreqHz exceeded the maximum frequency achievable.
Description:
Configures the frequency and duty cycle together. Calculates the least possible resolution(Prescaler) of the CCUx Timer. Using this Prescaler it would calculate the value for the period register. Using the duty_cycle the compare register values would be calculated.
Note:
This is a fixed point implementation for duty cycle. It is expected that there are resolution losses due to scaling of the duty cycle in the API. At higher frequencies it may not be possible to achieve the required duty cycle due to the hardware limitation. If the input frequency to the API is very high (> 30MHz) due to integer divisions, the desired frequency might not be set.
#include "DAVE.h"
int main(void)
{
PWM_STATUS_t pwm_setfreq_status;
DAVE_Init();
// Change duty cycle value to 90.90%.
PWM_SetDutyCycle(&PWM_0, 9090);
// Wait to observe the waveform
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
// Change PWM frequency to 100kHz and duty to 20%
pwm_setfreq_status = PWM_SetFreqAndDutyCycle(&PWM_0,100000,2000);
if (PWM_STATUS_FAILURE == pwm_setfreq_status)
{
// frequency couldn't be set
while(1);
}
while(1);
return 0;
}

Definition at line 866 of file PWM.c.

References PWM_STATUS_FAILURE, and PWM_HandleType::timer_type.

void PWM_SetPassiveLevel | ( | PWM_t *const | handle_ptr,
 |  | PWM_OUTPUT_PASSIVE_LEVEL_t | pwm_output_passive_level
 | ) |  |

Configure the passive level of the PWM output waveform.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
pwm_output_passive_level | Passive level LOW or HIGH.
Returns
void
Description:
Configure the passive level for the PWM signal. If ::PWM_OutputPassiveLevelType::PWM_OUTPUT_PASSIVE_LEVEL_HIGH is selected the output of the PWM will be high before the compare match occurs after that it would be set to low. If ::PWM_OutputPassiveLevelType::PWM_OUTPUT_PASSIVE_LEVEL_LOW is selected the output of the PWM will be low before the compare match occurs after that it would be set to high.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPassiveLevel(&PWM_0, PWM_OUTPUT_PASSIVE_LEVEL_HIGH);
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPassiveLevel(&PWM_0, PWM_OUTPUT_PASSIVE_LEVEL_LOW);
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
while(1);
return 0;
}

Definition at line 964 of file PWM.c.

References PWM_HandleType::ccu4_kernel_ptr, PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_kernel_ptr, PWM_HandleType::ccu8_slice_ptr, PWM_HandleType::shadow_mask, and PWM_HandleType::timer_type.

PWM_STATUS_t PWM_SetPeriodMatchValue | ( | PWM_t *const | handle_ptr,
 |  | uint32_t | period_match_value
 | ) |  |

Loads the required period match value.

Parameters
handle_ptr | Constant pointer to the handle structure PWM_t
period_match_value | value which needs to be loaded into the period register. Range: [0x0 to 0xFFFF]
Returns
void
Description:
Configures or loads the required period value into the period register. This API would also calculate the compare register value (w.r.t period_match_value ) to maintain the duty cycle.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
PWM_SetFreq(&PWM_0, 1U);// Set the required frequency as 1Hz
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPeriodMatchValue(&PWM_0, PWM_0.period_value / 2); // 2Hz
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
PWM_SetPeriodMatchValue(&PWM_0, PWM_0.period_value * 2); // 1Hz
for (uint32_t counter = 0; counter <= 0xFFFF; ++counter)
{
__NOP();
}
while(1);
return 0;
}

Definition at line 995 of file PWM.c.

References PWM_HandleType::ccu4_kernel_ptr, PWM_HandleType::ccu4_slice_ptr, PWM_HandleType::ccu8_kernel_ptr, PWM_HandleType::ccu8_slice_ptr, PWM_HandleType::compare_value, PWM_HandleType::duty_cycle, PWM_HandleType::period_value, PWM_STATUS_FAILURE, PWM_STATUS_SUCCESS, PWM_HandleType::shadow_mask, PWM_HandleType::state, and PWM_HandleType::timer_type.

void PWM_Start ( PWM_t *const handle_ptr )

Starts the PWM generation.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
void
Description:
Start the selected PWM generation. It is needed to be called if "Start after initialization" is unchecked in the UI. Enables the clock for the CCUx slice and also starts the timer operation. Invoke this API only after initialization and when the timer is not running. If invoked outside these conditions, the API will have no effect.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
//This needs to be called if "Start after initialization" is unchecked
if (!PWM_GetTimerStatus(&PWM_0))
{
PWM_Start(&PWM_0);
}
while(1);
return 0;
}

Definition at line 773 of file PWM.c.

References PWM_HandleType::timer_type.

void PWM_Stop ( PWM_t *const handle_ptr )

Stops the PWM generation.

Parameters
handle_ptr Constant pointer to the handle structure PWM_t
Returns
void
Description:
Stop the selected PWM generation. Disables the clock for the CCUx slice and also stops the timer operation. Invoke this API only after initialization and when the timer is running. If invoked outside these conditions, the API will have no effect.
#include "DAVE.h"
int main(void)
{
DAVE_Init();
if (PWM_GetTimerStatus(&PWM_0))
{
PWM_Stop(&PWM_0);
}
while(1);
return 0;
}

Definition at line 794 of file PWM.c.

References PWM_HandleType::timer_type.


PWM: Data structures

PWM
Data Structures
Data structures

Data Structures

struct | PWM_HandleType
Initialization parameters of the PWM App. More...
typedef struct PWM_HandleType | PWM_t
Initialization parameters of the PWM App.

Detailed Description


PWM: Enumerations

PWM
Enumerations
enum | PWM_TIMER_SLICE
 | The type identifies the CCU4 or CCU8 timer selected.
enum | PWM_TIMER_STATUS
 | The type identifies the timer status.
enum | PWM_INTERRUPT { PWM_INTERRUPT_PERIODMATCH = 0U, PWM_INTERRUPT_COMPAREMATCH = 2U }
 | The type identifies the timer interrupts. More...
enum | PWM_OUTPUT_PASSIVE_LEVEL { PWM_OUTPUT_PASSIVE_LEVEL_LOW = 0, PWM_OUTPUT_PASSIVE_LEVEL_HIGH }
 | The type identifies the timer interrupts. More...
enum | PWM_STATUS { PWM_STATUS_SUCCESS = 0, PWM_STATUS_FAILURE, PWM_STATUS_UNINITIALIZED, PWM_STATUS_RUNNING, PWM_STATUS_STOPPED }
 | The type identifies App state. More...
enum | PWM_ERROR_CODES { PWM_OPER_NOT_ALLOWED_ERROR = 1, PWM_INVALID_PARAM_ERROR }
 | The type identifies the App Error Codes. More...
typedef enum PWM_TIMER_SLICE | PWM_TIMER_SLICE_t
 | The type identifies the CCU4 or CCU8 timer selected.
typedef enum PWM_TIMER_STATUS | PWM_TIMER_STATUS_t
 | The type identifies the timer status.
typedef enum PWM_INTERRUPT | PWM_INTERRUPT_t
 | The type identifies the timer interrupts.
typedef enum PWM_OUTPUT_PASSIVE_LEVEL | PWM_OUTPUT_PASSIVE_LEVEL_t
 | The type identifies the timer interrupts.
typedef enum PWM_STATUS | PWM_STATUS_t
 | The type identifies App state.
typedef enum PWM_ERROR_CODES | PWM_ERROR_CODES_t
 | The type identifies the App Error Codes.

Detailed Description

Enumeration Type Documentation

enum PWM_ERROR_CODES

The type identifies the App Error Codes.

Enumerator
PWM_OPER_NOT_ALLOWED_ERROR | if the current API operation is not possible in the given state
PWM_INVALID_PARAM_ERROR | the parameters passed to an API are invalid

Definition at line 164 of file PWM.h.

enum PWM_INTERRUPT

The type identifies the timer interrupts.

Enumerator
PWM_INTERRUPT_PERIODMATCH | Period match interrupt while counting up
PWM_INTERRUPT_COMPAREMATCH | Compare match interrupt while counting up

Definition at line 133 of file PWM.h.

enum PWM_OUTPUT_PASSIVE_LEVEL

The type identifies the timer interrupts.

Enumerator
PWM_OUTPUT_PASSIVE_LEVEL_LOW | Passive level = Low
PWM_OUTPUT_PASSIVE_LEVEL_HIGH | Passive level = High

Definition at line 142 of file PWM.h.

enum PWM_STATUS

The type identifies App state.

Enumerator
PWM_STATUS_SUCCESS | APP is initialized as per selected parameters
PWM_STATUS_FAILURE | APP initialization function failure
PWM_STATUS_UNINITIALIZED | default state after power on reset
PWM_STATUS_RUNNING | CCU slice is running in PWM mode
PWM_STATUS_STOPPED | CCU slice timer is stopped

Definition at line 152 of file PWM.h.


PWM: Usage

PWM
Usage

Usage

The PWM APP is typically used just for a simple Pulse Width Modulation output generation.
This example demonstrates the brightness control of a LED (Light Emitting Diode) using PWM duty cycle.

Instantiate the required APPs
Drag an instance of PWM APP and INTERRUPT APP. Update the fields in the GUI of these APPs with the following configuration.
Configure the APPs
PWM APP:

  1. Set frequency as 40Hz.
  2. Goto the Events Tab.
  3. Enable compare match event.
INTERRUPT APP:

  4. Check the Enable interrupt at initialization.
  5. Provide the interrupt handler as "compare_match_handler".
Signal Connection
Establish a HW signal connection between the PWM and the INTERRUPT APP to ensure PWM events generates interrupts.

  6. Connect PWM_0/event_compare_match -> INTERRUPT_0/sr_irq to ensure assigning ISR node to the compare match event.
Manual pin allocation

  7. Select the LED Pin present in the boot kit
    Note:The pin number is specific to the development board chosen to run this example. The pin shown in the image above may not be available on every XMC kit. Ensure that a proper pin is selected according to the board.

Generate code
Files are generated here: '<project_name>/Dave/Generated/' ('project_name' is the name chosen by the user during project creation). APP instance definitions and APIs are generated only after code generation.

  • Note: Code must be explicitly generated for every change in the GUI configuration.
    Important: Any manual modification to APP specific files will be overwritten by a subsequent code generation operation.

Sample Application (main.c)

#include "DAVE.h"
// Add the following function in main.c
void compare_match_handler(void)
{
static uint32_t duty = (uint32_t)100;
static bool decrement_duty = (bool)false;
if (decrement_duty != false)
{
//Decrement the duty cycle until it reaches 1%
duty -= (uint32_t)100;
// Once the duty has reached 1% flag status is changed to Increment
if (duty <= (uint32_t)100)
{
decrement_duty = false;
}
}
else
{
// Increment the duty cycle until it reaches 100%
duty += (uint32_t)100;
// Once the duty has reached 100% flag status is changed to decrement
if (duty >= (uint32_t)10000)
{
decrement_duty = true;
}
}
// Sets the duty cycle of the PWM
PWM_SetDutyCycle(&PWM_0,duty);
// Clear the compare match interrupt.
PWM_ClearEvent(&PWM_0,PWM_INTERRUPT_COMPAREMATCH );
}
int main(void)
{
DAVE_STATUS_t status;
status = DAVE_Init(); /* Initialization of DAVE Apps */
if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler */
XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
while(1U)
{
}
}
PWM_Start(&PWM_0);
while(1U);
return 1;
}
Build and Run the Project
Observation
The LED brightness will gradually decrease and then increase. The brightness variation cycle will occur repeatedly.


PWM: APP Configuration Parameters

PWM
APP Configuration Parameters

App Configuration Parameters

Figure 1: General Settings

Figure 2: Event Settings

Figure 3: Pin Settings


PWM: Release History

PWM
Release History

Release History


PWM: Main Page

PWM
PWM Documentation

Index

License Terms and Copyright Information
Abbreviations and Definitions
Overview
Architecture Description
APP Configuration Parameters
Enumerations
Data structures
Methods
Usage

Release History


PWM: Apps

PWM
Apps
Here is a list of all modules:
o License Terms and Copyright Information
o Abbreviations and Definitions
o Overview
o Architecture Description
o APP Configuration Parameters
o Enumerations
o Data structures
o Methods
o Usage
\ Release History


Control Name Range/Items Description
Passive level Low
High
         Select the polarity of the PWM signal.
  • Low: Select this option to make the PWM have a low output untill compare value is reached. After the compare value the signal will be High.
  • High: Select this option to make the PWM have a high output untill compare value is reached. After the compare value the signal will be low.
    • Note: This option is useful when the user wants to generate a inverted PWM output.
Mode Push Pull
Open Drain
         Selects the Output pin characteristics.
  • Push Pull: Can drive both low and high voltages. No external pull up needed.
  • Open Drain: Can drive only low voltage. Needs an external pull up resistor.
Driver strength Weak Driver
Medium Driver
Strong Driver Soft Edge
Strong Driver Slow Edge
Strong Driver Sharp Edge
Strong Driver Medium Edge

Select output pad driver strength.
  • Selecting the appropriate driver strength allows to optimize the outputs for the needed interface performance.
  • Can help to reduce power consumption, and limits noise, crosstalk and electromagnetic emissions.


APP Version | Date | Change Description
4.0.0 | 16-Feb-2015 | Initial version for DAVEv4
4.1.2 | 06-Apr-2015 | 1.Configuration structure modified of PWM_t. 2.Removed PWM_Dynamic_t,PWM_ConfigType_t. 3.Added New macros for Mixed usage. 4.Added New API PWM_SetPeriodMatchValue(). 5.Modified enumeration PWM_InterruptType_t to PWM_INTERRUPT_t. 6.Modified enumeration PWM_OutputPassiveLevelType_t to PWM_OUTPUT_PASSIVE_LEVEL_t. 7.Modified enumeration PWM_TIMER_TYPE_t to PWM_TIMER_SLICE_t . 8.PWM_ClearEvent(), PWM_GetInterruptStatus() and PWM_SetPassiveLevel() API prototype modified for the new enum. 9.API name change PWM_AcknowledgeInterrupt to PWM_ClearEvent.
4.1.4 | 09-Jul-2015 | Documentation updated.
4.1.5 | 01-Sep-2015 | XMC14 device support added.
4.1.6 | 08-Oct-2015 | Added support for XMC4700/XMC4800 devices.
4.1.8 | 16-Dec-2015 | Added support for XMC4300 devices.
4.1.10 | 28-Jul-2016 | All event signals are made mandatory.
4.1.12 | 09-Jan-2021 | Modified check for minimum XMCLib version.