STM32 多通道ADC采样,采用Timer1进行采样率控制(2)
- UID
- 1029342
- 性别
- 男
|
STM32 多通道ADC采样,采用Timer1进行采样率控制(2)
//设置指定ADC的规则组通道,设置它们的转化顺序和采样时间(取最大值)
ADC_RegularChannelConfig(ADC1, ADC_Channel_10 , 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11 , 2, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 4, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 5, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 6, ADC_SampleTime_239Cycles5);
/* Enable ADC1 DMA*/
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 external trigger */
ADC_ExternalTrigConvCmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* TIM1 main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
void DMA1_Channel1_IRQHandler(void)
{
static portBASE_TYPE xHigherPriorityTaskWoken=pdFALSE;
if(DMA_GetITStatus(DMA1_IT_TC1))
{
xSemaphoreGiveFromISR(xADCBinary,&xHigherPriorityTaskWoken);
ADC_count++;
DMA_ClearITPendingBit(DMA1_IT_GL1);
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken ); //立即切换上下文
}
} |
|
|
|
|
|