![]() |
|
|||
File indexing completed on 2025-05-11 08:22:48
0001 /** 0002 * @file 0003 * 0004 * @ingroup arm_beagle 0005 * 0006 * @brief BeagleBone Black PWM support definitions. 0007 */ 0008 0009 /* 0010 * SPDX-License-Identifier: BSD-2-Clause 0011 * 0012 * Copyright (c) 2016 Punit Vara <punitvara@gmail.com> 0013 * 0014 * Redistribution and use in source and binary forms, with or without 0015 * modification, are permitted provided that the following conditions 0016 * are met: 0017 * 1. Redistributions of source code must retain the above copyright 0018 * notice, this list of conditions and the following disclaimer. 0019 * 2. Redistributions in binary form must reproduce the above copyright 0020 * notice, this list of conditions and the following disclaimer in the 0021 * documentation and/or other materials provided with the distribution. 0022 * 0023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0026 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0027 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0028 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0029 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0030 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0031 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0032 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0033 * POSSIBILITY OF SUCH DAMAGE. 0034 */ 0035 0036 0037 /** Some constants are taken from 0038 * https://github.com/VegetableAvenger/BBBIOlib/blob/master/BBBio_lib/BBBiolib_PWMSS.h 0039 */ 0040 0041 #ifndef LIBBSP_ARM_BEAGLE_BBB_PWM_H 0042 #define LIBBSP_ARM_BEAGLE_BBB_PWM_H 0043 0044 #ifdef __cplusplus 0045 extern "C" { 0046 #endif /* __cplusplus */ 0047 0048 /** 0049 * @brief BeagleBone Black PWM Macros. 0050 */ 0051 #define BBB_CONTROL_CONF_GPMC_AD(n) (0x800 + (n * 4)) 0052 #define BBB_CONTROL_CONF_LCD_DATA(n) (0x8a0 + (n * 4)) 0053 0054 0055 typedef enum{ 0056 BBB_P8_13_2B = 3, 0057 BBB_P8_19_2A, 0058 BBB_P8_45_2A, 0059 BBB_P8_46_2B, 0060 BBB_P8_34_1B, 0061 BBB_P8_36_1A, 0062 BBB_P9_14_1A, 0063 BBB_P9_16_1B, 0064 BBB_P9_21_0B, 0065 BBB_P9_22_0A, 0066 BBB_P9_29_0B, 0067 BBB_P9_31_0A 0068 }bbb_pwm_pin_t; 0069 0070 #define BBB_P8_13_MUX_PWM 4 0071 #define BBB_P8_19_MUX_PWM 4 0072 #define BBB_P8_45_MUX_PWM 3 0073 #define BBB_P8_46_MUX_PWM 3 0074 #define BBB_P8_34_MUX_PWM 2 0075 #define BBB_P8_36_MUX_PWM 2 0076 #define BBB_P9_14_MUX_PWM 6 0077 #define BBB_P9_16_MUX_PWM 6 0078 #define BBB_P9_21_MUX_PWM 3 0079 #define BBB_P9_22_MUX_PWM 3 0080 #define BBB_P9_29_MUX_PWM 1 0081 #define BBB_P9_31_MUX_PWM 1 0082 #define BBB_PWM_FREQ_THRESHOLD 0.5f 0083 0084 /** 0085 * @brief BeagleBone Black PWM API. 0086 */ 0087 0088 /** 0089 * @brief This function intilizes clock for pwm sub system. 0090 * 0091 * @param PWMSS_ID It is the instance number of EPWM of pwm sub system. 0092 * 0093 * @return true if successful 0094 * @return false if not successful 0095 * 0096 **/ 0097 bool beagle_pwm_init(BBB_PWMSS pwmss_id); 0098 0099 /* PWMSS setting 0100 * set pulse argument of epwm module 0101 * 0102 * @param pwm_id : EPWMSS number , 0~2 0103 * @param pwm_freq : frequency to be generated 0104 * @param dutyA : Duty Cycle(in percentage) in PWM channel A 0105 * @param dutyB : Duty Cycle(in percentage) in PWM channel B 0106 * 0107 * @return : 1 for success 0108 * @return : 0 for failed 0109 * 0110 * @example : beagle_pwm_configure(0 , 50.0f , 50.0f , 25.0f); // Generate 50HZ pwm in PWM0 , 0111 * // duty cycle is 50% for ePWM0A , 25% for ePWM0B 0112 * 0113 * @Note : 0114 * find an number nearst 65535 for TBPRD , to improve duty precision, 0115 * 0116 * Using big TBPRD can increase the range of CMPA and CMPB , 0117 * and it means we can get better precision on duty cycle. 0118 * 0119 * EX : 20.25% duty cycle 0120 * on TBPRD = 62500 , CMPA = 12656.25 ( .25 rejection) , real duty : 20.2496% (12656 /62500) 0121 * on TBPRD = 6250 , CMPA = 1265.625 ( .625 rejection), real duty : 20.24% (1265 6250) 0122 * on TBPRD = 500 , CMPA = 101.25 ( .25 rejection) , real duty : 20.2% (101/500) 0123 * 0124 * Divisor = CLKDIV * HSPCLKDIV 0125 * 1 TBPRD : 10 ns (default) 0126 * 65535 TBPRD : 655350 ns 0127 * 65535 TBPRD : 655350 * Divisor ns = X TBPRD : Cycle 0128 * 0129 * accrooding to that , we must find a Divisor value , let X nearest 65535 . 0130 * so , Divisor must Nearest Cycle/655350 0131 */ 0132 int beagle_pwm_configure(BBB_PWMSS pwm_id, float pwm_freq, float duty_a, float duty_b); 0133 0134 /** 0135 * @brief This API enables the particular PWM module. 0136 * 0137 * @param pwmid It is the instance number of EPWM of pwm sub system. 0138 * 0139 * @return true if successful 0140 * @return false if fail 0141 * 0142 **/ 0143 bool beagle_pwm_enable(BBB_PWMSS pwmid); 0144 0145 /** 0146 * @brief This API disables the particular PWM module. 0147 * 0148 * @param pwmid It is the instance number of EPWM of pwm sub system. 0149 * 0150 * @return true if successful 0151 * @return false if fail 0152 * 0153 **/ 0154 bool beagle_pwm_disable(BBB_PWMSS pwmid); 0155 0156 /** 0157 * @brief This function enables pinmuxing for PWM module. 0158 * 0159 * @param pin_no It is individual pin at which freuqency need to be generated. 0160 * It should be according to pwm sub system. 0161 * 0162 * @param pwm_id It is the instance number of EPWM of pwmsubsystem. 0163 * 0164 * @return true if successful 0165 * @return false if fail 0166 * 0167 **/ 0168 bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no, BBB_PWMSS pwm_id); 0169 0170 /** 0171 * @brief This function determines whether PWMSS-wide clocks enabled or not. 0172 * 0173 * @param pwmss_id It is the instance number of PWMSS which clocks need to be 0174 * checked. 0175 * 0176 * @return true if successful 0177 * @return false if fail 0178 * 0179 **/ 0180 bool beagle_pwmss_is_running(unsigned int pwmss_id); 0181 0182 0183 #ifdef __cplusplus 0184 } 0185 #endif /* __cplusplus */ 0186 0187 #endif /* LIBBSP_ARM_BEAGLE_BBB_PWM_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |