This task was first broken down into a simple state machine:
- Generate a 10 us pulse to turn on the sensor
- Clear a shift register (HC595, datasheet)
- Count the length of the output signal of the sensor and set shift register bits appropriately
- 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.
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 in operation, showing 2 of the LEDs active (indicating an object in the 22" to 33" range). |
No comments:
Post a Comment