在原子哥的ADC实验基础上,实行连续采集,并保存在txt文件中,每次保存一次数据,记录一下时间,发现一秒钟采集3个数据,保存效果如下:
2016-01-02 00:00:03 0.004v
2016-01-02 00:00:03 0.008v
2016-01-02 00:00:03 0.003v
2016-01-02 00:00:04 0.004v
2016-01-02 00:00:04 0.005v
2016-01-02 00:00:04 0.004v
2016-01-02 00:00:05 0.007v
2016-01-02 00:00:05 0.007v
2016-01-02 00:00:05 0.008v
想知道stm32自带的3个ADC采样速率是多少?
如何能提高采集速度?
看资料中提到转换速率可以达到0.41μs,采集数率可以达到μs级吗?
或者想实现高速度采集,必须外部新连接一个AD,来达到目的。
谢谢~~
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
[mw_shl_code=c,true]#define ADC_CHANNEL ADC_Channel_13
#define ADC123_CHANNEL_GPIO_CLK RCC_AHB1Periph_GPIOC
#define GPIO_PIN GPIO_Pin_3
#define GPIO_PORT GPIOC
#define DMA_CHANNELx DMA_Channel_0
#define DMA_STREAMx DMA2_Stream0
#define ADC_CDR_ADDRESS ((uint32_t)0x40012308)
u32 uhADCTripleConvertedValue=0;
//ADC三通道交错采样,官方资料称能达到8.4Msps,加入DMA中断之后实测约1.4M
//ADC1-CH13-PC3
//DMA2-CH0-STREAM0
//使用前需使用ADC_SoftwareStartConv(ADC1);
/*
● 第1 个请求:ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0]
● 第2 个请求:ADC_CDR[31:0] = ADC1_DR[15:0] | ADC3_DR[15:0]
● 第3 个请求:ADC_CDR[31:0] = ADC3_DR[15:0] | ADC2_DR[15:0]
● 第4 个请求:ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0]
*/
void ADC_TripleInterleaved(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
// NVIC_InitTypeDef NVIC_InitStructure;
/* Enable peripheral clocks *************************************************/
RCC_AHB1PeriphClockCmd( ADC123_CHANNEL_GPIO_CLK , ENABLE);
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_DMA2 , ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1 , ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC2 , ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC3 , ENABLE);
/* Configure ADC Channel 12 pin as analog input *****************************/
GPIO_InitStructure.GPIO_Pin = GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIO_PORT, &GPIO_InitStructure);
/* DMA2 Stream0 channel0 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_CHANNELx;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CDR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&uhADCTripleConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 3;//改动
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_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA_STREAMx, &DMA_InitStructure);
/* DMA2_Stream0 enable */
DMA_Cmd(DMA_STREAMx, ENABLE);
/* ADC Common configuration *************************************************/
ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_Interl;//改动
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2; //改动
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInit(&ADC_CommonInitStructure);
/* DMA mode 2 is used in interleaved mode in 12-bit resolutions *************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
/* ADC1 regular channel 13 configuration ************************************/
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel 13 configuration */
ADC_RegularChannelConfig(ADC1, ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* ADC2 regular channel 13 configuration ************************************/
ADC_Init(ADC2, &ADC_InitStructure);
/* ADC2 regular channel13 configuration */
ADC_RegularChannelConfig(ADC2, ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
/* ADC3 regular channel 13 configuration ************************************/
ADC_Init(ADC3, &ADC_InitStructure);
/* ADC3 regular channel13 configuration */
ADC_RegularChannelConfig(ADC3, ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
/* Enable DMA request after last transfer (multi-ADC mode) ******************/
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
/* Enable ADC1 **************************************************************/
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC2 **************************************************************/
ADC_Cmd(ADC2, ENABLE);
/* Enable ADC3 **************************************************************/
ADC_Cmd(ADC3, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn; //使能TIM中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //子优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能中断
NVIC_Init(&NVIC_InitStructure);
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE);
}[/mw_shl_code]
一周热门 更多>