PWMTimerCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @file PWMTimerCC26XX.h
34  * @brief PWM driver implementation for CC26XX/CC13XX
35  *
36  * # Overview #
37  * The general PWM API should be used in application code, i.e. PWM_open()
38  * should be used instead of PWMTimerCC26XX_open(). The board file will define the device
39  * specific config, and casting in the general API will ensure that the correct
40  * device specific functions are called.
41  *
42  * # General Behavior #
43  * Before using PWM on CC26XX:
44  * - The Timer HW is configured and system dependencies (for example IOs,
45  * power, etc.) are set by calling PWM_open().
46  *
47  * # Error handling #
48  * If unsupported arguments are provided to an API returning an error code, the
49  * PWM configuration will *not* be updated and PWM will stay in the mode it
50  * was already configured to.
51  *
52  * # Power Management #
53  * The TI-RTOS power management framework will try to put the device into the most
54  * power efficient mode whenever possible. Please see the technical reference
55  * manual for further details on each power mode.
56  *
57  * The PWMTimerCC26XX.h driver is not explicitly setting a power constraint when the
58  * PWM is running to prevent standby as this is assumed to be done in the
59  * underlying GPTimer driver.
60  * The following statements are valid:
61  * - After PWM_open(): The device is still allowed to enter Standby. When the
62  * device is active the underlying GPTimer peripheral will
63  * be enabled and clocked.
64  * - After PWM_start(): The device can only go to Idle power mode since the
65  * high-frequency clock is needed for PWM operation:
66  * - After PWM_stop(): Conditions are equal as for after PWM_open
67  * - After PWM_close(): The underlying GPTimer is turned off and the device
68  * is allowed to go to standby.
69  *
70  * # Accuracy #
71  * The PWM output period and duty cycle are limited by the underlying timer.
72  * In PWM mode the timer is effectively 24 bits which results in a minimum
73  * frequency of 48MHz / (2^24-1) = 2.86Hz (349.525ms)
74  * The driver will round off the configured duty and period to a value limited
75  * by the timer resolution and the application is responsible for selecting
76  * duty and period that works with the underlying timer if high accuracy is
77  * needed.
78  * The effect of this is most visible when using high output frequencies as the
79  * available duty cycle resolution is reduced correspondingly. For a 24MHz PWM
80  * only a 0%/50%/100% duty is available as the timer uses only counts 0 and 1.
81  * Similarly for a 12MHz period the duty cycle will be limited to a 12.5%
82  * resolution.
83  * The PWM signals are generated using the high-frequency clock as source.
84  *
85  * If very high-accuracy outputs are needed, the application should request
86  * using the external HF crystal:
87  * @code
88  * #include <ti/sysbios/family/arm/cc26xx/Power.h>
89  * #include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
90  * Power_setDependency(XOSC_HF);
91  * @endcode
92  *
93  * # Limitations #
94  * - The PWM output can currently not be synchronized with other PWM outputs
95  * - The PWM driver does not support updating duty and period using DMA.
96  * - When changing duty cycle there will be a period where the high level is
97  * either too short or too high since the timer match value is updated.
98  * # PWM usage #
99  *
100  * ## Basic PWM output ##
101  * The below example will output a 8MHz PWM signal with 50% duty cycle.
102  * @code
103  * PWM_Handle pwmHandle;
104  * PWM_Params params;
105  *
106  * PWM_Params_init(&params);
107  * params.idleLevel = PWM_IDLE_LOW;
108  * params.periodUnits = PWM_PERIOD_HZ;
109  * params.periodValue = 8e6;
110  * params.dutyUnits = PWM_DUTY_FRACTION;
111  * params.dutyValue = PWM_DUTY_FRACTION_MAX / 2;
112  *
113  * pwmHandle = PWM_open(Board_PWM0, &params);
114  * if(pwmHandle == NULL) {
115  * Log_error0("Failed to open PWM");
116  * Task_exit();
117  * }
118  * PWM_start(pwmHandle);
119  * @endcode
120  *
121  *
122  *******************************************************************************
123  */
124 #ifndef ti_drivers_pwm__PWMTimerCC26XX_include
125 #define ti_drivers_pwm__PWMTimerCC26XX_include
126 
127 #ifdef __cplusplus
128 extern "C" {
129 #endif
130 
131 #include <stdint.h>
132 #include <stdbool.h>
133 
134 #include <ti/drivers/PIN.h>
135 #include <ti/drivers/PWM.h>
137 
138 
147 #define PWMTimerCC26XX_CMD_DEBUG_STALL PWM_CMD_RESERVED + 0
152 #define CMD_ARG_DEBUG_STALL_OFF (uint32_t)GPTimerCC26XX_DEBUG_STALL_OFF
153 #define CMD_ARG_DEBUG_STALL_ON (uint32_t)GPTimerCC26XX_DEBUG_STALL_ON
154 /* @} */
155 
156 /* @} */
157 
158 /* PWM function table pointer */
160 
182 {
184  uint8_t gpTimerUnit;
186 
201 typedef struct PWMTimerCC26XX_Object
202 {
203  bool isOpen;
205  uint32_t periodValue;
206  uint32_t periodCounts;
208  uint32_t dutyValue;
209  uint32_t dutyCounts;
213 
214 #ifdef __cplusplus
215 }
216 #endif
217 #endif /* ti_driver_pwm_PWMTimerCC26XX_include */
uint8_t PIN_Id
Pin identifier data type.
Definition: PIN.h:577
PWM_IdleLevel idleLevel
Definition: PWMTimerCC26XX.h:210
bool isOpen
Definition: PWMTimerCC26XX.h:203
GPTimer driver implementation for CC26XX/CC13XX.
PWM_Period_Units periodUnit
Definition: PWMTimerCC26XX.h:204
PWMTimer26XX Object.
Definition: PWMTimerCC26XX.h:201
uint32_t periodCounts
Definition: PWMTimerCC26XX.h:206
uint32_t dutyValue
Definition: PWMTimerCC26XX.h:208
PWM driver interface.
PWMTimer26XX Hardware attributes.
Definition: PWMTimerCC26XX.h:181
struct PWMTimerCC26XX_Object PWMTimerCC26XX_Object
PWMTimer26XX Object.
The definition of a PWM function table that contains the required set of functions to control a speci...
Definition: PWM.h:407
uint32_t periodValue
Definition: PWMTimerCC26XX.h:205
enum PWM_Period_Units_ PWM_Period_Units
PWM period unit definitions. Refer to device specific implementation if using PWM_PERIOD_COUNTS (raw ...
struct PWMTimerCC26XX_HwAttrs PWMTimerCC26XX_HwAttrs
PWMTimer26XX Hardware attributes.
uint8_t gpTimerUnit
Definition: PWMTimerCC26XX.h:184
GPTimerCC26XX_Handle hTimer
Definition: PWMTimerCC26XX.h:211
PWM_Duty_Units dutyUnit
Definition: PWMTimerCC26XX.h:207
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:378
PIN_Id pwmPin
Definition: PWMTimerCC26XX.h:183
const PWM_FxnTable PWMTimerCC26XX_fxnTable
enum PWM_IdleLevel_ PWM_IdleLevel
Idle output level when PWM is not running (stopped / not started).
uint32_t dutyCounts
Definition: PWMTimerCC26XX.h:209
Generic PIN & GPIO driver.
enum PWM_Duty_Units_ PWM_Duty_Units
PWM duty cycle unit definitions. Refer to device specific implementation if using PWM_DUTY_COUNTS (ra...
Copyright 2018, Texas Instruments Incorporated