2014-07-01 12:10 AM
Hi,
i use the timer 10 to toggle a GPIO with a board STM32F429-DISCO.
int
init_timer
(
void
)
{
TIM_TimeBaseInitTypeDef
TIM_TimeBaseStructure;
NVIC_InitTypeDef
NVIC_InitStructure;
RCC_APB2PeriphClockCmd (
RCC_APB2Periph_TIM10
,
ENABLE
);
NVIC_InitStructure.NVIC_IRQChannel
=
TIM1_UP_TIM10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority
=
0
;
NVIC_InitStructure.NVIC_IRQChannelSubPriority
=
1
;
NVIC_InitStructure.NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init
(
&NVIC_InitStructure
);
// systemclock 180M BOARD STM32F429-DISCO
TIM_TimeBaseStructure.TIM_CounterMode
=
TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Prescaler
=
36000;
TIM_TimeBaseStructure.TIM_Period = 100;
TIM_TimeBaseInit
(
TIM10
,
&TIM_TimeBaseStructure);
TIM_Cmd
(
TIM10
,
ENABLE
);
TIM_ITConfig
(
TIM10
,
TIM_IT_Update
,
ENABLE
);
return
true
;
}
void
TIM1_UP_TIM10_IRQHandler
(
void
)
{
if
(
TIM_GetITStatus
(
TIM10
,
TIM_IT_Update
)
!=
RESET
)
{
TIM_ClearITPendingBit
(
TIM10
,
TIM_IT_Update
);
GPIO_ToggleBits(
GPIOG
,
GPIO_Pin_14); //toggle every 20 msec
}
}
I would like to modify the init_timer() function in order to generate an interrupt every 100 expernal pulse in the pin PA6 with the TIM10.
I have modified the function init_timer in this way
int
init_timer_new
(
void
)
{
TIM_TimeBaseInitTypeDef
TIM_TimeBaseStructure;
NVIC_InitTypeDef
NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel
=
TIM1_UP_TIM10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority
=
0
;
NVIC_InitStructure.NVIC_IRQChannelSubPriority
=
1
;
NVIC_InitStructure.NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init
(
&NVIC_InitStructure
);
RCC_APB2PeriphClockCmd (
RCC_APB2Periph_TIM10
,
ENABLE
);
// systemclock 180M BOARD STM32F429-DISCO
TIM_TimeBaseStructure.TIM_CounterMode
=
TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Prescaler
=
0
;
TIM_TimeBaseStructure.TIM_Period
=
100
;
TIM_TimeBaseInit
(
TIM10
,
&TIM_TimeBaseStructure);
/* Connect TIM10 - pins to AF */
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd
(
RCC_AHB1Periph_GPIOA,
ENABLE
);
/* GPIOA Configuration: TIM10 CH1 (PA6) */
GPIO_InitTypeDef
GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin
=
GPIO_Pin_6
;
GPIO_InitStructure.GPIO_Mode
=
GPIO_Mode_AF;
// Input/Output controlled by peripheral
GPIO_InitStructure.GPIO_Speed
=
GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType
=
GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd
=
GPIO_PuPd_UP;
// Button to ground expectation
GPIO_Init
(
GPIOA
,
&GPIO_InitStructure
);
GPIO_PinAFConfig
(
GPIOA
,
GPIO_PinSource6
,
GPIO_AF_TIM10
);
TIM_TIxExternalClockConfig
(
TIM10
,
TIM_TIxExternalCLK1Source_TI1
,
TIM_ICPolarity_Rising
,
0
);
TIM_Cmd
(
TIM10
,
ENABLE
);
TIM_ITConfig
(
TIM10
,
TIM_IT_Update
,
ENABLE
);
return
true
;
}
However, with this change it doesn�t work!!!
Is there any flaw in my code?
#timer #interrupt #stm32f4292014-07-01 05:39 AM
However, with this change it doesn?t work!!!
Is there any flaw in my code?
The biggest one would seem to be your random association of PA6 with TIM10_CH1, you can't just make this stuff up, you have limited options as described in the Data Sheet/Manual.2014-08-07 06:30 AM
2014-08-07 09:30 AM
Pretty sure that TIM13 can't use an external clock source.
TIM3, a quick blind build// STM32F429I-DISCO TIM3 (CH1 PA6) External Count Demo - sourcer32@gmail.com
#include ''stm32f429i_discovery.h''
//****************************************************************************
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* pin configuration */
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_DOWN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_TIM3); // PA6 TIM3_CH1
}
//****************************************************************************
void TIM3_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
int i;
/* Enable TIM3 Peripheral clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_Period = 100 - 1; // 100 (16-bit counter)
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);
TIM_Cmd(TIM3, ENABLE);
// Likely will interrupt initially unless we clear it
for(i=0; i<3; i++)
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
// Could also use compare mode, set the counter maximal and advance CCRx 100 ticks at a time
}
//****************************************************************************
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
/* Toggle LED3 */
STM_EVAL_LEDToggle(LED3);
}
}
//****************************************************************************
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM3 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//****************************************************************************
int main(void)
{
/* Initialize Leds mounted on STM32F429I-DISCO board */
STM_EVAL_LEDInit(LED3);
/* Turn on LED3 */
STM_EVAL_LEDOn(LED3);
NVIC_Configuration();
GPIO_Configuration();
TIM3_Configuration();
while(1); // Do not exit
}
//******************************************************************************
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d
'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
//******************************************************************************
2014-08-07 11:15 PM