[5e3096db] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup arm_beagle |
---|
| 5 | * |
---|
| 6 | * @brief BeagleBone Black BSP definitions. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * Copyright (c) 2016 Punit Vara <punitvara at gmail.com> |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
| 14 | * http://www.rtems.org/license/LICENSE. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | /** Some constants are taken from |
---|
| 18 | * https://github.com/VegetableAvenger/BBBIOlib/blob/master/BBBio_lib/BBBiolib_PWMSS.h |
---|
| 19 | */ |
---|
| 20 | |
---|
[6dc5c03f] | 21 | #ifndef LIBBSP_ARM_BEAGLE_BBB_PWM_H |
---|
| 22 | #define LIBBSP_ARM_BEAGLE_BBB_PWM_H |
---|
| 23 | |
---|
| 24 | #ifdef __cplusplus |
---|
| 25 | extern "C" { |
---|
| 26 | #endif /* __cplusplus */ |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * @brief BeagleBone Black PWM Macros. |
---|
| 30 | */ |
---|
[5e3096db] | 31 | #define BBB_CONTROL_CONF_GPMC_AD(n) (0x800 + (n * 4)) |
---|
| 32 | #define BBB_CONTROL_CONF_LCD_DATA(n) (0x8a0 + (n * 4)) |
---|
| 33 | |
---|
| 34 | #define BBB_PWMSS_COUNT 3 |
---|
| 35 | #define BBB_PWMSS0 0 |
---|
| 36 | #define BBB_PWMSS1 1 |
---|
| 37 | #define BBB_PWMSS2 2 |
---|
| 38 | |
---|
| 39 | #define BBB_P8_13_2B 3 |
---|
| 40 | #define BBB_P8_19_2A 4 |
---|
| 41 | #define BBB_P8_45_2A 5 |
---|
| 42 | #define BBB_P8_46_2B 6 |
---|
| 43 | #define BBB_P8_34_1B 7 |
---|
| 44 | #define BBB_P8_36_1A 8 |
---|
| 45 | #define BBB_P9_14_1A 9 |
---|
| 46 | #define BBB_P9_16_1B 10 |
---|
| 47 | #define BBB_P9_21_0B 11 |
---|
| 48 | #define BBB_P9_22_0A 12 |
---|
| 49 | #define BBB_P9_29_0B 13 |
---|
| 50 | #define BBB_P9_31_0A 14 |
---|
| 51 | |
---|
| 52 | #define BBB_MUX0 0 |
---|
| 53 | #define BBB_MUX1 1 |
---|
| 54 | #define BBB_MUX2 2 |
---|
| 55 | #define BBB_MUX3 3 |
---|
| 56 | #define BBB_MUX4 4 |
---|
| 57 | #define BBB_MUX5 5 |
---|
| 58 | #define BBB_MUX6 6 |
---|
| 59 | #define BBB_MUX7 7 |
---|
| 60 | |
---|
| 61 | #define BBB_EPWM1 1 |
---|
| 62 | #define BBB_EPWM2 2 |
---|
| 63 | #define BBB_EPWM0 0 |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * @brief BeagleBone Black PWM API. |
---|
| 67 | */ |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * @brief This function intilize clock and pinmuxing for pwm sub system. |
---|
| 71 | * |
---|
| 72 | * @param PWMSS_ID It is the instance number of EPWM of pwm sub system. |
---|
| 73 | * |
---|
| 74 | * @return true if successful |
---|
| 75 | * @return false if not successful |
---|
| 76 | * |
---|
| 77 | **/ |
---|
| 78 | bool beagle_pwm_init(uint32_t pwmss_id); |
---|
| 79 | |
---|
| 80 | /* PWMSS setting |
---|
| 81 | * set pulse argument of epwm module |
---|
| 82 | * |
---|
| 83 | * @param pwm_id : EPWMSS number , 0~2 |
---|
| 84 | * @param pwm_freq : frequency to be generated |
---|
| 85 | * @param dutyA : Duty Cycle in ePWM A |
---|
| 86 | * @param dutyB : Duty Cycle in ePWM B |
---|
| 87 | * |
---|
| 88 | * @return : 1 for success |
---|
| 89 | * @return : 0 for failed |
---|
| 90 | * |
---|
| 91 | * @example : PWMSS_Setting(0 , 50.0f , 50.0f , 25.0f); // Generate 50HZ pwm in PWM0 , |
---|
| 92 | * // duty cycle is 50% for ePWM0A , 25% for ePWM0B |
---|
| 93 | * |
---|
| 94 | * @Note : |
---|
| 95 | * find an number nearst 65535 for TBPRD , to improve duty precision, |
---|
| 96 | * |
---|
| 97 | * Using big TBPRD can increase the range of CMPA and CMPB , |
---|
| 98 | * and it means we can get better precision on duty cycle. |
---|
| 99 | * |
---|
| 100 | * EX : 20.25% duty cycle |
---|
| 101 | * on TBPRD = 62500 , CMPA = 12656.25 ( .25 rejection) , real duty : 20.2496% (12656 /62500) |
---|
| 102 | * on TBPRD = 6250 , CMPA = 1265.625 ( .625 rejection), real duty : 20.24% (1265 6250) |
---|
| 103 | * on TBPRD = 500 , CMPA = 101.25 ( .25 rejection) , real duty : 20.2% (101/500) |
---|
| 104 | * |
---|
| 105 | * Divisor = CLKDIV * HSPCLKDIV |
---|
| 106 | * 1 TBPRD : 10 ns (default) |
---|
| 107 | * 65535 TBPRD : 655350 ns |
---|
| 108 | * 65535 TBPRD : 655350 * Divisor ns = X TBPRD : Cyclens |
---|
| 109 | * |
---|
| 110 | * accrooding to that , we must find a Divisor value , let X nearest 65535 . |
---|
| 111 | * so , Divisor must Nearest Cyclens/655350 |
---|
| 112 | */ |
---|
| 113 | int beagle_pwmss_setting(uint32_t pwm_id, float pwm_freq, float dutyA, float dutyB); |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * @brief This API enables the particular PWM module. |
---|
| 117 | * |
---|
| 118 | * @param pwmid It is the instance number of EPWM of pwm sub system. |
---|
| 119 | * |
---|
| 120 | * @return true if successful |
---|
| 121 | * @return false if fail |
---|
| 122 | * |
---|
| 123 | **/ |
---|
| 124 | bool beagle_ehrpwm_enable(uint32_t pwmid); |
---|
[6dc5c03f] | 125 | |
---|
[5e3096db] | 126 | /** |
---|
| 127 | * @brief This API disables the HR sub-module. |
---|
| 128 | * |
---|
| 129 | * @param pwmid It is the instance number of EPWM of pwm sub system. |
---|
| 130 | * |
---|
| 131 | * @return true if successful |
---|
| 132 | * @return false if fail |
---|
| 133 | * |
---|
| 134 | **/ |
---|
| 135 | bool beagle_ehrpwm_disable(uint32_t pwmid); |
---|
| 136 | |
---|
| 137 | /** |
---|
| 138 | * @brief This function Enables pinmuxing for PWM module. |
---|
| 139 | * |
---|
| 140 | * @param pin_no It is individual pin at which freuqency need to be generated. |
---|
| 141 | * It should be according to pwm sub system. |
---|
| 142 | * |
---|
| 143 | * @param pwm_id It is the instance number of EPWM of pwmsubsystem. |
---|
| 144 | * |
---|
| 145 | * @return true if successful |
---|
| 146 | * @return false if fail |
---|
| 147 | * |
---|
| 148 | **/ |
---|
| 149 | bool beagle_epwm_pinmux_setup(uint32_t pin_no, uint32_t pwm_id); |
---|
[6dc5c03f] | 150 | |
---|
| 151 | #ifdef __cplusplus |
---|
| 152 | } |
---|
| 153 | #endif /* __cplusplus */ |
---|
| 154 | |
---|
| 155 | #endif /* LIBBSP_ARM_BEAGLE_BBB_PWM_H */ |
---|