定时器PWM值实现,可用于调光等的实现。
- EM357:
- 初始化
TIM2_OR = TIM_REMAPC4 | TIM_REMAPC3; /*两路通道,也可以打开四路通道*/
/*具体请查看EM357数据手册寄存器说明*/
TIM2_PSC = 0x1; //1^2=2 -> 12MHz/2 = 6 MHz = 6000 ticks per 1/1000 of a second
TIM2_EGR = 1; //trigger update event to load new prescaler value
TIM2_CCMR1 = 0; //start from a zeroed configuration
TIM2_ARR = emberAfBulbConfigTicsPerPeriod(); // set the period
TIM2_CNT = 0; //force the counter back to zero to prevent missing LEVEL_CONTROL_TOP
TIM2_CCR3 = 0;
TIM2_CCR4 = 0;
TIM2_CCMR2 |= (0x7 << TIM_OC3M_BIT) |
(0x7 << TIM_OC4M_BIT);
TIM2_CCER |= TIM_CC3P; // set up PWM 3 as active low
TIM2_CCER |= TIM_CC4P; // set up PWM 4 as active low
TIM2_CCER |= TIM_CC3E; //enable output on channel 3
TIM2_CCER |= TIM_CC4E; //enable output on channel 4
TIM2_CR1 |= TIM_CEN;
改变TIM2_CCR即可调节PWM值。
- EFR32:
初始化
- 管脚初始化
CMU_ClockEnable(cmuClock_GPIO,