*Dear mr:
I think he's going to use
Davantech SRF04 sensor or
Parallax PING))) sensor or for his measurement, that are used
here and
here respectively.
*Dear graceshin00:
Does your trouble mainly concerning to a measurement part, a display part or both?
The sensors above are intelligent modules. They begin measurement by asserting a start pulse and they return a result pulse which width indicates the measured distance. The pulseIn() function of Arduino returns measured width of a pulse.
You can measure the duration of the result pulse if you can handle a timer thoughtfully. Especially in Z8, a Gated Mode of a timer module is more useful for you to measure the duration.
If the timer module is unfamiliar to you, I weakly recommend you to use a software loop as the easiest way.
| Code: |
#define PING_BIT 0x01;
unsigned int pulseIn(void)
{
unsigned int count;
PAOUT &= ~PING_BIT;
// send a start pulse
PADD &= ~PING_BIT; // set PA1 to output
PAOUT |= PING_BIT; // set PA1 to high
for (count = 0; count < 999; count++); // please adjust this constant
// to make start pulse = 5us
PAOUT &= ~PING_BIT; // switch PA1 to low
// measure a result pulse
PADD |= PING_BIT; // switch PA1 to input
while ((PAIN & PING_BIT) == 0); // wait rising edge of a result pulse
for (count = 0; PAIN & 0x01; count++); // wait falling edge of the pulse
return count;
}
|
The function returns a value which is directly proportional to the pulse duration.
If you want your Z8 to run another task like a robot control, I strongly recommend you to use Gated Mode of the timer.
*Attn: everyone
Hi!
Does anyone know ultrasonic-based range sensor that outputs analog voltage related to the measured distance? As mr insisted, I also think it is the most easiest way to apply AN0191 if he want his Z8 to run another task while the measurement. I found
I2C-based range sensors, but I couldn't find an I
2C in Z8F042A.
*Attn: Zilog
I think there's no updated I
2C application note which is applicable to Encore XP series (premium peripheral set) -- e.g. ACK has been moved to I2CSTATE. I recently saw the question related to new I
2C
here.