Marcelo A. Segura

Cannot Aquire Pin Level with Processor Expert - MC9S08GT32CFB

Discussion created by Marcelo A. Segura on Dec 16, 2008
Latest reply on Jan 8, 2009 by Marcelo A. Segura

Description: Hello ! I'm using MC9S08GT32CFB on an ultrasonic flowmeter project with a PING ultrasonic sensor from parallax. This sensor uses the same pin for excitation and the pulse with time to target info. After excitation, it sends back a square pulse whose time witdth corresponds to the double time of flight to target. So, I'm using pin 24, named PING with output configuration, and pin 25, named LEVEL with input configuration. I placed a diode after pin 24. Using a periodic interrupt with 1 us period, I ask if the level on pin 25 is high, so as to increment a counter (named h), after the pulse finishes, I could get the number of microseconds with that counter. The counter barely increments to 17, when should expect 500 microseconds. I've also tried with time capture bean, though program crashes.
Something is wrong when reading the logical level of the pin.... Please, help !


void TI2_OnInterrupt(void)
{
  /* Write your code here ... */
 
  i = i++;
 
  PING_ClrVal();        // Set 0 on pin 24
                                 
  
  if (i == 100) {           // Wait 100 microsecs
   PING_SetVal();      // 1 on pin 24. Excitation pulse
  }

  if ( i > 110) {
 
         if( i < 25000) {
            if(LEVEL_GetVal()) {              // Check if pin 25 is high from ultrasonic echo
           h=h+1;                                    // Increase h if so.
            }
        }       
  }


  if (i == 25000) {                                  //   25 ms
    i = 0;                                                 //   Restart counters.
    h = 0;
  }   

}

 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-12-16 09:43 PM

Outcomes