2016-06-29 02:34 AM
Hi
I want to config TIM3 channel 2 for input pulses and generate pulse with the same frequency at PC0 of STM32F Its my code. Is it true?void TIM3CH1_Configuration(void)
{
/* TIM3 configuration: Input Capture mode ------------------------
The external signal is connected to TIM3 CH2 pin (PA.07),
The Rising edge is used as active edge,
------------------------------------------------------------ */
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_TimeBaseInitTypeDef TIM_BaseInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_DeInit(TIM3);
TIM_BaseInitStructure.TIM_Period = 1;
TIM_BaseInitStructure.TIM_Prescaler = 0;
TIM_BaseInitStructure.TIM_ClockDivision = 0;
TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_BaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM3, &TIM_BaseInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
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 = 0x0;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
/* Select the TIM3 Input Trigger: TI1FP1 */
TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);// TIM_TS_TI2FP2==>PA7 - TIM_TS_TI1FP1==>PA6
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
//TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM3, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
// /////////////////NVIC/////////////////////////////////
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);
// ///////////////////////////////////////////////////////
}
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_CC2) != RESET)
{
/* Clear TIM3 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);
GPIOC->BSRR = GPIO_Pin_0;
GPIOC->BRR = GPIO_Pin_0;
}
}
Regards
2016-06-29 03:38 AM
Hi,
There are so many code examples for what you are trying to do. Please check them.On a side note I would not place:TIM_DeInit(TIM3);
After:RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
And you must also configure the output pin of course and its corresponding peripheral clock (port).2016-06-29 04:40 AM
Hi,
I was configed PA7 as input trigger and PC0 as output and enabled the clock of both. Please give me the link of example for activating TIMx as input trigger on CHx. Regards2016-06-29 05:00 AM
Hi shams.hamed,
Timer examples in STM32Cube library package relevant to the device that you are using help you to build you target project. Check both ''TIM_InputCapture'' and ''TIM_TimerBase'' examples in at this path: STM32Cube_FW_F1_V1.4.0\Projects\STM3210E_EVAL\Examples\TIM A I have understood your need, you can identify the frequency of input signal and program you ouput with the same frequency value. -Hannibal-2016-06-29 05:02 AM
Assuming that I'm not going to build, test or evaluate incomplete code fragments, what are you currently observing with the provided code, and at what frequencies?
2016-06-29 05:02 AM
Hi,
You can refer to the example under :STM32Cube_FW_F1_V1.4.0\Projects\STM3210E_EVAL\Examples\TIM\TIM_InputCaptureThis example can help you as an implementation example to configure TIM peripheral and get inspiration to achieve you goal.Regards2016-06-29 05:18 AM
The OP is not using HAL, examples exist in the SPL and on the forum.
2016-06-29 07:20 AM
Thanks all
Finally I can config TIM3_CH2 as input trigger and I create output pulse with the same frequency as input pulse. It is the correct code.TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
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 = 0x0;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
/* Select the TIM3 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM3, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM3, TIM_IT_Trigger, ENABLE);
Its the Interrupt handler that make pulses.
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Trigger) != RESET)
{
/* Clear TIM3 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM3, TIM_IT_Trigger);
GPIOC->BSRR = GPIO_Pin_0;
GPIOC->BRR = GPIO_Pin_0;
}
}
Now, I want to trigger ADC with this input pulses. But without any interrupt handler.
How can I do this?
Regards