Hi folks. This is my first post so I'd like to start by thanking everyone who's contributed to this site. It's a fantastic resource. Places like this remind you of humanity's positive side.
Anyway, I'm building a robot with my son. It's based on the $50 robot but will use the Maxbotics sonar for object avoidance.
So far I've built the circuit on a breadboard and it's fine. I'm hooked up to the PC through the AVRISP Mk II and can program the ATMega8. The servos are working fine. I'm familiar enough with C, if a bit rusty.
So now I just need to work with the sonar. I've been reading the ATMega8 and Maxbotics datasheets (the full one for the MCU) and scouring the forums here and anywhere else that seems useful.
My thoughts on how to use the sonar are as follows
1. Connect (other than the power) just the PW pin. From my reading of the datasheet this should default the RX pin to constant reading, which is fine by me.
2. PW would be wired to PC1(ADC1) (Pin 24 on the datasheet).
3. When PC1 goes high, start a timer.
4. When PC1 goes low, record timer value and reset.
5. Calculate distance based of the length of the pulse / 2.
6. Initiate a turn if the distance is below a threshold. (by the by; does anyone know why threshold only has one 'h' in the middle? It's not a joke, it's just puzzled me for a while)
Now, I'm completely prepared for all of that to be utterly wrong. Or should that be utterly prepared to be completely wrong? Hmm...
Sorry. Back to the plot.
I've read through tutorials and such like on timers and while they seem a wee bit complex, I'm sure I could get one going on it's own. What I've not found, is an example of using a timer the way I plan to; having it basically monitor a pin and react to what happens on it.
If my approach is right, can anyone help with this?
Many thanks in advance
Chris