AnsweredAssumed Answered

measure time for a puls with ADC

Question asked by ericsson.ola on Aug 29, 2012
Latest reply on Sep 4, 2012 by ericsson.ola
I need to measure the averige a signal is low using the ADC.
Is there a way to connet the adc to a timer? I have nott been able to figure that out, so insted I have tried the folowing...

Start systick at 1ms, that counts up a timer variable. (this works fine)

Then I have configured the ADC, I can see on my rt watch that the ADC is running. The values are apporx 0x300 and 0x60 for a low and hig signal.

I have then this litte loop, that check for 5 low signals, and uses the systick timer to measure high and low time's.

 while (Sample_Count != 5)
  {
    old_Sample = Sample;
    while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
    //Delay(5);
    Sample = ADC_GetConversionValue(ADC1);
    if (Sample + 100 < old_Sample) 
    {
      ReciveUnitTimeCounter=0; //Reset timer
     
    }
    if (Sample - 100 > old_Sample) 
    {
      ReciveUnitTime += ReciveUnitTimeCounter;
      Sample_Count++;
    }
  }
  ReciveUnitTime = ReciveUnitTime/5;

Problem is that I need to have a the delay after I have checked if conversion ready for it to work. This is strange... I can't understand whay, I need it since I'm wating on the ADC to complete if its not alredy finished...

I guess it would be better to use the ADC start stop a real timer, but I don't know any other way than this. (The +-100 value should be dynamic changed in the end)

Outcomes