2014-11-25 04:08 AM
Hi,
i want to capture time signal on PA0. I use a FreeRtos. My code: //Input capture mode TIM1->CR1 = 0x0; TIM2->CCMR1=0x0; TIM2->CCER =0x0; TIM2->CR1 |=TIM_CR1_CMS ; TIM2->CR1 |=TIM_CR1_DIR; TIM2->CCMR1 |=TIM_CCMR1_CC1S_0 ;// CC1 channel is configured as input, IC1 is mapped on TI1 TIM2->CCMR1 |=TIM_CCMR1_IC1F_0 |TIM_CCMR1_IC1F_1 ;//f SAMPLING N=8 //TIM2->CCER |=TIM_CCER_CC1P ;//OC1 active high //TIM2->CCMR1&=~TIM_CCMR1_IC1PSC ;//Prescaler TIM2->CCER|=TIM_CCER_CC1E; // Capture enabled //TIM2->CR1|=TIM_CR1_ARPE ; autoreload TIM2->CR1|=TIM_CR1_CEN; // TIM2 enable TIM2->DIER|=TIM_DIER_CC1IE;// interrupt enable TIM2->PSC = 23999; NVIC_EnableIRQ(TIM2_IRQn); AND void TIM2_IRQHandler(void) { if(TIM2->SR & TIM_SR_CC1IF) { TIM2->SR = ~TIM_SR_CC1IF; TIM2->CNT = 0; //Zeruję licznik. ECHO=TIM2->CCR1; } } My signal on PA0 is PWM : 200ms high and 500ms low. ECHO=TIM2->CCR1 is alway 700. Why? Thanks.2014-11-25 05:49 AM
> TIM1->CR1 = 0x0;
TIM1? Probably a typo...> TIM2->CR1 |=TIM_CR1_CMS ;
Why??? > My signal on PA0 is PWM : 200ms high and 500ms low. > ECHO=TIM2->CCR1 is alway 700. Why? Because you capture on rising edge only. See CC1NP/CC1P in TIMx_CCER. JW