This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

data stream detection

Hi All,,

My 8 bitcontroller is receiving a stream of pulses on one of its normal pins (ie., not an interrupt pin). The width of the pulses is either 300-microseconds or 1-milliseconds. So infact a binary 0 and 1 is being received in the form of pulse width.

If the pulse width is 300-microseconds then it is a logic zero.
If the pulse width is 1-milliseconds then it is logic one.

The controller receives 25 pulses. Now i need to test this received bit stream to see if it is equal to a constant value stored in the code. If they matches i would toggle an output pin.

Can someone throw some quick code to do this ..??

Thankzz & Bye
-Steve

Parents
  • Here is an untested idea.

    static long key;
    static unsigned char keyCount;
    
    void CallEvery250MicroSeconds()  //assume edge noise is < 250uS
    {
      enum { keyConst = 1234 }; //pick your number
    
      bit curPin;
      static bit lastPin;
      static int pulseCount;
      
      curPin = theInPin;
      ++pulseCount;
     
      if( curPin )
      {
         if( !lastPin ) // 0->1 edge
           pulseCount = 0;
    
         else
           ++pulseCount;
      } 
      
      else //!curPin
      {  
         if( lastPin ) // 1->0 edge
         {
            key =<< 1;
            if( pulseCount > 150*4 ) //would be < 4 for a "0" pulse
              key =| 1;
    
            ++keyCount;
            if( keyCount == 25 )
            {
              theOutPin = ( key == keyConst );
    
              key = 0;
              keyCount = 0;
            }
    
         }
      }
    
      lastPin = curPin;
    }    
    

Reply
  • Here is an untested idea.

    static long key;
    static unsigned char keyCount;
    
    void CallEvery250MicroSeconds()  //assume edge noise is < 250uS
    {
      enum { keyConst = 1234 }; //pick your number
    
      bit curPin;
      static bit lastPin;
      static int pulseCount;
      
      curPin = theInPin;
      ++pulseCount;
     
      if( curPin )
      {
         if( !lastPin ) // 0->1 edge
           pulseCount = 0;
    
         else
           ++pulseCount;
      } 
      
      else //!curPin
      {  
         if( lastPin ) // 1->0 edge
         {
            key =<< 1;
            if( pulseCount > 150*4 ) //would be < 4 for a "0" pulse
              key =| 1;
    
            ++keyCount;
            if( keyCount == 25 )
            {
              theOutPin = ( key == keyConst );
    
              key = 0;
              keyCount = 0;
            }
    
         }
      }
    
      lastPin = curPin;
    }    
    

Children