Dear sir,
i want to measure the pulse width of input signal ranges from 100hz to 5000hz.
Below following is my code for initialization and measurement.
i did the programming in polling. not through interrupt.
in this program TIM3-CH3 capturing with wide range of variation in TIM3->CCR3. please help to get correct value in TIM3->CCR3
configured PB0(TIM3-CH3) in input with pull up/pull down Does it need to be changed
// Timer3 channel 3 initialization. RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // enable clock for TIM3 TIM3->CCR1 = 0x0000; //__TIM3_CCR1; // all CCRx default 0x0000 TIM3->CCR2 = 0x0000; //__TIM3_CCR2; // all CCRx default 0x0000 TIM3->CCR3 = 0x0000; //__TIM3_CCR3; // all CCRx default 0x0000 TIM3->CCR4 = 0x0000; //__TIM3_CCR4; // all CCRx default 0x0000 TIM3->CCMR1 = 0x0000; //__TIM3_CCMR1; // TIM3->SMCR = 0x0000; // Slave mode disabled TIM3->PSC = 0x02CF; //719 10usec accuracy TIM3->ARR = 0xFFF0; // set auto-reload TIM3->CR1 = 0x0000; // URS =0 -- update request for counter ov/underflow,UGbit,through slave TIM3->CR2 = 0x0080; // TI1S =1-- TIMX_CH1,CH2,and CH3 pins are connected to TI1 input(XOR) TIM3->CCMR2 = 0x0001; //CC3 config as input,IC3 mapped to TI3 TIM3->CCER = 0x0100; //CC3E capture/compare 3 enable void RpmMonitor(void) { unsigned short int x = 0,y = 0,z = 0; TIM3->CR1 &= 0x1110; // disable timer TIM3->SR = 0x0000; TIM3->CNT = 0x0000; TIM3->CR1 |= TIMX_CR1_CEN; // enable timer do x = TIM3->SR; while (x == 0x0000); if ( x == 0x0001) // if only counter overflow skip { TIM3->CR1 &= 0x1110; // disable timer z = 0x0000; } else //for CC3OF or CC3IF or TIF { TIM3->EGR |= 0x0001; //setting UG bit to clear Counter Value TIM3->SR = 0x0000; do x = TIM3->SR; while (x == 0x0000); TIM3->CR1 &= 0x1110; // disable timer if ( x == 0x0001) // if only counter overflow skip { z = 0x0000; } else { z = TIM3->CCR3; } } }
Still, you failed to explain the nature of the problem. What does not work as expected?
Tamir,
thanks for your reply. in the previous post itself i'd mentioned that The value measured from TIM3->CCR3 not fixed for fixed pulse width. its variation is very wide.
please help to get correct value in TIM3->CCR3
configured PB0(TIM3-CH3) in input with pull up/pull down. Does it need to be changed