问答

汇集网友智慧,解决技术难题

leadd@sina.com

TA的家园币:49  

  • 新唐的PWM产生波形,其实起始相位偏移点可以控制的

    为了形成三相方波,相位差120度。PWM独立方式工作。一开始初始化时就使能了各个通道。然后造成3个一摸一样的波形。完全不是期望的模样。反复测试,在ch0里设计计数比较点为120度。仅使能ch0中断。然后,在PWM0P0里使能第二通道。同理在第二通道中断使能第三通道复制voidPWM1P0_IRQHandler(void){/*A相比较事件发生(120)*/PWM1->CNTEN|=PWM_CNTEN_CNTEN2_Msk;/*标志被硬件置1。软件写1到该位->清标志。*/PWM1->INTSTS0|=PWM_INTSTS0_CMPUIF0_Msk;--------这一句,依TRM是写1清零的。原想判断哪个通道引起的事件,可这里就是句废话。。。行不通。有人能解释下吗?NVIC_DisableIRQ(PWM1P0_IRQn);}voidPWM1P1_IRQHandler(void){/*B相比较事件发生(120)*/PWM1->CNTEN|=PWM_CNTEN_CNTEN4_Msk;NVIC_DisableIRQ(PWM1P1_IRQn);}voidPWM1P2_IRQHandler(void){/*c相比较事件发生(120)*/PWM_SET_CMR(PWM1,0,32726);//恢复前两相的占空比50%PWM_SET_CMR(PWM1,2,32726);NVIC_DisableIRQ(PWM1P2_IRQn);}因为是周期波形,中断一次就够了。中断最后是全关闭了初始化代码如下:复制PWM_DISABLE_COMPLEMENTARY_MODE(PWM1);/*SetPWMTimerclockprescaler*/PWM_SET_PRESCALER(PWM1,0,21);PWM_SET_PRESCALER(PWM1,2,21);PWM_SET_PRESCALER(PWM1,4,21);/*SetPWMTimerduty=120°*/PWM_SET_CMR(PWM1,0,21817);PWM_SET_CMR(PWM1,2,21817);PWM_SET_CMR(PWM1,4,32726);/*SetPWMTimerperiod*/PWM_SET_CNR(PWM1,0,65453);PWM_SET_CNR(PWM1,2,65453);PWM_SET_CNR(PWM1,4,65453);/*Setwaveformgeneration*//*PWM1CH0\2\4设置PRDPCTL0=0x01=>PWM周期点输出LOW*/PWM1->WGCTL0=(PWM1->WGCTL0&~PWM_WGCTL0_PRDPCTL0_Msk)|(PWM_OUTPUT_NOTHINGWGCTL0&~PWM_WGCTL0_ZPCTL0_Msk)|(PWM_OUTPUT_HIGHWGCTL0=(PWM1->WGCTL0&~PWM_WGCTL0_ZPCTL2_Msk)|(PWM_OUTPUT_HIGHWGCTL0=(PWM1->WGCTL0&~PWM_WGCTL0_ZPCTL4_Msk)|(PWM_OU

    PWM 嵌入式 国产芯片

    2022-04-19 2