關(guān)于CH573中TIMER2的PWMDMA有些問(wèn)題

void TMR2_IRQHandler(void)

{

? ? if(TMR2_GetITFlag(TMR1_2_IT_DMA_END))

? ? {

? ? ? ? TMR2_ClearITFlag(TMR1_2_IT_DMA_END);

? ? ? ? PFIC_DisableIRQ(TMR2_IRQn);

? ? }

}

我發(fā)現(xiàn)在DMA中斷函數(shù)里加上PFIC_DisableIRQ(TMR2_IRQn);后,仿真和下載都出了些問(wèn)題,把這句話(huà)注銷(xiāo)掉就沒(méi)有問(wèn)題??墒亲N(xiāo)這句話(huà)后,程序就會(huì)不停的進(jìn)DMA中斷,執(zhí)行不了其他事件,請(qǐng)問(wèn)該如何解決。


屏幕截圖 2023-11-15 102227.png

#include?"WS2811.h"

__attribute__((aligned(4)))?uint32_t?PwmBuf[130];
__attribute__((aligned(4)))?uint32_t?GRB[3]?=?{18,?18,?42};
uint8_t?color_count?=?0;

void?WS2811_Init(void)
{
????uint8_t?i;
????GPIOA_ModeCfg(GPIO_Pin_11,?GPIO_ModeOut_PP_20mA);
????TMR2_PWMCycleCfg(60);
????LED_Init();
????TMR2_DMACfg(ENABLE,?(uint16_t)(uint32_t)&PwmBuf[0],?(uint16_t)(uint32_t)&PwmBuf[129],?Mode_Single);
????TMR2_PWMInit(High_Level,?PWM_Times_1);
????TMR2_ClearITFlag(TMR1_2_IT_DMA_END);
????PFIC_EnableIRQ(TMR2_IRQn);
????TMR2_ITCfg(ENABLE,?TMR1_2_IT_DMA_END);
}

void?WS2811_Pattern(uint32_t?*GRB)
{
????GPIOA_ModeCfg(GPIO_Pin_11,?GPIO_ModeOut_PP_20mA);
????TMR2_PWMCycleCfg(60);
????LED_Color(GRB);
????TMR2_DMACfg(ENABLE,?(uint16_t)(uint32_t)&PwmBuf[0],?(uint16_t)(uint32_t)&PwmBuf[129],?Mode_Single);
????TMR2_PWMInit(High_Level,?PWM_Times_1);
????TMR2_ClearITFlag(TMR1_2_IT_DMA_END);
????PFIC_EnableIRQ(TMR2_IRQn);
????TMR2_ITCfg(ENABLE,?TMR1_2_IT_DMA_END);
}

void?LED_Color(uint32_t?*GRB)
{
????uint8_t?i;
????for(i?=?0+color_count*24;?i?<?8+color_count*24;?i++)
????{
????????PwmBuf[i]?=?GRB[0];
????}
????for(i?=?8+color_count*24;?i?<?16+color_count*24;?i++)
????{
????????PwmBuf[i]?=?GRB[1];
????}
????for(i?=?16+color_count*24;?i?<?24+color_count*24;?i++)
????{
????????PwmBuf[i]?=?GRB[2];
????}
????for(i?=?24+color_count*24;?i?<?130;?i++)
????{
????????PwmBuf[i]?=?0;
????}

}

void?LED_Init(void)
{
????uint8_t?i,?j;

????for(i?=?0;?i?<?7;?i++)
????{
????????PwmBuf[i]?=?18;
????}
????for(i?=?7;?i?<?15;?i++)
????{
????????PwmBuf[i]?=?42;
????}
????for(i?=?15;?i?<?23;?i++)
????{
????????PwmBuf[i]?=?18;
????}

????for(i?=?23;?i?<?130;?i++)
????{
????????PwmBuf[i]?=?0;
????}

????for(j?=?0;?j?<?4;?j++)
????{
????????for(i?=?23+j*24;?i?<?31+j*24;?i++)
????????{
????????????PwmBuf[i]?=?18;
????????}
????????for(i?=?31+j*24;?i?<?39+j*24;?i++)
????????{
????????????PwmBuf[i]?=?42;
????????}
????????for(i?=?39+j*24;?i?<?47+j*24;?i++)
????????{
????????????PwmBuf[i]?=?18;
????????}
????}
}

tmosTaskID?WS2811_TaskID;
tmosEvents?LED_ProcessEvent(tmosTaskID?task_id,?tmosEvents?events)
{
????uint8_t?*msgPtr;
????if(events?&?SYS_EVENT_MSG)
????{
????????msgPtr?=?tmos_msg_receive(task_id);
????????if(msgPtr)
????????????tmos_msg_deallocate(msgPtr);
????????return?events?^?SYS_EVENT_MSG;
????}

????if(events?&?WS2811_EVENT)
????{
????????WS2811_Pattern(GRB);
????????color_count++;
????????if(color_count?>=?5)
????????{
????????????color_count?=?0;
????????????if(GRB[0]?==?42)
????????????{
????????????????GRB[0]?=?18;
????????????????GRB[1]?=?42;
????????????}
????????????else?if(GRB[1]?==?42)
????????????{
????????????????GRB[1]?=?18;
????????????????GRB[2]?=?42;
????????????}
????????????else?if(GRB[2]?==?42)
????????????{
????????????????GRB[2]?=?18;
????????????????GRB[0]?=?42;
????????????}
????????}
????????tmos_start_task(WS2811_TaskID,?WS2811_EVENT,?MS1_TO_SYSTEM_TIME(500));
????????return?events?^?WS2811_EVENT;
????}
????return?0;
}

void?WS2811_Start(void)
{
????tmos_start_task(WS2811_TaskID,?WS2811_EVENT,?MS1_TO_SYSTEM_TIME(500));
}

__attribute__((interrupt("WCH-Interrupt-fast")))
__attribute__((section(".highcode")))
void?TMR2_IRQHandler(void)
{
????if(TMR2_GetITFlag(TMR1_2_IT_DMA_END))
????{
????????TMR2_ClearITFlag(TMR1_2_IT_DMA_END);
????????PFIC_DisableIRQ(TMR2_IRQn);
????}
}


你好,如果是使用PWM驅(qū)動(dòng)2812,是可以不使用中斷的,通過(guò)DMA發(fā)送數(shù)據(jù)。比如需要20個(gè)波形,則發(fā)送21個(gè)數(shù)據(jù),最后一個(gè)數(shù)據(jù)作為PWM的停止(全高或者全低)。

或者可以使用SPI的方式進(jìn)行驅(qū)動(dòng),我們有一個(gè)SPI驅(qū)動(dòng)代碼可以提供參考。


@TECH_Lpc

不使用中斷,是注銷(xiāo)掉這三句嗎?

????TMR2_ClearITFlag(TMR1_2_IT_DMA_END);
????PFIC_EnableIRQ(TMR2_IRQn);
????TMR2_ITCfg(ENABLE,?TMR1_2_IT_DMA_END);

可是注銷(xiāo)掉后,這PWM不會(huì)再工作了。用邏輯分析儀的話(huà),發(fā)現(xiàn)并沒(méi)有波形。

至于SPI的話(huà),因?yàn)橐呀?jīng)用掉SPI去驅(qū)動(dòng)ST7789了,所以才會(huì)使用PWM來(lái)驅(qū)動(dòng)WS2811。


你好,可參考:

image.png


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频