PWMTimerLPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024, 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 PWMTimerLPF3.h
34  * @brief PWM driver implementation for Low Power F3 devices
35  *
36  * # Overview #
37  * The general PWM API should be used in application code, i.e. PWM_open()
38  * should be used instead of PWMTimerLPF3_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 LPF3:
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 SimpleLink 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 PWMTimerLPF3.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 LGPTimer 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 LGPTimer 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 (CLKSVT) is needed for PWM operation:
66  * - After PWM_stop(): Conditions are equal as for after PWM_open
67  * - After PWM_close(): The underlying LGPTimer 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  * The LGPT peripherals have the following counter widths:
73  * - LGPT0: 16 bits
74  * - LGPT1: 16 bits
75  * - LGPT2: 16 bits
76  * - LGPT3: 24 bits
77  *
78  * Note that some LPF3 device types do not support all four LGPT peripherals.
79  *
80  * The frequency of the underlying timer counter can be divided by configuring
81  * the preScalerDivision element of the @ref PWMTimerLPF3_HwAttrs struct.
82  * This configuration can be used to extend the PWM signal period but will
83  * decrease the accuracy.
84  * The minimum obtainable PWM signal frequency is dependent on the width of
85  * the counter for the LGPT peripheral used and the configured preScalerDivision
86  * value. When using the LGPT3 peripheral with the default preScalerDivision
87  * value of 1, the minimal frequency is 48MHz / (2^24-1) = 2.86Hz (349.525ms).
88  *
89  * When using high output frequencies the duty cycle resolution is reduced
90  * correspondingly. For a 24MHz PWM only a 0%/50%/100% duty is available as
91  * the timer uses only counts 0 and 1.
92  * Similarly for a 12MHz period the duty cycle will be limited to a 12.5%
93  * resolution.
94  *
95  * @note The PWM signals are generated by the LGPT peripheral using the
96  * timer clock which is dependent on the high frequency clock (CLKSVT).
97  *
98  * # Limitations #
99  * - The PWM output can currently not be synchronized with other PWM outputs.
100  * - The PWM driver does not support updating duty and period using DMA.
101  * - Attempts to change both the period and duty cycle at the same time
102  * for an active PWM signal, can cause pulses to be too long or short if
103  * the change is applied close to the end of the current counter cycle.
104  * This does not apply to changing only the period or only the duty cycle,
105  * as any of these separate changes will take effect on the next counter cycle.
106  * # PWM usage #
107  *
108  * ## Basic PWM output ##
109  * The below example will output a 8MHz PWM signal with 50% duty cycle.
110  * @code
111  * PWM_Handle pwmHandle;
112  * PWM_Params params;
113  *
114  * PWM_Params_init(&params);
115  * params.idleLevel = PWM_IDLE_LOW;
116  * params.periodUnits = PWM_PERIOD_HZ;
117  * params.periodValue = 8e6;
118  * params.dutyUnits = PWM_DUTY_FRACTION;
119  * params.dutyValue = PWM_DUTY_FRACTION_MAX / 2;
120  *
121  * pwmHandle = PWM_open(CONFIG_PWM0, &params);
122  * if(pwmHandle == NULL) {
123  * Log_error0("Failed to open PWM");
124  * Task_exit();
125  * }
126  * PWM_start(pwmHandle);
127  * @endcode
128  *
129  *
130  *******************************************************************************
131  */
132 #ifndef ti_drivers_pwm__PWMTimerLPF3_include
133 #define ti_drivers_pwm__PWMTimerLPF3_include
134 
135 #include <stdint.h>
136 #include <stdbool.h>
137 
138 #include <ti/drivers/PWM.h>
140 
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
153 #define PWMTimerLPF3_CMD_DEBUG_STALL (PWM_CMD_RESERVED + 0)
158 #define CMD_ARG_DEBUG_STALL_OFF ((uint32_t)LGPTimerLPF3_DEBUG_STALL_OFF)
159 #define CMD_ARG_DEBUG_STALL_ON ((uint32_t)LGPTimerLPF3_DEBUG_STALL_IMMEDIATE)
160 /* @} */
161 
162 /* @} */
163 
164 /* PWM function table pointer */
166 
173 typedef struct PWMTimerLPF3_HwAttrs
174 {
178 
188 typedef struct PWMTimerLPF3_Object
189 {
190  uint32_t periodValue;
191  uint32_t periodCounts;
192  uint32_t dutyValue;
193  uint32_t dutyCounts;
199  bool isOpen;
200  bool isRunning;
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 #endif /* ti_driver_pwm_PWMTimerLPF3_include */
LGPTimer Global configuration.
Definition: LGPTimerLPF3.h:767
PWMTimerLPF3 Object.
Definition: PWMTimerLPF3.h:188
PWM_Duty_Units
PWM duty cycle unit definitions. Refer to device specific implementation if using PWM_DUTY_COUNTS (ra...
Definition: PWM.h:306
bool isOpen
Definition: PWMTimerLPF3.h:199
uint8_t lgpTimerInstance
Definition: PWMTimerLPF3.h:175
PWM_Period_Units periodUnit
Definition: PWMTimerLPF3.h:195
struct PWMTimerLPF3_Object PWMTimerLPF3_Object
PWMTimerLPF3 Object.
LGPTimerLPF3_Handle hTimer
Definition: PWMTimerLPF3.h:194
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:294
uint32_t periodValue
Definition: PWMTimerLPF3.h:190
uint32_t periodCounts
Definition: PWMTimerLPF3.h:191
uint32_t dutyValue
Definition: PWMTimerLPF3.h:192
PWM_IdleLevel idleLevel
Definition: PWMTimerLPF3.h:198
LGPTimerLPF3_ChannelNo chNumber
Definition: PWMTimerLPF3.h:197
uint32_t dutyCounts
Definition: PWMTimerLPF3.h:193
The definition of a PWM function table that contains the required set of functions to control a speci...
Definition: PWM.h:409
bool isRunning
Definition: PWMTimerLPF3.h:200
const PWM_FxnTable PWMTimerLPF3_fxnTable
LGPTimer driver implementation for Low Power F3 devices.
LGPTimerLPF3_ChannelNo
Definitions for supported LGPTimer channel numbers.
Definition: LGPTimerLPF3.h:283
uint8_t preScalerDivision
Definition: PWMTimerLPF3.h:176
struct PWMTimerLPF3_HwAttrs PWMTimerLPF3_HwAttrs
PWMTimerLPF3 Hardware attributes.
PWM_Duty_Units dutyUnit
Definition: PWMTimerLPF3.h:196
PWMTimerLPF3 Hardware attributes.
Definition: PWMTimerLPF3.h:173
PWM_IdleLevel
Idle output level when PWM is not running (stopped / not started).
Definition: PWM.h:321
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale