TIM3 timer period
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-21 6:46 AM
Hi,
I use STM32F427 chip. In my application, I am generating a 25.6 kHz signal using an external signal with 9.984 MHz. In order to do so, the calculation for timer period should be as follows; (9.984MHz / 25.6kHz) - 1 = 389. However, in the application the microcontroller generates the 25.6 kHz when I set the timer period to 390. I am confused by that, shouldn't I subtract 1 by 390 to obtain the timer period? Thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-21 7:11 AM
Yes, 390-1 should be the number, you'd want to consider how you are measuring the respective signals, and if the resynchronization of the input put might impact it.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-21 7:32 AM
I have a counter in my code to count the number of pulses that the timer generates. Also a PPS signal is connected to one of microcontroller pins which triggers an interrupt at each pulse. It turned out that when I check the number of pulses that counted between two PPS signals, it is exactly 25600 when period is 390, and it is 25666 when period is 389.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-21 7:33 AM
I have a counter in my code to count the number of pulses that the timer generates. Also a PPS signal is connected to one of microcontroller pins which triggers an interrupt at each pulse. It turned out that when I check the number of pulses that counted between two PPS signals, it is exactly 25600 when period is 390, and it is 25666 when period is 389.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-21 7:58 AM
Do you set directly the timer ARR register, or do you use some sort of ''library call'', which performs the decrement?
JW- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-22 3:45 AM
The piece of code that sets the timer period is below;
TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 390; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-22 7:23 AM
In reference manual it was written that the counter starts from 0 and counts to ARR value. I use PWM1 mode to generate the pulse, can this cause to counter to count from 1 to ARR value? It doesn't really make sense, but could this happen?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-22 7:49 AM
We would need to see all the relevant portions of your code to judge.
Can you measure the input and output frequency by some independent method, e.g. using a frequency counter? Or, alternatively, you can try two smaller ARR values to clearly see the difference - say, 10 and 11 - and have a look at the resulting waveform with an oscilloscope? JW- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-23 12:25 AM
I am posting the whole timer configuration code below;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; GPIO_InitTypeDef GPIO_InitStructure; TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; 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_UP ; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_TIM3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3); TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 390; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_ETRClockMode1Config(TIM3, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0); TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0); TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1); TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICFilter = 0; TIM_SelectHallSensor(TIM3, ENABLE); TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; TIM_OCInitStructure.TIM_Pulse = 15; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OC2Init(TIM3, &TIM_OCInitStructure);