cancel
Showing results for 
Search instead for 
Did you mean: 

input capture issue on STM32F051, not on F100/F103

ingo
Associate II
Posted on February 02, 2014 at 10:50

Hello, my input capture code TIM1_CH3 (PA10) works very well on an F100 or F103, but not on the STM32F051. If i submit the debug session of the test code the GPIO and TIM1 register looks like ok. It looks like an misssing connection of the input trigger/capture impuls.

/*----*/

/* Test Timer1 Input Capture */

#ifdef STM32F0XX_MD

#include ''stm32f0xx.h''

#include ''stm32f0xx_rcc.h''

#include ''stm32f0xx_gpio.h''

#include ''stm32f0xx_tim.h''

#include ''stm32f0xx_misc.h''

#else

#include ''stm32f10x.h''

#include ''stm32f10x_rcc.h''

#include ''stm32f10x_gpio.h''

#include ''stm32f10x_tim.h''

#include ''misc.h''

#endif

/*---------------------------------------------------------------*/

/* STM32F051/STM32F100 ImpulsInput an PA10 [TIM1_CH3] */

#define IMPULSE_IN_PORT GPIOA

#define IMPULSE_IN_PIN GPIO_Pin_10

#define TIM_IMPULSE TIM1

/* Test Output on PA11 */

#define TEST_PORT GPIOA

#define TEST_PIN GPIO_Pin_11

#define SetTestPin TEST_PORT->BSRR = TEST_PIN

#define ResetTestPin TEST_PORT->BRR = TEST_PIN

/*---------------------------------------------------------------*/

void TIM_ConfigImp(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

#ifdef STM32F0XX_MD // no Funktion on STM32F051

/* GPIOA clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

/* TEST_PORT clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

/* TIM1 channel3 Capture Input configuration */

GPIO_InitStructure.GPIO_Pin = IMPULSE_IN_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(IMPULSE_IN_PORT, &GPIO_InitStructure);

/* output Pin */

GPIO_StructInit(&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Pin = TEST_PIN;

GPIO_Init(TEST_PORT, &GPIO_InitStructure);

/* Enable the TIM_IMPULSE global Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPriority = 0;

#else // function ok on STM32F100

/* TIM_IMPULSE clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

/* TEST_PORT clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

/* TIM_IMPULSE channel3 configuration : PB.08 */

GPIO_InitStructure.GPIO_Pin = IMPULSE_IN_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(IMPULSE_IN_PORT, &GPIO_InitStructure);

/* output Pin */

GPIO_StructInit(&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Pin = TEST_PIN;

GPIO_Init(TEST_PORT, &GPIO_InitStructure);

/* Enable the TIM_IMPULSE global Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

#endif

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

}

/*---------------------------------------------------------------*/

void TIMIMP_Init(void)

{

/* TIM Configuration */

TIM_ConfigImp();

/* ---------------------------------------------------------------------------

TIM1 configuration: Capture Input mode

--------------------------------------------------------------------------- */

TIM_ICInitTypeDef TIM_ICInitStructure;

TIM_DeInit(TIM1);

TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; // always Channel_3

TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

TIM_ICInitStructure.TIM_ICFilter = 0x00;

TIM_ICInit(TIM_IMPULSE, &TIM_ICInitStructure);

// notwendig???

TIM_SelectMasterSlaveMode(TIM_IMPULSE,TIM_MasterSlaveMode_Disable);

// set to 1us clock

TIM_PrescalerConfig(TIM_IMPULSE, (SystemCoreClock/1000000)-1, TIM_PSCReloadMode_Update);

/* TIM enable counter */

TIM_Cmd(TIM_IMPULSE, ENABLE);

/* Enable the CC3 Interrupt Request */

TIM_ITConfig(TIM_IMPULSE, TIM_IT_CC3, ENABLE); //***

}

/*---------------------------------------------------------------*/

void TIM1_CC_IRQHandler(void)

{

uint16_t captime;

SetTestPin;

if (TIM_GetITStatus(TIM_IMPULSE, TIM_IT_CC3))

{

captime = TIM_IMPULSE->CCR3;

/* Clear TIMx Capture compare interrupt pending bit */

TIM_IMPULSE->SR = (uint16_t)~TIM_IT_CC3;

}

ResetTestPin;

}

int main(void)

{

TIMIMP_Init();

while(1)

{

}

}

/*----*/

Thanks for help

Ingo (bad english speaking)
2 REPLIES 2
Posted on February 02, 2014 at 14:02

/* GPIOA Configuration: TIM2 on PA10 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect TIM1 pin - Alternate Function Assignment from Table 12 Data Manual */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_2); // PA10 TIM1_CH3

The pin muxing on the F0 series is different to the F1, you should review the reference manual and firmware library for examples, and acquaint yourself with the differences. They may be an F1 to F0 migration guide too.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ingo
Associate II
Posted on February 02, 2014 at 17:50

Many thanks, now it's working.

On STM32F1xx the alternate function is working only for output, on STM32F05x now on input too.

Ingo