TI-RTOS Drivers  tidrivers_tivac_2_16_00_08
Data Structures | Macros | Typedefs | Variables
PWMTiva.h File Reference

Detailed Description

PWM driver implementation for Tiva PWM perhiperals.

============================================================================

The PWM header file should be included in an application as follows:

Refer to PWM.h for a complete description of APIs & example of use.

Operation

This driver implementation uses the Pulse Width Modulator (PWM) peripherals present on Tiva devices to generate PWM signals. Each PWM peripheral instance contains 4 PWM signal generators, each controling 2 PWM outputs (8 PWM outputs total). This driver manages each PWM output individually (each output has it's own PWM handle/instance). However since a single clock prescalar is available for a peripheral and a generator is responsable for producing 2 outputs, there are some limitations in place to ensure proper operation:

  1. The peripheral prescalar will be set according to the period of the first PWM instance opened. Any subsequent outputs will fail to open if a greater prescalar is required to generate the PWM period.
  2. A PWM generators period is set to the period of the instance opened. Opening the second output will fail if the period used is not the same as what was set by the first output.
  3. A PWM generators options are set by the first instance opened. Opening the second output will fail if the options are not the same as what was set by the first output.

Since the period and duty registers are 16 bits wide the prescalar is used to divide the input clock and allow for larger periods. The maximum period supported is calculated as: MAX_PERIOD = (MAX_PRESCALAR * MAX_MATCH_VALUE) / CYCLES_PER_US 80 MHz clock: (64 * 65535) / 80 = 52428 microseconds 120 MHz clock: (64 * 65535) / 120 = 34952 microseconds

After opening, the PWM_control() API can be used to change a PWM generator period. However, the clock prescalar is shared by all generators so the new period must be a value that can generated with the same prescaler. Also keep in mind that changing a period affects both generator outputs. The equation below can be used to determine the prescalar for a given period: The prescalar will be the following power of 2 number (2^x): prescalar = (period * CYCLES_PER_US) / MAX_MATCH_VALUE 100 microseconds = (100 * 80) / 65535 = (0.1220) = 1 10000 microseconds = (10000 * 80) / 65535 = (12.20) = 16

Below is an example of how to use the PWM_control() API to change a period:

#include <driverlib/pwm.h>
int rc = 0;
int newPeriod = 2000;
rc = PWM_control(pwmHandle, PWMTiva_CHANGE_GEN_PERIOD, &newPeriod);
if (rc < 0) {
// handle error condition
}

Finally, if the duty supplied is greater than the period; the output will remain in active state.


#include <ti/drivers/PWM.h>
Include dependency graph for PWMTiva.h:

Go to the source code of this file.

Data Structures

struct  PWMTiva_HWAttrs
 PWMTiva Hardware attributes. More...
 
struct  PWMTiva_Status
 PWMTiva_Status. More...
 
struct  PWMTiva_Object
 PWMTiva Object. More...
 

Macros

#define PWMTiva_CMD_CHANGE_GEN_PERIOD   PWM_CMD_RESERVED + 0
 Control command to change the PWM period. More...
 
#define PWMTiva_CHANGE_GEN_PERIOD   PWMTiva_CMD_CHANGE_GEN_PERIOD
 
#define PWMTiva_NUM_PWM_PERIPHERALS   2
 
#define PWMTiva_NUM_PWM_GENERATORS   4
 

Typedefs

typedef struct PWMTiva_HWAttrs PWMTiva_HWAttrs
 PWMTiva Hardware attributes. More...
 
typedef struct PWMTiva_Status PWMTiva_Status
 PWMTiva_Status. More...
 
typedef struct PWMTiva_Object PWMTiva_Object
 PWMTiva Object. More...
 

Variables

const PWM_FxnTable PWMTiva_fxnTable
 

Macro Definition Documentation

#define PWMTiva_CHANGE_GEN_PERIOD   PWMTiva_CMD_CHANGE_GEN_PERIOD
#define PWMTiva_NUM_PWM_PERIPHERALS   2
#define PWMTiva_NUM_PWM_GENERATORS   4

Typedef Documentation

PWMTiva Hardware attributes.

These fields are used by driverlib APIs and therefore must be populated by driverlib macro definitions. For TivaWare these definitions are found in:

  • driverlib/pwm.h

A sample structure is shown below:

1 const PWMTiva_HWAttrs PWMTivaHWAttrs[] = {
2  {
3  .baseAddr = PWM0_BASE,
4  .pwmOutput = PWM_OUT_0,
5  .pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
6  }
7 };

PWMTiva_Status.

The application must not access any member variables of this structure!

PWMTiva Object.

The application must not access any member variables of this structure!

Variable Documentation

const PWM_FxnTable PWMTiva_fxnTable
Copyright 2016, Texas Instruments Incorporated