测试了TIMER_A的PWM几种模式
pwmMultipleUp
2.06kHz,75%占空比
#include "wdt_a.h"
#include "gpio.h"
#include "timer_a.h"
#define TIMER_PERIOD 511
#define DUTY_CYCLE1 384
#define DUTY_CYCLE2 128
int main( void )
{
volatile unsigned int i;
WDT_A_hold(WDT_A_BASE);
//P2.0 and P2.1 output
//P2.0 and P2.1 options select
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0 + GPIO_PIN1);
//Start timer
Timer_A_initUpModeParam initUpParam = {0};
initUpParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
initUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
initUpParam.timerPeriod = TIMER_PERIOD;
initUpParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
initUpParam.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;
initUpParam.timerClear = TIMER_A_DO_CLEAR;
initUpParam.startTimer = false;
Timer_A_initUpMode(TIMER_A1_BASE, &initUpParam);
Timer_A_startCounter(TIMER_A1_BASE,TIMER_A_UP_MODE);
//Initialize compare mode to generate PWM1
Timer_A_initCompareModeParam initComp1Param = {0};
initComp1Param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
initComp1Param.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;
initComp1Param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
initComp1Param.compareValue = DUTY_CYCLE1;
Timer_A_initCompareMode(TIMER_A1_BASE, &initComp1Param);
//Initialize compare mode to generate PWM2
Timer_A_initCompareModeParam initComp2Param = {0};
initComp2Param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2;
initComp2Param.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;
initComp2Param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
initComp2Param.compareValue = DUTY_CYCLE2;
Timer_A_initCompareMode(TIMER_A1_BASE, &initComp2Param);
//Enter LPM0
__bis_SR_register(LPM0_bits);
//For debugger
__no_operation();
while(1) // continuous loop
{
}
}
pwmSingle
2.06kHz,68%占空比
#include "wdt_a.h"
#include "gpio.h"
#include "timer_a.h"
#define TIMER_PERIOD 511
#define DUTY_CYCLE 350
int main( void )
{
volatile unsigned int i;
WDT_A_hold(WDT_A_BASE);
//P2.0 as PWM output
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0);
//Generate PWM - Timer runs in Up mode
Timer_A_outputPWMParam param = {0};
param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
param.timerPeriod = TIMER_PERIOD;
param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
param.dutyCycle = DUTY_CYCLE;
Timer_A_outputPWM(TIMER_A1_BASE, ¶m);
//Enter LPM0
__bis_SR_register(LPM0_bits);
//For debugger
__no_operation();
while(1) // continuous loop
{
}
}
上一篇:MSP-EXP430F5529LP开发板003-定时器库函数
下一篇:MSP430F5529LP+CC3000学习心得(一)——与AP的连接
推荐阅读最新更新时间:2024-11-09 18:26
设计资源 培训 开发板 精华推荐
- TDA7850H 4 x 50 W MOSFET 四桥功率放大器加 HSD 的典型应用
- LTC1538CG-AUX高效低噪声5V/3A、3.3V/3A、2.9V/2.6A、12V/200mA、5V/20mA笔记本电脑电源典型应用电路
- 电子教鞭(带鼠标控制)
- KITVR5100FRDMEVM: VR5100电源管理集成电路的评估套件
- 使用 Analog Devices 的 LT1269CQ 的参考设计
- CS51031快速Pfet降压控制器的典型应用电路不需要补偿
- LT3091ET7 线性稳压器的典型应用,使用较低值的 RSET 以实现较高的输出电压
- 用于医疗的 12 位、125KSPS DAC
- DC1903A-A,基于 LTM2889-3 隔离式 CAN 收发器加电源 @ 3.3V 电源的演示板
- LT3580,宽输入范围 SEPIC 转换器,具有 2.5MHz 的 5V 输出开关