我现在使用STM32F103VET6做一款设计,要求输出3路PWM,3路PWM的频率相同,相位相同,但占空比单独可调。如果1路PWM,可以开DMA控制,比较简单。但3路PWM单独控制占空比,开DMA就比较麻烦了。 我实验了一下TIM1_DCR 和TIM1_DMAR,试了2小时没有成功。有没有成功用过这个功能的? 上代码:DMA_InitTypeDef DMA_InitStructure; //for test u16 i; for(i=0;i<300;i++) { Sin[3*i] = (0x01&i)*2400+1200; Sin[3*i+2] = (0x01&i)*1200+1200; Sin[3*i+1] = 600; } RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); /* DMA1 Channel5 Config */ DMA_DeInit(DMA1_Channel5); //to DMAR DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->DMAR); DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Sin; //src DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_BufferSize = 900; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;//两种配置都试了 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//两种配置都试了 DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel5, &DMA_InitStructure); //CCR1 CCR2 CCR3 TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, 3); // TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE); /* TIM1 counter enable */ TIM_Cmd(TIM1, ENABLE); /* DMA1 Channel5 enable */ DMA_Cmd(DMA1_Channel5, ENABLE); /* TIM1 Main Output Enable */ TIM_CtrlPWMOutputs(TIM1, ENABLE); |
更正为TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, TIM_DMABurstLength_3Bytes);就好了。
评分
查看全部评分