stm32f103 - timer3 unwanted overflow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-15 02:37 AM
Posted on September 15, 2015 at 11:37
Hello, i am trying to measure a rc pwm signal (from a single channel of a rc receiver)
This signal has a total period of 20ms (50 hz) The active pulse is between 900us and 2000us width Strangely i have a similar aproach with a stm32f4 device where i have no overflow of the ''delta'' value So my APB clock is 60mhz, the prescaled value is 59 ( 60-1) , therefore my counter ticks at 1us rate And since i have 16bit timer only, i filed the period register with 0xFFFF (65535) This gives me a 26 hz ... normaly i am not intrested in this frequency ( or should i? )TIM_TimeBaseStructure.TIM_Prescaler = 59;
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
// configure Timer3 Channel 3
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
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 = 0x00;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
// configure Timer3 Channel 4
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x00;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
// Configure Timer2 Interupt Sources */
// TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE); // enable Channel 3 capture interupt
TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE);// enable Channel 4 capture interupt
TIM_SelectInputTrigger(TIM3,TIM_TS_TI1FP1);
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
//enable tim2 irq
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =6;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM3, ENABLE); // Start the Timer
And bellow is my timer3 handler
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3, TIM_IT_CC3) == SET){ // If Low-Hi transition occured
TIM_ClearITPendingBit(TIM3, TIM_IT_CC3);
capHi = TIM_GetCapture3(TIM3); // Get timer counts for Period
GPIO_SetBits(GPIOA,red);
GPIO_SetBits(GPIOB,GPIO_Pin_2);
GPIO_ResetBits(GPIOB,GPIO_Pin_2);
}
if(TIM_GetITStatus(TIM3, TIM_IT_CC4) == SET){ // If Hi-Low transition occured
TIM_ClearITPendingBit(TIM3, TIM_IT_CC4);
capLo= TIM_GetCapture4(TIM3); // Get timer counts for Period
GPIO_ResetBits(GPIOA,red);
GPIO_SetBits(GPIOB,GPIO_Pin_10);
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
}
delta=capLo-capHi; // get the actual high period of the signal
/***** send the values to serial *****/
sprintf(txt,''%u'',capHi);
USART_Puts('' capHi: '');
USART_Puts(txt);
sprintf(txt,''%u'',capLo);
USART_Puts('' capLo: '');
USART_Puts(txt);
sprintf(txt,''%u'',delta);
USART_Puts('' delta: '');
USART_Puts(txt);
USART_Puts(''\r\n'' );
}
And bellow i have ploted some serial data , the red values are the bad ones, and i want to know is there a way to overcome this issue?
capHi: 27149 capLo: 28140 delta: 991
capHi: 15668 capLo: 16659 delta: 991
capHi: 4188 capLo: 52696 delta:
48508
capHi: 40226 capLo: 41217 delta: 991 capHi: 28748 capLo: 29738 delta: 990 capHi: 64784 capLo: 239 delta: 991 capHi: 53301 capLo: 54292 delta: 991 capHi: 23801 capLo: 24791 delta: 990 capHi: 12319 capLo: 13310 delta: 991 capHi: 838 capLo: 1828 delta: 990 capHi: 36874 capLo: 37865 delta: 991 capHi: 25394 capLo: 26384 delta: 990 capHi: 61431 capLo: 62422 delta: 991 capHi: 49950 capLo: 50941 delta: 991 capHi: 38467 capLo: 21440 delta:48509
capHi: 8969 capLo: 9960 delta: 991 capHi: 63025 capLo: 64016 delta: 991 capHi: 33528 capLo: 34518 delta: 990 capHi: 22047 capLo: 23037 delta: 990
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-15 06:58 AM
Posted on September 15, 2015 at 15:58
>
/***** send the values to serial *****/
In an ISR? It's a bad idea. How long does this take? If it would be short enough, you'd see only one of the two values changed in each message.
JW