cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f3 discovery, timer input capture problem

esovo1
Associate II
Posted on September 29, 2014 at 15:25

Hei,

I'm sending a 3 us pulse to trigger the sensor. Than I have a time frame to reconfigure the pin in input capture, in order to measure the pulse. The pulse is working, but when I configurate the pin in input capture the pin is in a high output state.

Why is the pin HIGH

? Shouldn't it be low. Here is the code:

/* Includes ------------------------------------------------------------------*/
#include ''main.h''
/* strucutures ---------------------------------------------------------*/
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void Pin_Config(void);
void TIM_Config(void);
char a=0;
int main(void)
{
Pin_Config();
TIM_Config(); 
while (1);
}
void Pin_Config(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); // GPIOB clock enable
/*PA.01 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //PB6= TIM4_CH1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_2); //Connect TIM pins to AF2, PB6= TIM4_CH1
}
void TIM_Config(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //TIM4 clock enable
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 71; // 1M Hz
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
TIM_TimeBaseStructure.TIM_Period = 203;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* TIM4 PWM2 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_PWM1; //PWM1MODE: CNT>CCR1 -> OCREF==0 else OCREF==1 
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 200;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; // begining output is low
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; 
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
NVIC_Init(&NVIC_InitStructure); 
TIM_ClearFlag(TIM4, TIM_FLAG_CC1); // Clear the CC1 flags
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE); // Enable the TIM4 receive interrupt
TIM_Cmd(TIM4, ENABLE); //Enable TIM counter 
}
void TIM4_IRQHandler(void)
{
// Configure PWM Input Capture //
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; // PA6 TIM3_CH2
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //Falling, Rising
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV8; // every 8 rising edge is a capture
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
} 
// Unused functions that have to be included to ensure correct compiling
// ###### DO NOT CHANGE ######
// =======================================================================
uint32_t L3GD20_TIMEOUT_UserCallback(void)
{
return 0;
}
uint32_t LSM303DLHC_TIMEOUT_UserCallback(void)
{
return 0;
}
// ============================================================================================================================

#stm32 #tim #tim #stm32
12 REPLIES 12
esovo1
Associate II
Posted on October 08, 2014 at 13:44

No I haven't.... where is that documented?

esovo1
Associate II
Posted on October 10, 2014 at 11:06

hey, thanks a lot. It is working now like it should. I just changed the pin.

 Again, thanks.