求助 CH32V203 ADC在定時器觸發(fā)下采集PWM信號,在調(diào)試中發(fā)現(xiàn)1024個數(shù)據(jù)中時候數(shù)據(jù)不對 請問時啥原因

ADC引腳和PWM引腳引線短接,PWM頻率1K,定時器觸發(fā)12K

ADC通過定時器觸發(fā),接收完畢后通過DMA中斷打印數(shù)據(jù)

仿真調(diào)試中發(fā)現(xiàn)數(shù)據(jù)不正常(每1024個數(shù)據(jù)都有), (數(shù)據(jù)如下)

939:0,

940:1,

941:1,

942:0,

943:0,

944:0,

945:4095,

946:4095,

947:4095,

948:4095,

949:4095,

950:4095,

951:0,

952:4095,

953:4095,

954:4095,

955:0,

956:0,

957:0,

958:0,

959:0,

960:1,

961:4095,

962:4095,

963:4095,

964:4095,

965:4095,

966:4095,


現(xiàn)在不知是哪了的問題,請大家?guī)兔聪?謝謝? ??

外設(shè)配置代碼如下

void?DMA_ADC_1_Init(void)
{
????DMA_InitTypeDef?DMA_InitStructure?=?{0};
????NVIC_InitTypeDef??NVIC_InitStructure?=?{0};

????RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,?ENABLE);

????DMA_DeInit(DMA_ADC1_CHANNEL);
????DMA_InitStructure.DMA_PeripheralBaseAddr?=?ADC1_DR_Address;
????DMA_InitStructure.DMA_MemoryBaseAddr?=?(u32)&ADC_1_ARR;
????DMA_InitStructure.DMA_DIR?=?DMA_DIR_PeripheralSRC;
????DMA_InitStructure.DMA_BufferSize?=?DMA_ADC1_BufferSize?;
????DMA_InitStructure.DMA_PeripheralInc?=?DMA_PeripheralInc_Disable;
????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(DMA_ADC1_CHANNEL,?&DMA_InitStructure);

????NVIC_InitStructure.NVIC_IRQChannel?=?DMA1_Channel1_IRQn;
????NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0;
????NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?1;
????NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
????NVIC_Init(&NVIC_InitStructure);

????DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,?ENABLE);??????//使能傳輸完成中斷

????DMA_Cmd(DMA_ADC1_CHANNEL,?ENABLE);

}

void?TIM4_Configuration(void)
{
????TIM_TimeBaseInitTypeDef?TIM_TimeBaseStructure;
????TIM_OCInitTypeDef???????TIM_OCInitStructure;

????RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,?ENABLE);

????TIM_TimeBaseStructure.TIM_Period?=?USER_TIM_Period;
????TIM_TimeBaseStructure.TIM_Prescaler?=?USER_TIM_Prescaler;
????TIM_TimeBaseStructure.TIM_ClockDivision?=?TIM_CKD_DIV1;;
????TIM_TimeBaseStructure.TIM_CounterMode?=?TIM_CounterMode_Up;
????TIM_TimeBaseInit(TIM4,?&TIM_TimeBaseStructure);


????TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM1;
????TIM_OCInitStructure.TIM_OutputState?=?TIM_OutputState_Enable;
????TIM_OCInitStructure.TIM_OutputNState?=?TIM_OutputNState_Disable;
????TIM_OCInitStructure.TIM_Pulse?=?USER_TIM_Period/2000;
????TIM_OCInitStructure.TIM_OCPolarity?=?TIM_OCPolarity_Low;
????TIM_OCInitStructure.TIM_OCNPolarity?=?TIM_OCNPolarity_Low;
????TIM_OCInitStructure.TIM_OCIdleState?=?TIM_OCIdleState_Set;
????TIM_OCInitStructure.TIM_OCNIdleState?=?TIM_OCIdleState_Reset;
????TIM_OC4Init(TIM4,&TIM_OCInitStructure);

???TIM_Cmd(TIM4,?ENABLE);
}

void?ADC_Function_Init(void)
{
????ADC_InitTypeDef??ADC_InitStructure?=?{0};
????GPIO_InitTypeDef?GPIO_InitStructure?=?{0};

????RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,?ENABLE);
????RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,?ENABLE);

????RCC_ADCCLKConfig(RCC_PCLK2_Div8);/*12M*/

????GPIO_InitStructure.GPIO_Pin?=?ADC1_LOOP_1?|?ADC1_LOOP
????????????????????????????????|?ADC1_Light??|?ADC1_AC_Light;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AIN;
????GPIO_Init(GPIOA,?&GPIO_InitStructure);

