想要使用高级定时器相互触发,同时用定时器触发三个ADC的多路规则通道和注入通道,可是写好程序后ADC总是未被触发看了几遍也找不到问题,请教一下大家
- ADC配置:
- ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_RegSimult; //adc三重模式
- ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
- ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
- ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
- ADC_CommonInit(&ADC_CommonInitStructure);
- // Channel-specific settings
- ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; //ADC分辨率双模式 12位精度
- ADC_InitStructure.ADC_ScanConvMode = ENABLE; //扫描模式
- ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
- ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Falling; //选择外部触发方式 下降沿触发
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T8_CC1; //选择TIM8_CC1触发规则组开始转换的外部事件
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //数据右对齐
- ADC_InitStructure.ADC_NbrOfConversion = 4; //指定使用规则通道组完成转换的次数 采样通道数
- ADC_Init(ADC1, &ADC_InitStructure);
- ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; //不使用外部触发 (多ADC模式中,外部事件触发必须仅触发主ADC,从ADC设置为软件触发)
- ADC_InitStructure.ADC_ExternalTrigConv = 0;
- ADC_Init(ADC2, &ADC_InitStructure);
- ADC_Init(ADC3, &ADC_InitStructure);
- // Enable DMA request after last transfer (Multi-ADC mode) 多ADC模式下 使能 源数据变化时开启DMA传输
- ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
- // Injected channels for current measurement at end of cycle
- ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4);
- ADC_ExternalTrigInjectedConvConfig(ADC2, ADC_ExternalTrigInjecConv_T8_CC2);
- ADC_ExternalTrigInjectedConvEdgeConfig(ADC1, ADC_ExternalTrigInjecConvEdge_Falling);
- ADC_ExternalTrigInjectedConvEdgeConfig(ADC2, ADC_ExternalTrigInjecConvEdge_Falling);
- ADC_InjectedSequencerLengthConfig(ADC1, 2); //设置注入通道长度 1-4
- ADC_InjectedSequencerLengthConfig(ADC2, 2);
- ADC_Channels();
-
- // Interrupt
- ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE); //使能ADC的JEOC中断源 注入转换中断屏蔽结束
-
- ADC_AutoInjectedConvCmd(ADC1, ENABLE);
- ADC_AutoInjectedConvCmd(ADC2, ENABLE);
-
- //Enable ADC_DMA
- ADC_DMACmd(ADC1, ENABLE);
- ADC_DMACmd(ADC2, ENABLE);
- ADC_DMACmd(ADC3, ENABLE);
- // Enable ADC1
- ADC_Cmd(ADC1, ENABLE);
- // Enable ADC2
- ADC_Cmd(ADC2, ENABLE);
- // Enable ADC3
- ADC_Cmd(ADC3, ENABLE);
复制代码
- 定时器配置
- void TIM1_Config(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
- TIM_DeInit(TIM1);
- TIM1->CNT = 0;
- // TIM1 clock enable
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
- // Time Base configuration
- TIM_TimeBaseStructure.TIM_Prescaler = 8399;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseStructure.TIM_Period = 9999;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0; //时钟分割
- TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
- TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
- // Channel 1, 2 and 3 Configuration in PWM mode
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
- TIM_OCInitStructure.TIM_Pulse = TIM1->ARR / 2;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //输出比较极性 高
- TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //互补输出极性 高
- TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; //空闲状态期间输出比较引脚状态
- TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
- TIM_OC4Init(TIM1, &TIM_OCInitStructure);
- TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
- TIM_CCPreloadControl(TIM1, ENABLE);
- TIM_ARRPreloadConfig(TIM1, ENABLE);
- // TIM1 Master and TIM8 slave
- TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);
- TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
-
- TIM_CCxCmd(TIM1, TIM_Channel_4, TIM_CCx_Enable);
- // Enable TIM1 and TIM8
- TIM_Cmd(TIM1, ENABLE);
- // Main Output Enable
- TIM_CtrlPWMOutputs(TIM1, ENABLE); //设置TIM1 的PWM输出使能
- }
- void TIM8_Config(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
- TIM_DeInit(TIM8);
- TIM8->CNT = 0;
-
- // ------------- Timer8 for ADC sampling ------------- //
- // Time Base configuration
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
- TIM_TimeBaseStructure.TIM_Prescaler = 8399;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseStructure.TIM_Period = 9999;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0;
- TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
- TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = TIM8->ARR / 2;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
- TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
- TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
- TIM_OC1Init(TIM8, &TIM_OCInitStructure);
- TIM_OC1PreloadConfig(TIM8, TIM_OCPreload_Enable);
- TIM_OC2Init(TIM8, &TIM_OCInitStructure);
- TIM_OC2PreloadConfig(TIM8, TIM_OCPreload_Enable);
- TIM_ARRPreloadConfig(TIM8, ENABLE);
- TIM_CCPreloadControl(TIM8, ENABLE);
- TIM_CtrlPWMOutputs(TIM8, ENABLE);
-
- TIM_SelectInputTrigger(TIM8, TIM_TS_ITR0); //选择输入触发源 ITR0
- TIM_SelectSlaveMode(TIM8, TIM_SlaveMode_Reset); //计数器从模式选择 所选的触发信号上升沿重新初始化
-
- TIM_ITRxExternalClockConfig(TIM8, TIM_TS_ITR0); //选择ITR0为触发源提供时钟
- TIM_CCxCmd(TIM8, TIM_Channel_1, TIM_CCx_Enable);
- TIM_CCxCmd(TIM8, TIM_Channel_2, TIM_CCx_Enable);
-
- TIM_ITConfig(TIM8, TIM_IT_CC1, ENABLE);
- TIM_ITConfig(TIM8, TIM_IT_CC2, ENABLE);
-
- TIM_Cmd(TIM8, ENABLE);
- }
复制代码
0
已退回10积分
|
1个回答
|
|
|