A project to hopefully help my recently gone blind dog (Navi) stop running into things. It's basically a backup sensor that I plan to install on her face somewhere.
I removed the beeper from its breakout board and removed the IO pins from the sonar board. The beeper pins were perfectly spaced to fit between the ground and echo pins on the sonar board so I just soldered it directly in. The beeper pin indcated with a + is connected to echo. I also added some bits of wire to the "G", "S", "R", "V" pads on the sonar board. These are connected to the "GND", "SWIM", "RST", and "5.0V" pins on the programmer.
- libusb-dev required by stm8flash
- sdcc required to build for stm8
make init #get stm8flash and build it
make #build the songles program
make flash OBJECT=songgles #flash the songles program
- programming manual instruction set
- datasheet register map and interrupt vectors
- reference manual register configuration
- sonar
- sonar schematic
- stm8flash
- sdcc stm8 examples
- sdcc mixing c and assembly
-
I extracted the program installed on the sonar when I got it and used a reverse assembler to get to something I could read. I reverse engineered that a bit to learn how this stuff works and also give me a reference for getting this thing working with my own code. I'm not going to put any of that here...but it wasn't hard. I learend a lot.
-
The advertized range is 2-450cm. That's (roughly) 120-27150microseconds for a round trip. The sparkfun version claims an "8 cycle sonic burst". That leaves us 15 microseconds per burst if we want to get them all off before we start listening for the echo. I have no idea if that's a resonable amount of time. They have their prescaler (TIM1_PSCR) set to 3 and their auto-reload (TIM1_ARR) set to 48. 1/(16MHz/(3))*48 = 9microseconds. At the moment it's not clear to me if they're really using the timer to drive the emitter or if they're just looping. If this is the emitter it has a "nominal frequency" of 40kHz. 1/40kHz = 25 microseconds. So something doesn't add up. I'm going to go with a 25 microsecond period and 8 pulses since I don't care too much about close range.
Timeline:
start wall first echo
|-----3.3cm---->|-----3.3cm---->|
_ _ _ _ _ _ _ _
| |_| |_| |_| |_| |_| |_| |_| |_______________________________________
|25-|25-|25-|25-|25-|25-|25-|25-|
|-------------200ms-------------|
_ _ _ _ _ _ _ _
________________________________/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_______
|/|/|/|/|/|/|/|/|/|/|/|/|/|/|/|_______________________________________
.
. |
. |
. |
. |
. |______________________________________