PWMTimerCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019, 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  *
79  * The effect of this is most visible when using high output frequencies as the
80  * available duty cycle resolution is reduced correspondingly. For a 24MHz PWM
81  * only a 0%/50%/100% duty is available as the timer uses only counts 0 and 1.
82  * Similarly for a 12MHz period the duty cycle will be limited to a 12.5%
83  * resolution.
84  *
85  * @note The PWM signals are generated using the high-frequency clock as
86  * a source. The internal RC oscillator is the source of the high frequency
87  * clock, but may not be accurate enough for certain applications. If very
88  * high-accuracy outputs are needed, the application should request using
89  * the external HF crystal:
90  * @code
91  * #include <ti/drivers/Power.h>
92  * #include <ti/drivers/power/PowerCC26XX.h>
93  * Power_setDependency(PowerCC26XX_XOSC_HF);
94  * @endcode
95  *
96  * # Limitations #
97  * - The PWM output can currently not be synchronized with other PWM outputs
98  * - The PWM driver does not support updating duty and period using DMA.
99  * - Changes to the timer period are applied immediately, which can cause
100  * pulses to be too long or short unless period changes are applied close
101  * to a timeout. Does not apply to duty cycle, which is applied on timeout.
102  * # PWM usage #
103  *
104  * ## Basic PWM output ##
105  * The below example will output a 8MHz PWM signal with 50% duty cycle.
106  * @code
107  * PWM_Handle pwmHandle;
108  * PWM_Params params;
109  *
110  * PWM_Params_init(&params);
111  * params.idleLevel = PWM_IDLE_LOW;
112  * params.periodUnits = PWM_PERIOD_HZ;
113  * params.periodValue = 8e6;
114  * params.dutyUnits = PWM_DUTY_FRACTION;
115  * params.dutyValue = PWM_DUTY_FRACTION_MAX / 2;
116  *
117  * pwmHandle = PWM_open(CONFIG_PWM0, &params);
118  * if(pwmHandle == NULL) {
119  * Log_error0("Failed to open PWM");
120  * Task_exit();
121  * }
122  * PWM_start(pwmHandle);
123  * @endcode
124  *
125  *
126  *******************************************************************************
127  */
128 #ifndef ti_drivers_pwm__PWMTimerCC26XX_include
129 #define ti_drivers_pwm__PWMTimerCC26XX_include
130 
131 #include <stdint.h>
132 #include <stdbool.h>
133 
134 #include <ti/drivers/PIN.h>
135 #include <ti/drivers/PWM.h>
137 
138 #ifdef __cplusplus
139 extern "C" {
140 #endif
141 
150 #define PWMTimerCC26XX_CMD_DEBUG_STALL PWM_CMD_RESERVED + 0
155 #define CMD_ARG_DEBUG_STALL_OFF (uint32_t)GPTimerCC26XX_DEBUG_STALL_OFF
156 #define CMD_ARG_DEBUG_STALL_ON (uint32_t)GPTimerCC26XX_DEBUG_STALL_ON
157 /* @} */
158 
159 /* @} */
160 
161 /* PWM function table pointer */
163 
185 {
187  uint8_t gpTimerUnit;
189 
204 typedef struct PWMTimerCC26XX_Object
205 {
206  bool isOpen;
207  bool isRunning;
209  uint32_t periodValue;
210  uint32_t periodCounts;
212  uint32_t dutyValue;
213  uint32_t dutyCounts;
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 #endif /* ti_driver_pwm_PWMTimerCC26XX_include */
uint8_t PIN_Id
Pin identifier data type.
Definition: PIN.h:578
PWM_IdleLevel idleLevel
Definition: PWMTimerCC26XX.h:214
bool isOpen
Definition: PWMTimerCC26XX.h:206
GPTimer driver implementation for CC26XX/CC13XX.
PWM_Period_Units periodUnit
Definition: PWMTimerCC26XX.h:208
PWMTimer26XX Object.
Definition: PWMTimerCC26XX.h:204
PWM_Duty_Units
PWM duty cycle unit definitions. Refer to device specific implementation if using PWM_DUTY_COUNTS (ra...
Definition: PWM.h:306
bool isRunning
Definition: PWMTimerCC26XX.h:207
uint32_t periodCounts
Definition: PWMTimerCC26XX.h:210
uint32_t dutyValue
Definition: PWMTimerCC26XX.h:212
Pulse Width Modulation (PWM) driver.
PWM_Period_Units
PWM period unit definitions. Refer to device specific implementation if using PWM_PERIOD_COUNTS (raw ...
Definition: PWM.h:295
PWMTimer26XX Hardware attributes.
Definition: PWMTimerCC26XX.h:184
struct PWMTimerCC26XX_Object PWMTimerCC26XX_Object
PWMTimer26XX Object.
uint32_t periodValue
Definition: PWMTimerCC26XX.h:209
The definition of a PWM function table that contains the required set of functions to control a speci...
Definition: PWM.h:410
struct PWMTimerCC26XX_HwAttrs PWMTimerCC26XX_HwAttrs
PWMTimer26XX Hardware attributes.
uint8_t gpTimerUnit
Definition: PWMTimerCC26XX.h:187
GPTimerCC26XX_Handle hTimer
Definition: PWMTimerCC26XX.h:215
PWM_Duty_Units dutyUnit
Definition: PWMTimerCC26XX.h:211
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:407
PIN_Id pwmPin
Definition: PWMTimerCC26XX.h:186
const PWM_FxnTable PWMTimerCC26XX_fxnTable
uint32_t dutyCounts
Definition: PWMTimerCC26XX.h:213
PWM_IdleLevel
Idle output level when PWM is not running (stopped / not started).
Definition: PWM.h:320
Generic PIN & GPIO driver.
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale