cancel
Showing results for 
Search instead for 
Did you mean: 

Input capture - autoreload problem

cyrildufoing
Associate II
Posted on December 08, 2015 at 16:36

Hi

I try to set an input capture on a stm32f100(rbt6b) 

I set a counter period of 0xFFFF, the problem is that when I retrieve the value, I have the feeling that the timer is overflow at 255 and not 65535 as I mentioned in the configuration...

Someone can help me ? 

So the timer autoreload at 255 and not 65535...

#timers #discovery #capture #stm32f #input
4 REPLIES 4
Posted on December 08, 2015 at 17:25

May be you can show us some code for the initialization and reading of the timer, it might be more apparent from that what you're actually doing wrong.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cyrildufoing
Associate II
Posted on December 09, 2015 at 14:04

I use tim 2

.

/* TIM2 init function */

void MX_TIM2_Init(void)

{

  TIM_MasterConfigTypeDef sMasterConfig;

  TIM_IC_InitTypeDef sConfigIC;

  htim2.Instance = TIM2;

  htim2.Init.Prescaler = 24;

  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

  htim2.Init.Period = 65000;

  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

  HAL_TIM_IC_Init(&htim2);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);

  sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;

  sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;

  sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;

  sConfigIC.ICFilter = 0;

  HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2);

}

And here is my callback function :

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

if(HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_2)>= 0x58)

{

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

if(HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_2)>= 0xB0)

{

HAL_UART_Receive_IT(&huart1, data_rdm, 513);

rdm_flag = 1;

dmx_flag = 0;

}

HAL_UART_Receive_IT(&huart1, data_dmx, 513);

dmx_flag = 1;

rdm_flag = 0;

}

if (htim->Instance==TIM2)

{

//HAL_UART_Receive(&huart1, data_, 513, 1000);

__HAL_TIM_SetCounter(&htim2, 0); //reset counter after input capture interrupt occurs

}

}

When I send HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_2) by uart to my pc, the counter autoreload at 255

Posted on December 09, 2015 at 15:04

And what values are you seeing when you read the capture? And when in those sequences do you write zero into the counter?

Right now you have the counter tick from 0..0xFDE8, the capture should latch the current count, and you write 0 into the counter every time through the call back.

How exactly are you sending the 16-bit value back to the pc? If you don't zero the counter, do you see values >255 then?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cyrildufoing
Associate II
Posted on December 13, 2015 at 19:01

Hi,

Thank you a lot it works when I don't 0 the counter :)

Cyril