PWM driver implementation using MSP432 Timer_A peripherals.
The PWM header file should be included in an application as follows:
This driver configures a MSP432 Timer_A peripheral for PWM. If the timer is already in use (by the kernel for instance), PWM instances will not be opened.
When used for PWM generation, each Timer_A can produce up to 6 PWM outputs and this driver manages each output as an independent PWM instance. However since a single period, prescalar, and clock source are used for all PWM outputs, there are limitations in place to ensure proper operation:
The timer is automatically configured in count-up mode using the clock source specified in the hwAttrs structure. In PWM mode, the timer capture/compare register 0 is used as the period register and cannot be used to generate a PWM output.
The period and duty registers are 16 bits wide, thus a prescalar is used to divide the input clock and allow for larger periods. The maximum period supported is calculated as:
After opening, the PWM_setPeriod() API can be used to change the PWM period. Keep in mind the period is shared by all other PWMs on the timer, so all other PWM outputs on the timer will change.
In order to use the PWM APIs, the application is required to define 4 configuration items in the application Board.c file:
Allocation of each timer peripheral is managed through a set of resource allocation APIs. For example, the TimerMSP432_allocateTimerResource API will allocate a timer for exclusive use. Any attempt to allocate this resource in the future will result in a false value being returned from the allocation API. To free a timer resource, the TimerMSP432_freeTimerResource is used. The application is not responsible for calling these allocation APIs directly.
The TI-RTOS power management framework will try to put the device into the most power efficient mode whenever possible. Please see the technical reference manual for further details on each power mode.
This driver supports dynamic power performance levels. The driver will determine which power performance levels are compatible with the desired period and period units. The driver prevents transitions to performance levels in which the period cannot be generated. When PWM_setPeriod() is called, the compatible performance levels are re-calculated and set.
After a performance level change, the period is recalculated such that the generated period will remain the same. The duty cycle is not recalculated. The application is responsible for calling PWM_setDuty() after a performance level change. The exact period may vary after a performance level transition. This is due to a change in clock frequency and hence period per clock cycle.
The following statements are valid:
#include <stdbool.h>
#include <ti/devices/DeviceFamily.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/PWM.h>
#include <ti/devices/msp432p4xx/driverlib/pmap.h>
#include <ti/devices/msp432p4xx/driverlib/timer_a.h>
Go to the source code of this file.
Data Structures | |
struct | PWMTimerMSP432_HWAttrsV2 |
PWMTimerMSP432 Hardware attributes. More... | |
struct | PWMTimerMSP432_Status |
PWMTimerMSP432_Status. More... | |
struct | PWMTimerMSP432_Object |
PWMTimerMSP432 Object. More... | |
Typedefs | |
typedef struct PWMTimerMSP432_HWAttrsV2 | PWMTimerMSP432_HWAttrsV2 |
PWMTimerMSP432 Hardware attributes. More... | |
typedef struct PWMTimerMSP432_Status | PWMTimerMSP432_Status |
PWMTimerMSP432_Status. More... | |
typedef struct PWMTimerMSP432_Object | PWMTimerMSP432_Object |
PWMTimerMSP432 Object. More... | |
Variables | |
const PWM_FxnTable | PWMTimerMSP432_fxnTable |
typedef struct PWMTimerMSP432_HWAttrsV2 PWMTimerMSP432_HWAttrsV2 |
PWMTimerMSP432 Hardware attributes.
The 'clockSource' field is used by driverlib APIs and therefore must be populated by driverlib macro definitions. For msp432_driverlib these definitions are found in:
The 'pwmPin' field identifies which physical pin as well as which timer compare register to use for a particular PWM channel. The encoded pin identifier for initializing the 'pwmPin' field must be selected from the PWMTimerMSP432_HWAttrs 'pwmPin' field options macros.
A sample structure is shown below:
typedef struct PWMTimerMSP432_Status PWMTimerMSP432_Status |
The application must not access any member variables of this structure!
typedef struct PWMTimerMSP432_Object PWMTimerMSP432_Object |
PWMTimerMSP432 Object.
The application must not access any member variables of this structure!
const PWM_FxnTable PWMTimerMSP432_fxnTable |