在同步模式下, ADC1 和 ADC2 同步采样的两个通道的需要设置为准确的相同采样时间
来个应用例子吧:
// ADC1 做电流检实时检测
ADC_DeInit(ADC1,&ADC_InitStructure);
ADC_InitStructure.ADC_Mode = ADC_MODE_REGSIMULT;
ADC_InitStructure.ADC_Mode_Scan = ENABLE; // 开启多通道扫描模式
ADC_InitStructure.ADC_Mode_Continuous = ENABLE; // 连续模式
ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;
ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
ADC_InitStructure.ADC_Channel_Number = 4;
ADC_Init(ADC1,&ADC_InitStructure);
ADC_RegularChannel_Config (ADC1,ADC_CHANNEL_2, 1, ADC_SAMPLETIME_7POINT5 ); // I
ADC_RegularChannel_Config (ADC1,ADC_CHANNEL_2, 2, ADC_SAMPLETIME_7POINT5 ); // I
ADC_RegularChannel_Config (ADC1,ADC_CHANNEL_2, 3, ADC_SAMPLETIME_7POINT5 ); // I
ADC_RegularChannel_Config (ADC1,ADC_CHANNEL_2, 4, ADC_SAMPLETIME_7POINT5 ); // I
// ADC2 做电流峰值,位置,温度,电压等检测
ADC_DeInit(ADC2,&ADC_InitStructure);
ADC_InitStructure.ADC_Mode = ADC_MODE_REGSIMULT;
ADC_InitStructure.ADC_Mode_Scan = ENABLE; // 开启多通道扫描模式
ADC_InitStructure.ADC_Mode_Continuous = ENABLE; // 连续模式
ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;
ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
ADC_InitStructure.ADC_Channel_Number = 4;
ADC_Init(ADC2,&ADC_InitStructure);
ADC_RegularChannel_Config (ADC2,ADC_CHANNEL_1, 1, ADC_SAMPLETIME_7POINT5 ); // I-PEAK
ADC_RegularChannel_Config (ADC2,ADC_CHANNEL_3, 2, ADC_SAMPLETIME_7POINT5 ); // POS
ADC_RegularChannel_Config (ADC2,ADC_CHANNEL_4, 3, ADC_SAMPLETIME_7POINT5 ); // NTC
ADC_RegularChannel_Config (ADC2,ADC_CHANNEL_5, 4, ADC_SAMPLETIME_7POINT5 ); // VDC
DMA_DeInit(DMA1_CHANNEL1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_RDTR_ADDRESS;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)(Adc12Result);
DMA_InitStructure.DMA_DIR = DMA_DIR_PERIPHERALSRC;
DMA_InitStructure.DMA_BufferSize = BuffSize;
DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PERIPHERALDATASIZE_WORD;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MEMORYDATASIZE_WORD;
DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR;
DMA_InitStructure.DMA_Priority = DMA_PRIORITY_MEDIUM;
DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE;
DMA_Init(DMA1_CHANNEL1, &DMA_InitStructure);
。。。。
ADC_SoftwareStartConv_Enable(ADC1,ENABLE);
ADC_SoftwareStartConv_Enable(ADC2,ENABLE);
这样DMA就直接读取到两个ADC同步转换的结果了。
|