我在使用MSP430FR2433库函数进行PWM输出实验的时候,发现无法成功输出。反复看了注释、手册都找不到问题,求大佬帮忙。
我写的PWM初始化函数是这样
- void PWM_Init(void)
- {
- GPIO_Init();
- Timer_Init();
-
- }
- void GPIO_Init(void)
- {
- GPIO_setAsOutputPin(GPIO_PORT_P1 , GPIO_PIN1);
- }
- void Timer_Init(void)
- {
- Timer_A_initUpModeParam Timer_A_initUpModeParameter;
- Timer_A_initCompareModeParam Timer_A_initCompareModeParameter;
- /**********************************************************************/
-
- Timer_A_initUpModeParameter.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;
- Timer_A_initUpModeParameter.clockSource = TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK;
- Timer_A_initUpModeParameter.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
- Timer_A_initUpModeParameter.startTimer = 0;
- Timer_A_initUpModeParameter.timerClear = TIMER_A_DO_CLEAR ;
- Timer_A_initUpModeParameter.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
- Timer_A_initUpModeParameter.timerPeriod = 1000;
-
- Timer_A_initUpMode(TIMER_A0_BASE , & Timer_A_initUpModeParameter);
-
- /*************************************************************************/
-
- Timer_A_initCompareModeParameter.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
- Timer_A_initCompareModeParameter.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;
- Timer_A_initCompareModeParameter.compareOutputMode = TIMER_A_OUTPUTMODE_TOGGLE_SET;
- Timer_A_initCompareModeParameter.compareValue = 500;
-
- Timer_A_initCompareMode(TIMER_A0_BASE, & Timer_A_initCompareModeParameter);
-
- /***************************************************************************/
-
- Timer_A_startCounter(TIMER_A0_BASE , TIMER_A_UP_MODE);
-
- }
复制代码
然后在main函数中调用PWM_Init()函数。
附上IAR工程
此帖出自
小平头技术问答
一周热门 更多>