cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f103 adc cause triangular wave on input

Dan S
Associate
Posted on March 21, 2017 at 04:48

Hi,

I am doing a work with stm32f103 adc.The adc is triggered by tim8,and it works,but it cause a triangular wave on input.

what's wrong ?

The input pin is PA1,code is as below:

/* ADC1 init function */

void MX_ADC1_Init(void)

{

  ADC_ChannelConfTypeDef sConfig;

    /**Common config

    */

  hadc1.Instance = ADC1;

  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;

  hadc1.Init.ContinuousConvMode = DISABLE;

  hadc1.Init.DiscontinuousConvMode = DISABLE;

  hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T8_TRGO;

  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc1.Init.NbrOfConversion = 1;

  HAL_ADC_Init(&hadc1);

  /**Enable or disable the remapping of ADC1_ETRGREG:

  * ADC1 External Event regular conversion is connected to TIM8 TRG0

  */

  __HAL_AFIO_REMAP_ADC1_ETRGREG_ENABLE();

    /**Configure Regular Channel

    */

  sConfig.Channel = ADC_CHANNEL_1;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

}

void MX_TIM8_Init(void)

{

  TIM_ClockConfigTypeDef sClockSourceConfig;

//  TIM_SlaveConfigTypeDef sSlaveConfig;

  TIM_MasterConfigTypeDef sMasterConfig;

  htim8.Instance = TIM8;

  htim8.Init.Prescaler = 20;

  htim8.Init.CounterMode = TIM_COUNTERMODE_UP;

  htim8.Init.Period = 140;

  htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

  htim8.Init.RepetitionCounter = 0;

  HAL_TIM_Base_Init(&htim8);

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

  HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig);

/*

  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_DISABLE;

  sSlaveConfig.InputTrigger = TIM_TS_ITR0;

  HAL_TIM_SlaveConfigSynchronization(&htim8, &sSlaveConfig);

*/

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;

  HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig);

}

main()

{

.......

    MX_ADC1_Init();

    MX_TIM8_Init();

    HAL_ADC_Start_IT(&hadc1);

    HAL_TIM_Base_Start(&htim8);

......

 }
0 REPLIES 0