cancel
Showing results for 
Search instead for 
Did you mean: 

Remap STM32F103 timer input pin.

Anatoly Proshkin
Associate
Posted on April 27, 2018 at 12:09

Remap STM32F103 timer input pin.

Help me, please. I'm using stm32103 MCU (LQFP100) and I need PWM input

for measurement of duty cycle.

Pin PB0 (TIM3_CH3) is already in use, and I remap TIM3_CH3 to PC8.

And I do not get the TIM3_IRQHandler interrupt.

GPIOC Pin8: period 20 ms

Could anyone help me find the reason?

Regards,

Anprosh

fragments of init and interrupt source code

-------------------------------------------

volatile uint16_t period_capture = 0;

volatile uint16_t duty_cycle_capture = 0;

volatile uint8_t capture_is_first = 1;

volatile uint8_t capture_is_ready = 0;

//----------------------------------------------------------- init_timer_temp

void init_timer_temp(void)

{

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE); //TIM3_CH3 -> GPIOC Pin8

TIM_TimeBaseInitTypeDef timer_base;

TIM_TimeBaseStructInit(&timer_base);

timer_base.TIM_Prescaler = 24000 - 1;

TIM_TimeBaseInit(TIM3, &timer_base);

TIM_ICInitTypeDef timer_ic;

timer_ic.TIM_Channel = TIM_Channel_3;

timer_ic.TIM_ICPolarity = TIM_ICPolarity_Rising;

timer_ic.TIM_ICSelection = TIM_ICSelection_DirectTI;

timer_ic.TIM_ICPrescaler = TIM_ICPSC_DIV1;

timer_ic.TIM_ICFilter = 0;

// chan1 for period capture chan2 for duty cycle capture

TIM_PWMIConfig(TIM3, &timer_ic);

// select trigger source input1 (PC8)

TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1);

TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);

TIM_Cmd(TIM3, ENABLE);

NVIC_EnableIRQ(TIM3_IRQn);

}

//----------------------------------------------------------- TIM3_IRQHandler

void TIM3_IRQHandler(void)

{

if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)

   {

   TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);

   NVIC_DisableIRQ(TIM3_IRQn);

   // capture chan1 chan2

   period_capture = TIM_GetCapture1(TIM3);

   duty_cycle_capture = TIM_GetCapture2(TIM3);

   NVIC_EnableIRQ(TIM3_IRQn);

   if  (!capture_is_first)

   capture_is_ready = 1;

   capture_is_first = 0;

   if (TIM_GetFlagStatus(TIM3, TIM_FLAG_CC1OF) != RESET)

      {

      TIM_ClearFlag(TIM3, TIM_FLAG_CC1OF);

      // ...

      }

   }

}
0 REPLIES 0