完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我准备用msp432的driver例程中pwmled的例程编写一个马达控制程序,再修改测试过程中发现无法使用timer_A0这个硬件资源,我在board.h,msp432p401r.h,msp432p401r.c中做了相应的修改,但依然无法打开Timer_A0。Timer_A1-A3都可以用。程序如下。
“Board.h” #define Board_TIMER0 MSP_EXP432P401R_TIMER_T32_0 #define Board_TIMER1 MSP_EXP432P401R_TIMER_T32_1 #define Board_TIMER2 MSP_EXP432P401R_TIMER_TA_0 #define Board_TIMER3 MSP_EXP432P401R_TIMER_TA_1 #define Board_TIMER4 MSP_EXP432P401R_TIMER_TA_2 #define Board_TIMER5 MSP_EXP432P401R_TIMER_TA_3 “msp432p401r.h” /*! * @def MSP_EXP432P401R_TimerName * @brief Enum of Timer names on the MSP_EXP432P401R dev board */ typedef enum MSP_EXP432P401R_TimerName [ MSP_EXP432P401R_TIMER_T32_0 = 0, MSP_EXP432P401R_TIMER_T32_1, MSP_EXP432P401R_TIMER_TA_0, MSP_EXP432P401R_TIMER_TA_1, MSP_EXP432P401R_TIMER_TA_2, MSP_EXP432P401R_TIMER_TA_3, MSP_EXP432P401R_TIMERCOUNT ] MSP_EXP432P401R_TimerName; “msp432p401r.c” /* * =============================== Timer =============================== */ #include #include TimerMSP432_Object timerMSP432Objects[MSP_EXP432P401R_TIMERCOUNT]; const TimerMSP432_HWAttrs timerMSP432HWAttrs[MSP_EXP432P401R_TIMERCOUNT] = [ /* Timer32_0 */ [ .timerBaseAddress = TIMER32_0_BASE, .clockSource = TIMER_A_CLOCKSOURCE_SMCLK, .intNum = INT_T32_INT1, .intPriority = ~0 ], [ .timerBaseAddress = TIMER32_1_BASE, .clockSource = TIMER_A_CLOCKSOURCE_SMCLK, .intNum = INT_T32_INT2, .intPriority = ~0 ], /* Timer_A0 */ [ .timerBaseAddress = TIMER_A0_BASE, .clockSource = TIMER_A_CLOCKSOURCE_ACLK, .intNum = INT_TA0_N, .intPriority = ~0 ], /* Timer_A1 */ [ .timerBaseAddress = TIMER_A1_BASE, .clockSource = TIMER_A_CLOCKSOURCE_ACLK, .intNum = INT_TA1_0, .intPriority = ~0 ], /* Timer_A2 */ [ .timerBaseAddress = TIMER_A2_BASE, .clockSource = TIMER_A_CLOCKSOURCE_ACLK, .intNum = INT_TA2_0, .intPriority = ~0 ], /* Timer_A3 */ [ .timerBaseAddress = TIMER_A3_BASE, .clockSource = TIMER_A_CLOCKSOURCE_ACLK, .intNum = INT_TA3_0, .intPriority = ~0 ] ]; const Timer_Config Timer_config[MSP_EXP432P401R_TIMERCOUNT] = [ [ .fxnTablePtr = &TimerMSP432_Timer32_fxnTable, .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_T32_0], .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_T32_0] ], [ .fxnTablePtr = &TimerMSP432_Timer32_fxnTable, .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_T32_1], .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_T32_1] ], [ .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable, .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_TA_0], .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_TA_0] ], [ .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable, .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_TA_1], .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_TA_1] ], [ .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable, .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_TA_2], .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_TA_2] ], [ .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable, .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_TA_3], .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_TA_3] ] ]; "pwmled.c" /* * ======== pwmled.c ======== */ /* For usleep() */ #include #include #include /* Driver Header files */ #include #include /* Example/Board Header files */ #include "Board.h" PWM_Handle pwm1 = NULL; PWM_Handle pwm2 = NULL; PWM_Handle pwm3 = NULL; PWM_Handle pwm4 = NULL; /* Period and duty in microseconds */ uint32_t pwmPeriod = 5000; uint32_t duty = 3000; /* N steps */ uint32_t n = 4096; /* motor start/stop flag */ bool motorflag = true; /******************************************************************************* * LOCAL FUNCTIONS ******************************************************************************/ static void motor_forward(uint32_t value); static void motor_reversal(uint32_t value); static void timer0Callback(Timer_Handle myHandle); /* * ======== mainThread ======== * Task periodically increments the PWM duty for the on board LED. */ void *mainThread(void *arg0) [ PWM_Params params; Timer_Params timeparams; Timer_Handle timer0; /* Call driver init functions. */ PWM_init(); Timer_init(); PWM_Params_init(¶ms); params.dutyUnits = PWM_DUTY_US; params.dutyValue = 0; params.periodUnits = PWM_PERIOD_US; params.periodValue = pwmPeriod; pwm1 = PWM_open(Board_PWM0, ¶ms); pwm2 = PWM_open(Board_PWM1, ¶ms); pwm3 = PWM_open(Board_PWM2, ¶ms); pwm4 = PWM_open(Board_PWM3, ¶ms); if (pwm1 == NULL) [ /* Board_PWM0 did not open */ while (1); ] if (pwm2 == NULL) [ /* Board_PWM0 did not open */ while (1); ] if (pwm3 == NULL) [ /* Board_PWM0 did not open */ while (1); ] if (pwm4 == NULL) [ /* Board_PWM0 did not open */ while (1); ] PWM_start(pwm1); PWM_start(pwm2); PWM_start(pwm3); PWM_start(pwm4); Timer_Params_init(&timeparams); timeparams.period = 5000000; timeparams.periodUnits = Timer_PERIOD_US; timeparams.timerMode = Timer_ONESHOT_CALLBACK; timeparams.timerCallback = timer0Callback; timer0 = Timer_open(Board_TIMER2, &timeparams); if (timer0 == NULL) [ /* Failed to initialized timer */ while (1); 程序会在这里进入死循环,因为Board_TIMER2(Timer_A0)没有打开. ] Timer_start(timer0); motor_forward(n); sleep(1); motor_reversal(n); sleep(1); return NULL; ] /*Motor forward*/ static void motor_forward(uint32_t value) [ uint32_t i; uint8_t j; uint8_t step; for(i=value;i>8;i=i-8) [ if(motorflag == false) [ i = 0; break; ] for(step=0;step<8;step++) [ if(motorflag == false) [ break; ] switch(step) [ case 0: /*A*/ PWM_setDuty(pwm1, duty); usleep(pwmPeriod); break; case 1: /*AB*/ PWM_setDuty(pwm2, duty); usleep(pwmPeriod); PWM_setDuty(pwm1, 0); break; case 2: /*B*/ usleep(pwmPeriod); break; case 3: /*BC*/ PWM_setDuty(pwm3, duty); usleep(pwmPeriod); PWM_setDuty(pwm2, 0); break; case 4: /*C*/ usleep(pwmPeriod); break; case 5: /*CD*/ PWM_setDuty(pwm4, duty); usleep(pwmPeriod); PWM_setDuty(pwm3, 0); break; case 6: /*D*/ usleep(pwmPeriod); break; case 7: /*DA*/ PWM_setDuty(pwm1, duty); usleep(pwmPeriod); PWM_setDuty(pwm4, 0); PWM_setDuty(pwm1, 0); break; default: break; ] ] ] for(j=0;j [ if(motorflag == false) [ break; ] switch(j) [ case 0: /*A*/ PWM_setDuty(pwm1, duty); usleep(pwmPeriod); break; case 1: /*AB*/ PWM_setDuty(pwm2, duty); usleep(pwmPeriod); PWM_setDuty(pwm1, 0); break; case 2: /*B*/ usleep(pwmPeriod); break; case 3: /*BC*/ PWM_setDuty(pwm3, duty); usleep(pwmPeriod); PWM_setDuty(pwm2, 0); break; case 4: /*C*/ usleep(pwmPeriod); break; case 5: /*CD*/ PWM_setDuty(pwm4, duty); usleep(pwmPeriod); PWM_setDuty(pwm3, 0); break; case 6: /*D*/ usleep(pwmPeriod); break; case 7: /*DA*/ PWM_setDuty(pwm1, duty); usleep(pwmPeriod); PWM_setDuty(pwm4, 0); PWM_setDuty(pwm1, 0); break; default: break; ] ] PWM_setDuty(pwm1, 0); PWM_setDuty(pwm2, 0); PWM_setDuty(pwm3, 0); PWM_setDuty(pwm4, 0); ] /*Motor reversal*/ static void motor_reversal(uint32_t value) [ uint32_t i; uint8_t j; uint8_t step; for(i=value;i>8;i=i-8) [ if(motorflag == false) [ i = 0; break; ] for(step=0;step<8;step++) [ if(motorflag == false) [ break; ] switch(step) [ case 0: /*D*/ PWM_setDuty(pwm4, duty); usleep(pwmPeriod); break; case 1: /*DC*/ PWM_setDuty(pwm3, duty); usleep(pwmPeriod); PWM_setDuty(pwm4, 0); break; case 2: /*C*/ usleep(pwmPeriod); break; case 3: /*CB*/ PWM_setDuty(pwm2, duty); usleep(pwmPeriod); PWM_setDuty(pwm3, 0); break; case 4: /*B*/ usleep(pwmPeriod); break; case 5: /*BA*/ PWM_setDuty(pwm1, duty); usleep(pwmPeriod); PWM_setDuty(pwm2, 0); break; case 6: /*A*/ usleep(pwmPeriod); break; case 7: /*AD*/ PWM_setDuty(pwm4, duty); usleep(pwmPeriod); PWM_setDuty(pwm1, 0); PWM_setDuty(pwm4, 0); break; default: break; ] ] ] for(j=0;j [ if(motorflag == false) [ break; ] switch(j) [ case 0: /*D*/ PWM_setDuty(pwm4, duty); usleep(pwmPeriod); break; case 1: /*DC*/ PWM_setDuty(pwm3, duty); usleep(pwmPeriod); PWM_setDuty(pwm4, 0); break; case 2: /*C*/ usleep(pwmPeriod); break; case 3: /*CB*/ PWM_setDuty(pwm2, duty); usleep(pwmPeriod); PWM_setDuty(pwm3, 0); break; case 4: /*B*/ usleep(pwmPeriod); break; case 5: /*BA*/ PWM_setDuty(pwm1, duty); usleep(pwmPeriod); PWM_setDuty(pwm2, 0); break; case 6: /*A*/ usleep(pwmPeriod); break; case 7: /*AD*/ PWM_setDuty(pwm4, duty); usleep(pwmPeriod); PWM_setDuty(pwm1, 0); PWM_setDuty(pwm4, 0); break; default: break; ] ] PWM_setDuty(pwm1, 0); PWM_setDuty(pwm2, 0); PWM_setDuty(pwm3, 0); PWM_setDuty(pwm4, 0); ] static void timer0Callback(Timer_Handle myHandle) [ motorflag = false; ] |
|
相关推荐
6个回答
|
|
|
|
|
|
有关timer的配置就那么几行,其他timerA都可以打开,只有timerA0打不开,无法使用。 |
|
|
|
Timer_A0是不是已经被其他资源占用了,所以打不开。因为我目前位置看到的例程中timer driver使用的timerA都是timerA1,A2,A3。为社么不使用A0呢。 |
|
|
|
xbvwerw 发表于 2018-6-21 12:25 TimerA0用作定时的话也不用配置输出口, |
|
|
|
xbvwerw 发表于 2018-6-21 12:25 TimerA配置成定时的话也不用配置输出口 |
|
|
|
是不是SYS/BIOS中的clock模块产生的clock ticks就是基于timer_A0 |
|
|
|
只有小组成员才能发言,加入小组>>
332 浏览 1 评论
528 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
772 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
649 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1124 浏览 1 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
51浏览 29评论
83浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
244浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
196浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
54浏览 13评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 12:28 , Processed in 0.950688 second(s), Total 87, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号