2017-08-01 08:51 AM
STM32F429II
Hi everybody. I have a question about the
coexistence of OC and IC in the same Timer. For example, I have to use PH10 as OC and PH11 as IC. As Alternate function respectively CH1 and CH2 of Timer 5.
The IC works for PH11. When I try to set the OC even the IC stops working.
2017-08-01 09:21 AM
Then you do something wrong.
Read out and post the timer registers' content.
JW
2017-08-01 10:40 AM
>>
I have a question about the
coexistence of OC and IC in the same Timer.
Should work, processor will do what you tell it, show us what you're telling it.
2017-08-02 03:46 AM
You're both right :
void TIM5_Config(void)
{ /* GPIOH clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // used as Input Capture
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //GPIO_PuPd_NOPULL; GPIO_Init(GPIOH, &GPIO_InitStructure);GPIO_PinAFConfig(GPIOH, GPIO_PinSource11, GPIO_AF_TIM5); // Connect TIM pins to AF2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // used as Output Compare
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //GPIO_PuPd_NOPULL; GPIO_Init(GPIOH, &GPIO_InitStructure);GPIO_PinAFConfig(GPIOH, GPIO_PinSource10, GPIO_AF_TIM5); // Connect TIM pins to AF2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); // TIM5 clock enableTIM_ICInitTypeDef TIM_InputCaptureInitStructure;
TIM_InputCaptureInitStructure.TIM_Channel = TIM_Channel_2;
TIM_InputCaptureInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; TIM_InputCaptureInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_InputCaptureInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; // TIM_InputCaptureInitStructure.TIM_ICFilter = 0x0;TIM_ICInit(TIM5, &TIM_InputCaptureInitStructure);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit (&TIM_OCInitStructure);/* just use basic Output Compare Mode*/ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Active; /* set the initial match interval for CC1 */ TIM_OCInitStructure.TIM_Pulse = 20000; TIM_OC1Init (TIM5, &TIM_OCInitStructure);// Clear CC1 Flag
TIM_ClearFlag(TIM5, TIM_FLAG_CC1 ); // Clear CC2 Flag TIM_ClearFlag(TIM5, TIM_FLAG_CC2 );NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // Enable the TIM5 global Interrupt NVIC_Init(&NVIC_InitStructure); /* Select the slave Mode: Reset Mode */ TIM_SelectSlaveMode(TIM5, TIM_SlaveMode_Reset); TIM_SelectMasterSlaveMode(TIM5, TIM_MasterSlaveMode_Enable);//Enable CC2 interrupt
TIM_ITConfig(TIM5,TIM_IT_CC2 | TIM_IT_CC1, ENABLE); //EnableTIM5 TIM_Cmd(TIM5,ENABLE);}
2017-08-02 05:13 AM
Sorry I put even the timBase configuration. but nothing changed
static void TIM5_Config(void)
{// TIM_DeInit(TIM5 ); /* GPIOH clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // used as Input Capture GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //GPIO_PuPd_NOPULL; GPIO_Init(GPIOH, &GPIO_InitStructure);GPIO_PinAFConfig(GPIOH, GPIO_PinSource11, GPIO_AF_TIM5); // Connect TIM pins to AF2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // used as Output Compare
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //GPIO_PuPd_NOPULL; GPIO_Init(GPIOH, &GPIO_InitStructure);GPIO_PinAFConfig(GPIOH, GPIO_PinSource10, GPIO_AF_TIM5); // Connect TIM pins to AF2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); // TIM5 clock enableTIM_ICInitTypeDef TIM_InputCaptureInitStructure;
TIM_InputCaptureInitStructure.TIM_Channel = TIM_Channel_2;
TIM_InputCaptureInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; TIM_InputCaptureInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_InputCaptureInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; // TIM_InputCaptureInitStructure.TIM_ICFilter = 0x0;TIM_ICInit(TIM5, &TIM_InputCaptureInitStructure);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit (&TIM_OCInitStructure);// just use basic Output Compare Mode TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Active; // set the initial match interval for CC1 TIM_OCInitStructure.TIM_Pulse = 20000; TIM_OC1Init (TIM5, &TIM_OCInitStructure); TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 1; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
// Clear CC1 Flag
TIM_ClearFlag(TIM5, TIM_FLAG_CC1 ); // Clear CC2 Flag TIM_ClearFlag(TIM5, TIM_FLAG_CC2 );NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // Enable the TIM5 global Interrupt NVIC_Init(&NVIC_InitStructure); /* Select the slave Mode: Reset Mode */ TIM_SelectSlaveMode(TIM5, TIM_SlaveMode_Reset); TIM_SelectMasterSlaveMode(TIM5, TIM_MasterSlaveMode_Enable);//Enable CC2 interrupt
TIM_ITConfig(TIM5,TIM_IT_CC2 | TIM_IT_CC1, ENABLE);//| TIM_IT_CC1 //EnableTIM5 TIM_Cmd(TIM5,ENABLE);}
2017-08-02 05:37 AM
TIM_SelectSlaveMode(TIM5, TIM_SlaveMode_Reset);
Without having set TRGI source in TIMx_SMCR.TS, this defaults to Internal Trigger 0. Have you properly initialized the timer to which this links to output some reasonable TRGO? If not, this may hold this timer in reset indefinitely.
JW
2017-08-02 06:46 AM
Hello!
You did not initialize
TIM5 time base (TIM_TimeBaseInit) , prescaler , auto reload register..2017-08-02 08:37 AM
So If your intention is to have your timer as slave then do what
Waclawek.Jan
suggested .If not, call this TIM_SelectSlaveMode(TIM5, 0);or left it at it's default value