The HC-SR04 problem is solved!

Ok, a look at the HC-SR04 datasheet explains and solves the problem.

The speed of ultra sonic is 343 m/s. To measure a distance from 1m, it’s need round about 6 milliSeconds (actually there are two meter, one meter to the destination and one meter back).

So we need a special time for one measurement cycle and we are not able to make as many measurements per second as we want.
The HC-SR04 datasheet shows us the measurement cycle and the cycle time.
 
HC-SR04_datasheet

The cycle time must be less than 16 Hz. This is not possible with Timer0 and Timer2. Both timer are 8 Bit, and with a prescaler of 1024 we get as slowest frequence 61 Hz (16.000.000 / 1024*256). Therefore we need to use Timer1 if we want to measure permanently.

Here an example for a measurement function:

void Eyes_measurement() {
  digitalWrite(Eyes_Trigger,LOW);        // to be sure the Trigger is down
  delayMicroseconds(2);
  digitalWrite(Eyes_Trigger,HIGH);       // start a measurement
  delayMicroseconds(10);
  digitalWrite(Eyes_Trigger,LOW);        
  pulsdauer = pulseIn(Eyes_Echo,HIGH);   // get the result
  distance = pulsdauer / 58;             // value in cm
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s