Close

bat-eye stereo version

A project log for Project BASICS

A concerned effort to improve the basic standard of living in underdeveloped and developing countries.

Frank BussFrank Buss 06/10/2017 at 23:180 Comments

I wrote a new Arduino script, based on my improved mono version, for two sensors and two speakers:

https://github.com/DebarghaG/Project_Basics/blob/master/bateye-stereo.ino

There was no problem with the two sensors, they don't influence each other. The echo signal is only evaluated by the sensor which sent the trigger signal last.

Other changes compared to the mono version: The frequency gets higher now when the distance gets lower. I think this is better, because higher frequencies are associated with danger, and if you are about to crash into something, this is dangerous :-)

I also added a 10 cm offset: If it is below 10 cm, then the frequency is clamped to the max frequency. The idea behind this is that it is not useful to navigate that near, and with the offset you get higher resolution for distances greater than 10 cm.

And the frequency is now scaled logarithmically. The reason for this is, that the human ear is logarithmic as well. For lower frequencies, the frequency steps are smaller than for higher frequencies, but for the ear it sounds linear. The ranges and exponent has to be determined experimentally, see the fscale function call for this. For the old behaviour, only the 1000.0f and 150.0f values have to be swapped, for lower frequencies when nearer, and the exponent 7.0f has to be set to 0.0f for linear mapping.

Some notes about how the sound generator works: Because the Arduino tone-function doesn't work for 2 pins, I had to write my own tone generator. The idea is to use an accumulator and an increment value. The accumulator is 32 bit and the increment is calculated. This is an old idea, the general idea is described for example here. Because the accumulator increments are done in an interrupt with high frequency (10 kHz samplerate), I used fixed point arithmetic for it, and by testing the most significant bit of a 32 bit accumulator, I can create a square wave with high frequency resolution. Outside of the interrupt the timing is not critical and I can use float calculation.

The old SID of the C64 used this phase accumulator concept, too, see this video from Jeri Ellsworth for an explanation:

Discussions