cancel
Showing results for 
Search instead for 
Did you mean: 

Capacitor charge time capture

David.Cheng
Associate II

0690X0000098CksQAE.pngR is 10k, and c 1uf, vcc 3.1 , charge to full,

i then captured the rising edge, but time counter changes every time

static void TIM1_Config(void)
{
  TIM1_ICInit( TIM1_Channel_2, TIM1_ICPolarity_Rising, TIM1_ICSelection_DirectTI,
               TIM1_ICPSC_DIV2, 1);
  
  /* Enable TIM1 */
  TIM1_Cmd(ENABLE);
 
  /* Clear CC1 Flag*/
  TIM1_ClearFlag(TIM1_FLAG_CC2);
  
  //printf("xxbbbb  %u\n", TIM1_GetCapture2());
  
  printf("%02x \n", TIM1->SR1);
  /* wait a capture on CC1 */  // CC1IF
  while((TIM1->SR1 & TIM1_FLAG_CC2) != TIM1_FLAG_CC2);
  /* Get CCR1 value*/
  ICValue1 = TIM1_GetCapture2();
  
  printf("capture value %u\n", ICValue1);
  TIM1_ClearFlag(TIM1_FLAG_CC1);
  
}

2 REPLIES 2
Danish1
Lead II

A problem with this plan is that you don’t know at what voltage the stm32 will regard its input at logic high, at which point the timer-value will be captured.

This logic threshold can vary from chip-to-chip and also over temperature. And with that the proportion of the R-C time constant that you actually measure will change.

Perhaps it is time to step back and tell us what you are trying to achieve.

Hope this helps,

Danish

measure ​thermistor's R when capacitor is charged full (p1.2 270ohm gets high level )

0690X0000098FTpQAM.png