STM32F2 Counting pulses using ETR and generating one pulse at max speed
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-02-26 11:20 PM
Posted on February 27, 2015 at 08:20
#timers #pwm-tim3 #one-pulse
Hi.
To start i'm using STM32F207I have a 15Mhz signal (that sometimes is enabled and sometimes it is not) connected to TIM3 ETR. I just want to count pulses and generate a pulse after few of this clocks (from 1 to 16 configured by software).To try it, I have set the TIM3 ETR (PD2 pin) as clock for TIMER 3, and it works (it starts counting). The code used is: RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; 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_Init(GPIOD, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_TIM3); TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1); TIM_SelectInputTrigger(TIM3,TIM_TS_ETRF); TIM_ETRClockMode2Config(TIM3,TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0); TIM_TIxExternalClockConfig (TIM3, TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Falling, 0) ;This is working ok as I said. Now I want to make a pulse faster than TIM3 clock if possible. Configuring TIM3 to count up from 0 to the current count limit TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 3; //Count limit TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); And now I have to set the output. I would like a pulse, so i tried the One-Pulse thing, but it is not working or not working as I wished. I have tried with PWM1/2 and Toggle. It counts right, but toggle is not ok since it generates a ''clock divider'', and pwm generates pulses at speed of the clock and thats not ok.I would need a small delay between the detection of the counting event and the rising of the output. This is what i tried: TIM_OCInitTypeDef TIM3_OC; TIM3_OC.TIM_OCMode = TIM_OCMode_PWM1; TIM3_OC.TIM_OutputState = TIM_OutputState_Enable; TIM3_OC.TIM_OCPolarity = TIM_OCPolarity_High; TIM3_OC.TIM_Pulse = 1; TIM_OC3Init(TIM3, &TIM3_OC); TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); TIM_SelectOnePulseMode(TIM3,TIM_OPMode_Repetitive); TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);In the image attached I explain what to I get and what do I need. I have seen a card done by another company using STM32F207, and same pins (PD2 clk input, PC7 pulse output and PC8 pulse output). Any idea or help would be welcomed.Thanks in advance
Labels:
- Labels:
-
TIM
This discussion is locked. Please start a new topic to ask your question.
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-02-27 5:06 AM
Posted on February 27, 2015 at 14:06
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-02-27 8:14 AM
Posted on February 27, 2015 at 17:14
Given you want a smaller pulse width than the input clock, you're going to have use a master/slave relationship using TIM3 to trigger a one-shot mode on a different timer clocking at a higher rate (system).
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-02-27 10:37 PM
Posted on February 28, 2015 at 07:37
Thanks for your answer clive.
Sync timers sounds good, I suppose that tim3 is slave, the new timer is master, setting the new timer to the faster speed possible as you said would be ok, but then, but then i see the same problem again... you have a counter and you want a pulse... I suppose that you need to make a PWM in the new timer (the only way to make a real pulse based in channels configuration). Another question, how do you connect it to the event generated by tim3, without using it as clock source... is it the way explained in page 397 of RM0033 or page 401 of RM0033?