关于定时器触发AD转换的问题,怎么让定时器的引脚不输出啊?

2019-03-23 20:11发布

我用的是stm32f107,是要用TIM1的1通道比较触发AD转换,但是我芯片外接的PHY也要使用TIM1的1通道所在引脚PA8所以,我只想让TIM触发AD转换,但是不让他使用引脚,怎么办啊,下面是我TIM的配置,请您指点下应该改哪几句,还有请问怎么使用TIM的TRGO触发AD啊,希望您能给一个示范的例子,谢谢了。
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  TIM_TimeBaseStructure.TIM_Period = 469;         
  TIM_TimeBaseStructure.TIM_Prescaler = 0;      
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
  
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;               
  TIM_OCInitStructure.TIM_Pulse = 200;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;         
  TIM_OC1Init(TIM1, &TIM_OCInitStructure);

DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_RegularConvertedValueTab;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  DMA_InitStructure.DMA_BufferSize = 6;
  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(DMA1_Channel1, &DMA_InitStructure);



  
  
  DMA_Cmd(DMA1_Channel1, ENABLE);

  DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);

  ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC2;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 6;
  ADC_Init(ADC1, &ADC_InitStructure);
  /*使用AD0,3,4  作为电压的ABC三相采集   使用引脚PA0,PA3,PA4*/
  ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_71Cycles5);   
  ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 2, ADC_SampleTime_71Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 3, ADC_SampleTime_71Cycles5);   
  ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 4, ADC_SampleTime_71Cycles5);   
  ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 5, ADC_SampleTime_71Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 6, ADC_SampleTime_71Cycles5);
  ADC_DMACmd(ADC1, ENABLE);


  ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 6;
  ADC_Init(ADC2, &ADC_InitStructure);

  ADC_RegularChannelConfig(ADC2, ADC_Channel_5, 1, ADC_SampleTime_71Cycles5);   
  ADC_RegularChannelConfig(ADC2, ADC_Channel_6, 2, ADC_SampleTime_71Cycles5);
  ADC_RegularChannelConfig(ADC2, ADC_Channel_7, 3, ADC_SampleTime_71Cycles5);   
  ADC_RegularChannelConfig(ADC2, ADC_Channel_8, 4, ADC_SampleTime_71Cycles5);   
  ADC_RegularChannelConfig(ADC2, ADC_Channel_9, 5, ADC_SampleTime_71Cycles5);
  ADC_RegularChannelConfig(ADC2, ADC_Channel_10, 6, ADC_SampleTime_71Cycles5);
  
  ADC_ExternalTrigConvCmd(ADC1, ENABLE);
  ADC_ExternalTrigConvCmd(ADC2, ENABLE);

  
  ADC_Cmd(ADC1, ENABLE);

  ADC_TempSensorVrefintCmd(ENABLE);

  ADC_ResetCalibration(ADC1);

  while(ADC_GetResetCalibrationStatus(ADC1));

  
  ADC_StartCalibration(ADC1);
  
  while(ADC_GetCalibrationStatus(ADC1));


  ADC_Cmd(ADC2, ENABLE);

     
  ADC_ResetCalibration(ADC2);
  
  while(ADC_GetResetCalibrationStatus(ADC2));

  
  ADC_StartCalibration(ADC2);

  while(ADC_GetCalibrationStatus(ADC2));  
    TIM_Cmd(TIM1, ENABLE);
   TIM_CtrlPWMOutputs(TIM1, ENABLE); 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。