Sunday, January 13, 2013

Digital control of an SRF05

The SRF05 is an ultrasonic sensor (datasheet). Connecting it to an Arduino has been done and is a staightforward task, for example see this site: http://luckylarry.co.uk/arduino-projects/arduino-sonic-range-finder-with-srf05/. To beef up my digital logic skills a bit, and play around with some old ICs I had, I wanted to control the SRF05 using only digital logic, and display some sort of visual representation of its output with LEDs.

This task was first broken down into a simple state machine:
  1. Generate a 10 us pulse to turn on the sensor
  2. Clear a shift register (HC595, datasheet)
  3. Count the length of the output signal of the sensor and set shift register bits appropriately
  4. Latch the shift register output to light up LEDs
For a system block diagram, schematic and some results, check out the rest of this post after the break.


The following block diagram shows the rough outline of the system:


To generate pulses and detect the rising and falling edges, 555 timers (datasheet) were selected. This allowed customizable length of output pulse from each system. The rising edge was used to clear the shift register, and falling edge used to latch the output and turn on the LEDs. The extra clock into the shift register timed the SRF05 output, so that the number of bits shifted into the shift register corresponded to the amount of time the SRF05 pulse lasted. Finally, to ensure that the shift register clock was synchronized to the start of the SRF05 output pulse, it was reset on the rising edge of the output pulse.

Debugging the circuit reminded me how much I used the oscilloscopes at school for this type of thing. Luckily I had an Arduino Duemilanov, and using the instructions in the Arduino Forum I setup a SUMP client on my Macbook pro and used my Arduino as a logic analyzer. It was a nice setup, allowing me to both debug my system, and observe its performance. Typically I would trigger on the input pulse from the SRF-05. Two sample captures are shown, at 20 and 100 KHz sample rates. One downside is that the Arduino can only store 1024 samples, so capturing at high frequencies does not allow the entire cycle to be monitored, while at low frequencies (as seen below), some pulses are too short and missed by the capturing system. 

20 KHz Logic Analyzer Capture

100 KHz Logic Analyzer Capture 

Some metrics of my system could be obtained from the logic captures. For example I had a 33 ms period, (datasheet recommends no faster than 30 ms) and a 10 us trigger pulse which was bang on. My SR_Latch was 34 us and SR_reset was 24 us. The datasheet for the HC595 suggested 75 ns was the shortest I could get away with, so I was well in range. One downside of my current implementation is that my first SR clock pulse is longer than it should be, because the 555 timer takes one cycle to stabilize. Starting this timer earlier (for example synchronizing with the trigger pulse) might be preferable.

Once I take some photos of the setup in action and draw up a schematic, I'll add them to this post.
An Eagle schematic is available for download here, or see the image below. Please let me know if you find errors.


To validate the system, I performed tests. A chair was positioned at a distance that just turned on the first LED (12.5 inches). Subsequently the chair was moved backwards and the position of each LED turning on was recorded (distances between LEDs were 10 inches, +- 0.5 inches).

System from a top view. Arduino is only used for providing power (+5V and gnd) and 5 green wires for measuring logic signals during debug. The 556 at the top of the screen provides the SR_clock and the trigger pulse for the SRF05. The next 556 provides edge detection of the SRF05 output pulse. The 3rd IC is a hex buffer. The two NPN transistors are used as logic inverters. My shift register (HC595) was a surface mount so I put it on a breakout board for ease of breadboarding. In this system, only 5 of 8 possible SR outputs (LEDs) were used, because I ran out of breadboard room. 

System in operation, showing 2 of the LEDs active (indicating an object in the 22" to 33" range).

No comments:

Post a Comment