你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 5596|回复: 3

STM32F407的ADC问题

[复制链接]

11

主题

38

回帖

0

蝴蝶豆

新手上路

最后登录
2019-7-9
发表于 2012-9-26 13:24:26 | 显示全部楼层 |阅读模式
各位,大家好!
本人正在使用STM32F407的ADC,资料介绍其可以有2M的采样率,如果设置分辨率为8b,采样率应该还可以高的。
我在程序中使用了2个独立AD(即ADC1、ADC2),使用TIM1_CC1作为触发源,现在的问题是,TIM1最高只能设置到1MHz,即使设置到了2MHz,采样率也只有1M啊,这是怎么回事啊,请求大家帮助啊!!!
void ADC1_CH2_DMA_Config(void)
{
 ADC_InitTypeDef       ADC_InitStructure;
 ADC_CommonInitTypeDef ADC_CommonInitStructure;
 DMA_InitTypeDef       DMA_InitStructure;
 GPIO_InitTypeDef      GPIO_InitStructure;
 NVIC_InitTypeDef   NVIC_InitStructure;
 /* Enable ADC3, DMA2 and GPIO clocks ****************************************/
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
 /* DMA2 Stream0 channel2 configuration **************************************/
 //DMA_DeInit(DMA2_Stream0);
 DMA_InitStructure.DMA_Channel = DMA_Channel_0; 
 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
 DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1V[0];//(uint32_t)&ADC1ConvertedValue;
 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
 DMA_InitStructure.DMA_BufferSize = 512;//1;
 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//DMA_MemoryInc_Disable;
 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA_Mode_Normal;
 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(DMA2_Stream0, &DMA_InitStructure);
 DMA_Cmd(DMA2_Stream0, ENABLE);
 /* Configure ADC1 Channel2 pin as analog input ******************************/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 /* ADC Common Init **********************************************************/
 ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
 ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
 ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
 ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
 ADC_CommonInit(&ADC_CommonInitStructure);
 /* ADC1 Init ****************************************************************/
 ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;
 ADC_InitStructure.ADC_ScanConvMode = DISABLE;
 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//ENABLE;
 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
 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 channel2 configuration *************************************/
 ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_3Cycles);
 /* Enable DMA request after last transfer (Single-ADC mode) */
 ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
 NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x06;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
 /* Enable ADC1 DMA */
 ADC_DMACmd(ADC1, ENABLE);
 /* Enable ADC1 */
 ADC_Cmd(ADC1, ENABLE);
}
void ADC2_CH6_DMA_Config(void)
{
 ADC_InitTypeDef       ADC_InitStructure;
 ADC_CommonInitTypeDef ADC_CommonInitStructure;
 DMA_InitTypeDef       DMA_InitStructure;
 GPIO_InitTypeDef      GPIO_InitStructure;
 NVIC_InitTypeDef      NVIC_InitStructure;
 /* Enable ADC2, DMA2 and GPIO clocks ****************************************/
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
 /* DMA2 Stream2 channel6 configuration **************************************/
 //DMA_DeInit(DMA2_Stream2);
 DMA_InitStructure.DMA_Channel = DMA_Channel_1; 
 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC2_DR_ADDRESS;
 DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC2V[0];//(uint32_t)&ADC1ConvertedValue;
 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
 DMA_InitStructure.DMA_BufferSize = 512;//1;
 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//DMA_MemoryInc_Disable;
 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA_Mode_Normal;
 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(DMA2_Stream2, &DMA_InitStructure);
 DMA_Cmd(DMA2_Stream2, ENABLE);
 /* Configure ADC2 Channel6 pin as analog input ******************************/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 /* ADC Common Init **********************************************************/
 ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
 ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div6;
 ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
 ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
 ADC_CommonInit(&ADC_CommonInitStructure);
 /* ADC1 Init ****************************************************************/
 ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;
 ADC_InitStructure.ADC_ScanConvMode = DISABLE;
 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//ENABLE;
 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
 ADC_InitStructure.ADC_NbrOfConversion = 1;
 ADC_Init(ADC2, &ADC_InitStructure);
 /* ADC1 regular channel2 configuration *************************************/
 ADC_RegularChannelConfig(ADC2, ADC_Channel_6, 1, ADC_SampleTime_3Cycles);
 /* Enable DMA request after last transfer (Single-ADC mode) */
 ADC_DMARequestAfterLastTransferCmd(ADC2, ENABLE);
 NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x07;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 ADC_ITConfig(ADC2, ADC_IT_EOC, DISABLE);
 /* Enable ADC2 DMA */
 ADC_DMACmd(ADC2, ENABLE);
 /* Enable ADC2 */
 ADC_Cmd(ADC2, ENABLE);
}
void TIM_Config(void)
{
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_OCInitTypeDef  TIM_OCInitStructure;
 NVIC_InitTypeDef   NVIC_InitStructure;
 GPIO_InitTypeDef GPIO_InitStructure;
 RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
 /* Time Base configuration */
 TIM_TimeBaseStructure.TIM_Prescaler = 0;//0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseStructure.TIM_Period = 83;//1679; // Period = (168M/freq - 1)
 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 //TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
 
 /* Channel 1, 2,3 and 4 Configuration in PWM mode */
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 42;//839; // Pulse = 50*(Period-1)/100
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
 TIM_OC1Init(TIM1, &TIM_OCInitStructure);
 TIM_ARRPreloadConfig(TIM1, ENABLE);
 TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
  TIM_CtrlPWMOutputs(TIM1, ENABLE);
 
 NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM10_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x05;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 
 TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);//TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
 /* TIM1 counter enable */
 TIM_Cmd(TIM1, ENABLE);
}
回复

使用道具 举报

24

主题

591

回帖

0

蝴蝶豆

中级会员

最后登录
2020-12-2
发表于 2012-9-26 21:28:20 | 显示全部楼层

RE:STM32F407的ADC问题

更改成time0试试。
回复 支持 反对

使用道具 举报

11

主题

38

回帖

0

蝴蝶豆

新手上路

最后登录
2019-7-9
 楼主| 发表于 2012-9-27 09:42:22 | 显示全部楼层

RE:STM32F407的ADC问题

老大啊,有timer0吗?
回复 支持 反对

使用道具 举报

11

主题

38

回帖

0

蝴蝶豆

新手上路

最后登录
2019-7-9
 楼主| 发表于 2012-9-28 08:52:37 | 显示全部楼层

RE:STM32F407的ADC问题

大神都不在啊!寻求帮助啊
回复 支持 反对

使用道具 举报

关于 意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
13245底部标题123相同标题
12底部标题123相同标题
33333底部标题123相同序号
3435底部标题-无链接
关注我们
st-img 微信公众号
st-img 手机版