void timera2_pwm2_cfg(void)
{
M4_MSTP->FCG2_f.TIMERA_2 = 0; //时钟使能TIMERA_2功能
ENABLE_GPIO_REG_WRITE();
M4_PORT->PCRA1_f.DDIS = 0; //配置成为数字口
M4_PORT->PFSRA1_f.FSEL = 4 ; //配置成TIMA_2_PWM2输出
DISABLE_GPIO_REG_WRITE();
M4_PORT->POERA_f.POUTE01 = 1; //输出
M4_TMRA2->BCSTR_f.CKDIV = 1; //PCLK1/2(20M)
M4_TMRA2->BCSTR_f.SYNST = 0; //禁止与1单元同步
M4_TMRA2->BCSTR_f.MODE = 0; //锯齿波计数方式
M4_TMRA2->BCSTR_f.DIR = 1; //向上计数方式
// M4_TMRA2->ECONR_f.ETEN2 = 1; //2单元2通道使能匹配事件输出
M4_TMRA2->ICONR_f.ITEN2 = 1; //2单元2通道使能匹配中断
M4_INTC->SEL2_f.INTSEL = INT_TMRA2_CMP; //中断2选择定时器a2通道2匹配中断
NVIC_ClearPendingIRQ(Int002_IRQn);
NVIC_SetPriority(Int002_IRQn , 12); //设置优先级
NVIC_EnableIRQ(Int002_IRQn); //使能中断1
M4_TMRA2->PERAR_f.PER = 25; //1.25us周期
M4_TMRA2->CMPAR2_f.CMP = 12; //0.6us
// M4_TMRA2->CMPAR2_f.CMP = rgb[0];
M4_TMRA2->PCONR2_f.CMPC = 0; //匹配输出0
M4_TMRA2->PCONR2_f.PERC = 1; //溢出输出1
M4_TMRA2->PCONR2_f.STAC = 1; //溢出输出1
M4_TMRA2->PCONR2_f.STPC = 0; //溢出输出0
M4_TMRA2->PCONR2_f.OUTEN = 1; //端口输出使能
M4_TMRA2->BCSTR_f.START = 1; //定时器开启
}
void IRQ002_Handler(void)
{
if(M4_TMRA2->STFLR_f.CMPF2)
{
M4_TMRA2->STFLR_f.CMPF2 = 0; //清楚中断标志位
}
}
修改频率就修改M4_TMRA2->PERAR_f.PER,修改占空比就修改M4_TMRA2->CMPAR2_f.CMP,
配置和中断都给你写好了 |