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

双ADC触发问题

[复制链接]
hanhan0519 提问时间:2012-7-4 21:36 /
/* Time base configuration */
 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
 TIM_TimeBaseStructure.TIM_Period = newFreq-1;//0x32;         
 TIM_TimeBaseStructure.TIM_Prescaler = 0x0;      
 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
 TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
 
 /* TIM8 TRGO selection */
 TIM_SelectOutputTrigger(TIM8, TIM_TRGOSource_Update);
 
 /* DAC channel1 Configuration */
 DAC_InitStructure.DAC_Trigger = DAC_Trigger_T8_TRGO;
 DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
 DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
 DAC_Init(DAC_Channel_1, &DAC_InitStructure);
 
 /* DAC channel2 Configuration */
 DAC_Init(DAC_Channel_2, &DAC_InitStructure);
 /* DMA2 channel4 configuration */
 DMA_DeInit(DMA2_Channel4);
 DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
 DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DualSine12bit;
 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;   //外设作为目的
 DMA_InitStructure.DMA_BufferSize = BufferSize;
 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_M2M = DMA_M2M_Disable;
 DMA_Init(DMA2_Channel4, &DMA_InitStructure);
 
 /* Enable DMA2 Channel4 */
 DMA_Cmd(DMA2_Channel4, ENABLE);
 
 /* Enable DAC Channel1 */
 DAC_Cmd(DAC_Channel_1, ENABLE);
 /* Enable DAC Channel2 */
 DAC_Cmd(DAC_Channel_2, ENABLE);
 
 /* Enable DMA for DAC Channel2 */
 DAC_DMACmd(DAC_Channel_1, ENABLE);
 /*以下为ADC触发*/
 /* Time base configuration */
 TIM_TimeBaseStructure.TIM_Period = BufferSize-1;
 TIM_TimeBaseStructure.TIM_Prescaler = 0;
 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 /* TIM2 channel2 configuration in PWM mode */
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;               
 TIM_OCInitStructure.TIM_Pulse = 8;
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;        
 TIM_OC2Init(TIM2, &TIM_OCInitStructure);
 TIM_SelectMasterSlaveMode(TIM8,TIM_MasterSlaveMode_Enable);// 主从模式
 TIM_SelectSlaveMode(TIM2,TIM_SlaveMode_External1); //从模式 上升沿作为计数脉冲
 TIM_SelectInputTrigger(TIM2,TIM_TS_ITR1);
 /* Enable TIM2 outputs */
    //TIM_CtrlPWMOutputs(TIM2, ENABLE);
 /* DMA1 Channel1 Configuration ----------------------------------------------*/
 DMA_DeInit(DMA1_Channel1);
 DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
 DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_RegularConvertedValueTab;
 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //外设作为源
 DMA_InitStructure.DMA_BufferSize = 64;
 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
 DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Word;
 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
 DMA_Init(DMA1_Channel1, &DMA_InitStructure);
  
 /* Enable DMA1 channel1 */
 DMA_Cmd(DMA1_Channel1, ENABLE);
 /* Enable DMA1 channel1 ITconfig */
 DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
 /* ADC1 configuration ------------------------------------------------------*/
 ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;  //ADC1 and ADC2 为同步规则模式
 ADC_InitStructure.ADC_ScanConvMode = DISABLE;   //单通道模式
 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;  //循换模式
 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;
 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
 ADC_InitStructure.ADC_NbrOfChannel = 1;
 ADC_Init(ADC1, &ADC_InitStructure);
 
 ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_55Cycles5); //规则
 ADC_DMACmd(ADC1, ENABLE);
// /* ADC2 configuration ------------------------------------------------------*/
 ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
 ADC_InitStructure.ADC_ScanConvMode = DISABLE;
 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
 ADC_InitStructure.ADC_NbrOfChannel = 1;
 ADC_Init(ADC2, &ADC_InitStructure);
 
 /* ADC1/2 regular channel12/13 configuration */  
 ADC_RegularChannelConfig(ADC2, ADC_Channel_13, 1, ADC_SampleTime_55Cycles5); //规则 7.38us
 
 /* Enable ADC2 external trigger conversion */
     ADC_ExternalTrigConvCmd(ADC2, ENABLE);
 /* Enable EOC interupt */
 ADC_ITConfig(ADC1, ADC_IT_EOC, 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));
  /* Enable ADC2 */
 ADC_Cmd(ADC2, ENABLE);
 /* Enable ADC2 reset calibaration register */  
 ADC_ResetCalibration(ADC2);
 /* Check the end of ADC1 reset calibration register */
 while(ADC_GetResetCalibrationStatus(ADC2));
 /* Start ADC2 calibaration */
 ADC_StartCalibration(ADC2);
 /* Check the end of ADC1 calibration */
 while(ADC_GetCalibrationStatus(ADC2));
 /* TIM8 enable counter */
 TIM_Cmd(TIM8, ENABLE);
 /* TIM2 enable counter */
 TIM_Cmd(TIM2, ENABLE);
程序大概是这样我通过DAC产生一个正弦波,DAC触发有定时器8完成,该正弦波一个周期打64个点,频率可调。打到第八个点的时候,启动双ADC转换,,每次转换1次操作,共采集64个数据。ADC触发有定时器2控制,设置捕获值为8。将定时器设置为主模式,定时器2设置为从模式。每次定时器8计数满是定时器2加1一次,当加到捕获值为8的时候启动ADC转换,程序不知道为什么进不了ADC中断函数,已经调了1个星期还是没有搞定。望高手帮我看看啊
 
收藏 评论1 发布时间:2012-7-4 21:36

举报

1个回答
果壳中的宇宙 回答时间:2012-9-13 15:46:09

回复:双ADC触发问题

没看见你设置NVIC寄存器的:
void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        /* Configure and enable ADC interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

}
调用它,试一试

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版