老师您好 ,最近在修改程序,我把最后的/B路,也采用比较输出切换模式,程序编译没错,但是下载以后,用示波器观察发生波形不对,我把程序截图发上来,您帮忙给看一下,是哪里出了问题。
计算周期还是每记800个时钟单位为1个计数周期。【向上计数模式,ARR=800-1】附件有cubeMX的截图。
uint16_t Data1_to_Comp[]={199,699}; //ch1
uint16_t Data2_to_Comp[]={599,299}; //ch2
uint16_t Data3_to_Comp[]={399,99}; //ch3
uint16_t Data4_to_Comp[]={799,499}; //ch4
__HAL_TIM_DISABLE_OCxPRELOAD(&htim1, TIM_CHANNEL_1);
__HAL_TIM_DISABLE_OCxPRELOAD(&htim1,TIM_CHANNEL_2);
__HAL_TIM_DISABLE_OCxPRELOAD(&htim1, TIM_CHANNEL_3);
__HAL_TIM_DISABLE_OCxPRELOAD(&htim1, TIM_CHANNEL_4);
TIM_CCxChannelCmd(TIM1,TIM_CHANNEL_1, TIM_CCx_ENABLE);
TIM_CCxChannelCmd(TIM1,TIM_CHANNEL_2, TIM_CCx_ENABLE);
TIM_CCxChannelCmd(TIM1,TIM_CHANNEL_3, TIM_CCx_ENABLE);
TIM_CCxChannelCmd(TIM1,TIM_CHANNEL_4, TIM_CCx_ENABLE);
hdma_tim1_ch1.State = HAL_DMA_STATE_READY;
HAL_DMA_Start(&hdma_tim1_ch1,(uint32_t)Data1_to_Comp, (uint32_t)&TIM1->CCR1, 2);
__HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_CC1);
hdma_tim1_ch2.State= HAL_DMA_STATE_READY;
HAL_DMA_Start(&hdma_tim1_ch2, (uint32_t)Data2_to_Comp, (uint32_t)&TIM1->CCR2,2);
__HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_CC2);
hdma_tim1_ch3.State= HAL_DMA_STATE_READY;
HAL_DMA_Start(&hdma_tim1_ch3, (uint32_t)Data3_to_Comp,(uint32_t)&TIM1->CCR3, 2) ;
__HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_CC3);
hdma_tim1_ch4_trig_com.State= HAL_DMA_STATE_READY;
HAL_DMA_Start(&hdma_tim1_ch4_trig_com, (uint32_t)Data4_to_Comp,(uint32_t)&TIM1->CCR4, 2) ;
__HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_CC4);
特别说明一下这里的CH4 是hdma_tim1_ch4_trig_com,其他3个通道都是 hdma_tim1_chX
trig_com 这个尾椎是cubeMX里自己生成的名称。
附图有cubeMX配置截图
最后的2张照片,是我用手机拍照的,下载程序以后,产生的错误的波形,以及上次没改程序以后正确的波形。
|