【MSPM0L1306 LaunchPad】7、pwm的应用
[复制链接]
MSPM0L1306 内置了四个 16 位通用计时器,每个计时器具有两个捕 捉/比较寄存器,支持待机模式下的低功耗运 行,总共支持 8 个 PWM 通道,可以通过产生SPWM信号经过低通滤波后得到正弦信号。定时器主要特性如下:
打开CCS,选择PWM例程:
PWM的配置,十分简单:
外部输出管脚配置:
程序说明,通过查SPWM正弦表方式,定时输出PWM值:
#include "ti_msp_dl_config.h"
/* Array of 128 samples to select duty cycles to generate sine waveform for 1024 Period count (10 bit DAC resolution) */
#define ARRAY_SIZE 128
uint16_t gSine128[ARRAY_SIZE] = {
512,537,562,587,611,636,660,684,
707,730,753,774,796,816,836,855,
873,890,907,922,937,950,963,974,
984,993,1001,1008,1013,1017,1021,1022,
1023,1022,1021,1017,1013,1008,1001,993,
984,974,963,950,937,922,907,890,
873,855,836,816,796,774,753,730,
707,684,660,636,611,587,562,537,
512,486,461,436,412,387,363,339,
316,293,270,249,227,207,187,168,
150,133,116,101,86,73,60,49,
39,30,22,15,10,6,2,1,
0,1,2,6,10,15,22,30,
39,49,60,73,86,101,116,133,
150,168,187,207,227,249,270,293,
316,339,363,387,412,436,461,486};
/* Counter used to cycle through sine array */
volatile uint32_t gSineCounter = 0;
int main(void)
{
SYSCFG_DL_init();
/* Enable PWM interrupts */
NVIC_EnableIRQ(PWM_0_INST_INT_IRQN);
/* Start PWM counter */
DL_TimerG_startCounter(PWM_0_INST);
while(1){
__WFI();
}
}
void PWM_0_INST_IRQHandler(void){
switch (DL_TimerG_getPendingInterrupt(PWM_0_INST)){
case DL_TIMERG_IIDX_CC0_DN: /* Interrupt on CC0 Down Event */
/* Set new Duty Cycle based on sine array sample value */
DL_TimerG_setCaptureCompareValue(PWM_0_INST, gSine128[gSineCounter%128], DL_TIMER_CC_0_INDEX);
/* Increment gSineCounter value */
gSineCounter++;
break;
default:
break;
}
}
PA10脚原始输出信号如下:
|