用STM32做相位相差180的SPWM

2019-08-19 17:06发布

各位大虾,本人用的STM32F103RB产生两路SPWM,TIM1产生PWM,利用TIM2中断,更改PWM的占空比,
我定义了一个数组用来存放占空比值,这些数据是我从一个软件上得到的,
u16  Sin_Table[128]={0x80,0x86,0x8C,0x93,0x99,0x9F,0xA5,0xAB,0xB1,0xB6,
0xBC,0xC1,0xC7,0xCC,0xD1,0xD5,0xDA,0xDE,0xE2,0xE6,
0xEA,0xED,0xF0,0xF3,0xF5,0xF8,0xFA,0xFB,0xFD,0xFE,
0xFE,0xFF,0xFF,0xFF,0xFE,0xFE,0xFD,0xFB,0xFA,0xF8,
0xF5,0xF3,0xF0,0xED,0xEA,0xE6,0xE2,0xDE,0xDA,0xD5,
0xD1,0xCC,0xC7,0xC1,0xBC,0xB6,0xB1,0xAB,0xA5,0x9F,
0x99,0x93,0x8C,0x86,0x80,0x7A,0x74,0x6D,0x67,0x61,
0x5B,0x55,0x4F,0x4A,0x44,0x3F,0x39,0x34,0x2F,0x2B,
0x26,0x22,0x1E,0x1A,0x16,0x13,0x10,0x0D,0x0B,0x08,
0x06,0x05,0x03,0x02,0x02,0x01,0x01,0x01,0x02,0x02,
0x03,0x05,0x06,0x08,0x0B,0x0D,0x10,0x13,0x16,0x1A,
0x1E,0x22,0x26,0x2B,0x2F,0x34,0x39,0x3F,0x44,0x4A,
0x4F,0x55,0x5B,0x61,0x67,0x6D,0x74,0x7A,};

但是我中断服务函数写的不对,导致两路波形出来的是同相的SPWM波形,

void TIM2_IRQHandler(void)//¶¨ê±Æ÷ÖD¶Ïoˉêy
{   
        if(TIM_GetITStatus(TIM2,TIM_IT_Update)!=RESET)         //ÅD¶ÏêÇ·ñ¶¨ê±ÖD¶Ï
        {
        i=0;
        if(a==64)a=0;
        TIM1->CCR1=Sin_Table[a];
        TIM1->CCR2=Sin_Table[a+64];
        a++;
    }
        TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);//±ØDëÇå3yÖD¶Ï±ê־λ·ñÔòò»Ö±ÖD¶Ï
}       

才学STM32,很多不明白,求个各位大虾指点。


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。