AnsweredAssumed Answered

comparator output as tim15 IC1 and TRGI

Question asked by korobeynikov.leonid on May 9, 2015
Latest reply on May 9, 2015 by Clive One
I'm using analog hall sensor in my application. One of its tasks is to measure rpm. I also calculate angle, so it's connected to ADC input + I internally connected it to COMP3-. Comp out, if I pass it to PA8 looks ok. Next I want to link it to TIM15IC1, take input capture and reset timer. So I'll have signal period in CCR1 without using interrupts.
In stmstudio i can see timer resets and counts from 0, but CCR1 only sometimes takes right value. It looks like there is race condition and capture happens after timer reset. I tried any possible IC, PWMIC and input trigger modes, lines commented.

/////////////////////////////////////////////////////////////////////////////////////////////////
////////////////                         COMP3/////////////////////////
     COMP_InitStructure.COMP_NonInvertingInput = COMP_NonInvertingInput_IO2;
     COMP_InitStructure.COMP_InvertingInput = COMP_InvertingInput_IO2;
     COMP_InitStructure.COMP_Output = COMP_Output_TIM15IC1;
     COMP_InitStructure.COMP_OutputPol = COMP_OutputPol_Inverted;
     COMP_InitStructure.COMP_BlankingSrce = COMP_BlankingSrce_None;
     COMP_InitStructure.COMP_Hysteresis = COMP_Hysteresis_High;
     COMP_InitStructure.COMP_Mode = COMP_Mode_HighSpeed;
     COMP_Init(COMP_Selection_COMP3, &COMP_InitStructure);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_7);
     COMP_Cmd(COMP_Selection_COMP3, ENABLE);


     /////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////////               TIM15          /////////////////////////
     TIM_TimeBaseStructure.TIM_Prescaler = 999;
     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
     TIM_TimeBaseStructure.TIM_Period = 0xffff;
     TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;     
     TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
     TIM_TimeBaseInit(TIM15, &TIM_TimeBaseStructure);
     //TIM_UpdateDisableConfig(TIM15, ENABLE);
     //TIM_UpdateRequestConfig(TIM15,TIM_UpdateSource_Regular);
     //TIM_SelectOnePulseMode(TIM15, TIM_OPMode_Single);
     TIM_ICInitTypeDef TIM_ICInitStructure;
     TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
     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 = 0x0;
     TIM_ICInit(TIM15, &TIM_ICInitStructure);
     TIM_SelectInputTrigger(TIM15, TIM_TS_TI1FP1);
     TIM_SelectSlaveMode(TIM15, TIM_SlaveMode_Reset);
     //TIM_SelectMasterSlaveMode(TIM15,TIM_MasterSlaveMode_Enable);
     TIM_Cmd(TIM15, ENABLE);

http://jpegshare.net/images/25/64/2564168d184940909eb8626485860ddf.png

Outcomes