This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Technical Reference似乎表示了不同的PWM Generator可以采用不同的波形频率。
然而我在使用TI-drivers时无法使不同发生器的PWM采用不同频率。我该如何解决?
此外,MSP432E4系列的产品的timer的PWM_MODE产生的波形是否有占空比为50%的限制?
您是否有参考TI例程:
simplelink_msp432e4_sdk_4_20_00_12\examples\nortos\MSP_EXP432E401Y\driverlib\pwm_genx_syncgenerators
可以过编译。然而PWM_open()的返回值是NULL.具体情况是在PWMMSP432E4.c里initHw()中此处返回的错误导致。我这里尽管使用了不同generator的引脚,可是只要频率不同就无法打开PWM。我该如何向你发送代码?
抱歉,我这边找了一下,没有MSP432E的板子,所以我是使用MSP432P系列来测试的
代码如下,不建议您在循环内打开PWM,即
/*** - custom variables end - ***/
for(int i=0;i<CONFIG_PWM_COUNT;i++){
pwmHandle[i] = PWM_open(i, pwmParams+i);
if(pwmHandle[i]==NULL){
//error: PWM did not open
//there had better a UART output
while(1);
}
而是尝试逐个打开
/* * Copyright (c) 2015-2019, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ======== pwmled2.c ======== */ /* For usleep() */ #include <unistd.h> #include <stddef.h> /* Driver Header files */ #include <ti/drivers/PWM.h> /* Driver configuration */ #include "ti_drivers_config.h" /* * ======== mainThread ======== * Task periodically increments the PWM duty for the on board LED. */ void *mainThread(void *arg0) { /* Period and duty in microseconds */ uint16_t pwmPeriod = 3000; uint16_t duty = 0; uint16_t dutyInc = 100; /* Sleep time in microseconds */ uint32_t time = 50000; PWM_Handle pwm1 = NULL; PWM_Handle pwm2 = NULL; PWM_Params params; /* Call driver init functions. */ PWM_init(); PWM_Params_init(¶ms); params.dutyUnits = PWM_DUTY_US; params.dutyValue = 0; params.periodUnits = PWM_PERIOD_US; params.periodValue = pwmPeriod; pwm1 = PWM_open(CONFIG_PWM_0, ¶ms); if (pwm1 == NULL) { /* CONFIG_PWM_0 did not open */ while (1); } PWM_start(pwm1); pwm2 = PWM_open(CONFIG_PWM_1, ¶ms); if (pwm2 == NULL) { /* CONFIG_PWM_0 did not open */ while (1); } PWM_start(pwm2); /* Loop forever incrementing the PWM duty */ while (1) { PWM_setDuty(pwm1, duty); PWM_setDuty(pwm2, duty); duty = (duty + dutyInc); if (duty == pwmPeriod || (!duty)) { dutyInc = - dutyInc; } usleep(time); } }
您可以看一下下面链接的
以及说明:
另外我之前附上的代码是MSP432P401R系列的例程
你好,我虽然使用了循环打开PWM,但是我并没有使用同样的index,而是利用了循环变量i“PWM_open(i,params+i)”
此外,MSP432P4和E4型号名字相似,但是PWM实现外设不同,差别较大,还麻烦您帮我再问一问,以解我心头之困,谢谢