最近在做FOC电机驱动,基于ST电机库2.0。用定时器1 CH4 触发ADC(双ADC同步注入模式)采集。在ADC配置中可以配置ADC触发注入组采集时间为
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4); //TIM1 CH4触发
然而在配置TIM1作为输出源时候,函数TIM_SelectOutputTrigger(),并没有TIM1 CH4作为输出触发源的选项
/**
* @brief Selects the TIMx Trigger Output Mode.
* @param TIMx: where x can be 1 to 8 to select the TIM peripheral.
* @param TIM_TRGOSource: specifies the Trigger Output source.
* This paramter can be one of the following values:
*
* - For all TIMx
* @arg TIM_TRGOSource_Reset: The UG bit in the TIM_EGR register is used as the trigger output (TRGO).
* @arg TIM_TRGOSource_Enable: The Counter Enable CEN is used as the trigger output (TRGO).
* @arg TIM_TRGOSource_Update: The update event is selected as the trigger output (TRGO).
*
* - For all TIMx except TIM6 and TIM7
* @arg TIM_TRGOSource_OC1: The trigger output sends a positive pulse when the CC1IF flag
* is to be set, as soon as a capture or compare match occurs (TRGO).
* @arg TIM_TRGOSource_OC1Ref: OC1REF signal is used as the trigger output (TRGO).
* @arg TIM_TRGOSource_OC2Ref: OC2REF signal is used as the trigger output (TRGO).
* @arg TIM_TRGOSource_OC3Ref: OC3REF signal is used as the trigger output (TRGO).
* @arg TIM_TRGOSource_OC4Ref: OC4REF signal is used as the trigger output (TRGO).
*
* @retval None
*/
void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource)
{
/* Check the parameters */
assert_param(IS_TIM_ALL_PERIPH(TIMx));
assert_param(IS_TIM_TRGO_SOURCE(TIM_TRGOSource));
/* Reset the MMS Bits */
TIMx->CR2 &= CR2_MMS_Mask;
/* Select the TRGO source */
TIMx->CR2 |= TIM_TRGOSource;
}
查看手册说明确实是存在TIM1 CH4触发ADC采集这个功能,但是TIM1中并没有找到相关标志位。。。。
请问各位,这个怎么搞??
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
路过,顺便回答一下,你说的其实是两码事。
启动前:
那个是在SVPWM_3ShuntInit里,这时还没有启动。这个配置是临时的。而且这个TIM_TRGOSource_Update只在UEV触发后才运行,不能比UEV提前运行。这时采样0电流补偿信号用的是SVPWM_3ShuntCurrentReadingCalibration(); 里面有个函数SVPWM_InjectedConvConfig,规定触发源是ADC_ExternalTrigInjecConv_T1_TRGO。
TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update)和电流采样触发没有关系。
启动时及启动后:
在后来启动过程中,有一个函数是SVPWM_3ShuntAdvCurrentReading,其中就配置了TIM1_CC4为触发源。这个是提前UEV运行的,此时CCR4=CNT。代码和注释如下
void SVPWM_3ShuntAdvCurrentReading(FunctionalState cmd)
{
if (cmd == ENABLE)
{
// Enable ADC trigger sync with CC4
//等价于:ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4); 因为 ADC_ExternalTrigInjecConv_T1_CC4=((u32)0x00001000)
ADC1->CR2 |= 0x00001000; //001: Timer 1 CC4 event,注意在这里配置了触发源CC4, 因为只配置了bit12, 在当前配置下,CC4或(=111)JSWSTART都是可能的,取决于bit14,13,而此时bit14=bit13=0
// Enable UPDATE ISR
// Clear Update Flag
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
}else
{
// Disable UPDATE ISR
TIM_ITConfig(TIM1, TIM_IT_Update, DISABLE);
// Sync ADC trigger with Update
//ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_TRGO);
ADC1->CR2 &=0xFFFFEFFF;
// ReEnable EXT. ADC Triggering
ADC1->CR2 |=0x00008000;
}
}
这样说的话,只要配置ADC触发源为TIM1 CH4,就可以触发ADC采集,与TIM_SelectOutputTrigger()配置无关?
问得好。
注意看SVPWM_3ShuntAdvCurrentReading(FunctionalState cmd)这个函数,里面有一句:
if (cmd == ENABLE)
{…}
Else
{…}
也就是说,如果你调用SVPWM_3ShuntAdvCurrentReading时,使用的参数不是ENABLE,那么这个时候是使用默认的TIM1->TRGO, 也就是UEV触发采样。即:要不要在UEV提前采样,是可以配置的,默认是在运行时才配置ENABLE的用TIM1->CCR4触发。
一周热门 更多>