????ADC_DeInit(ADC1);

????ADC_InitStructure.ADC_Mode?=?ADC_Mode_Independent;
????ADC_InitStructure.ADC_ScanConvMode?=?DISABLE;
????ADC_InitStructure.ADC_ContinuousConvMode?=?DISABLE;
????ADC_InitStructure.ADC_ExternalTrigConv?=?ADC_ExternalTrigConv_T4_CC4;
????ADC_InitStructure.ADC_DataAlign?=?ADC_DataAlign_Right;
????ADC_InitStructure.ADC_NbrOfChannel?=?ADC_1_NbrOfChannel;
????ADC_InitStructure.ADC_OutputBuffer?=?ADC_OutputBuffer_Disable;/*不用輸出BUFF*/
????ADC_InitStructure.ADC_Pga?=?ADC_Pga_1;/*不用放大增益*/

????ADC_Init(ADC1,?&ADC_InitStructure);

????ADC_RegularChannelConfig(ADC1,?ADC1_IN1_LOOP,1,?ADC_SampleTime_71Cycles5);//PWM

????ADC_Cmd(ADC1,?ENABLE);

????ADC_BufferCmd(ADC1,?DISABLE);?//disable?buffer
????ADC_ResetCalibration(ADC1);
????while(ADC_GetResetCalibrationStatus(ADC1));
????ADC_StartCalibration(ADC1);
????while(ADC_GetCalibrationStatus(ADC1));
????Calibrattion_Val?=?Get_CalibrationValue(ADC1);

????ADC_DMACmd(ADC1,?ENABLE);
????ADC_ExternalTrigConvCmd(ADC1,?ENABLE);

}

/*PWM*/
void?TIM1_PWMOut_Init(void)
{
????GPIO_InitTypeDef?GPIO_InitStructure={0};
????TIM_OCInitTypeDef?TIM_OCInitStructure={0};
????TIM_TimeBaseInitTypeDef?TIM_TimeBaseInitStructure={0};

????RCC_APB2PeriphClockCmd(?ADVANCE_TIM_CH1N_GPIO_CLK?|?RCC_APB2Periph_TIM1,?ENABLE?);

????GPIO_InitStructure.GPIO_Pin?=??ADVANCE_TIM_CH1N_PIN?;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????GPIO_Init(?ADVANCE_TIM_CH3N_PORT,?&GPIO_InitStructure?);

????TIM_TimeBaseInitStructure.TIM_Period?=?TIM1_PWMOut_Period;
????TIM_TimeBaseInitStructure.TIM_Prescaler?=?TIM1_PWMOut_Prescaler;
????TIM_TimeBaseInitStructure.TIM_ClockDivision?=?TIM_CKD_DIV1;
????TIM_TimeBaseInitStructure.TIM_CounterMode?=?ADVANCE_TIM_CounterMode;
????TIM_TimeBaseInit(?ADVANCE_TIM,?&TIM_TimeBaseInitStructure);

#if?(PWM_MODE?==?PWM_MODE1)
??TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM1;

#elif?(PWM_MODE?==?PWM_MODE2)
????TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM2;

#endif

????/*CH1N*/
????TIM_OCInitStructure.TIM_OutputNState?=?TIM_OutputNState_Enable;
????TIM_OCInitStructure.TIM_Pulse?=?TIM1_CCR1_Value;
????TIM_OCInitStructure.TIM_OCNPolarity?=?TIM_CH1N_OCPolarity;
????TIM_OCInitStructure.TIM_OCNIdleState?=?TIM_OCNIdleState_Reset;
????TIM_OC1Init(?ADVANCE_TIM,?&TIM_OCInitStructure?);

????//?主輸出使能,當(dāng)使用的是通用定時器時,這句不需要
????TIM_CtrlPWMOutputs(ADVANCE_TIM,?ENABLE?);

????/*TIM_OCPreload_Disable?后?更改CCP值后?馬上更新數(shù)據(jù)*/
????TIM_OC1PreloadConfig(?ADVANCE_TIM,?TIM_OCPreload_Disable?);


????TIM_ARRPreloadConfig(?ADVANCE_TIM,?ENABLE?);
}

void??DMA1_Channel1_IRQHandler(void)
{
????uint32_t?i;
????
????if(DMA_GetITStatus(DMA1_IT_TC1)!=RESET)
????{
?????????TIM_Cmd(?TIM4,?DISABLE?);
????????for(i?=?0;i

問題找到了,打了斷點(diǎn)后 輸出不正常,全速運(yùn)行就可以了,調(diào)試時打斷點(diǎn)也影響數(shù)組里的數(shù)據(jù)么?


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

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