Status update: Analog/pwm sonar usage on PixRacer is canceled, due to conflicts mentioned.
Although couldnt manage to use pwm sonar with 5 pwm, im going to create a PR for accepting 5 as pwm count for pixracer. This may be useful for someone.
Beside of givin up on pwm/analog, i managed to convert my sonar to an I2C sonar. This is how its done:
Sonar I have, is a HC-SR04 bundled with an ATMega328 board and a 12bit I2C DAC, to provide analog signal (turned out this is not pwm at all).
First of all, I desoldered the 6pin DAC to let me use I2C without it. Instead of the DAC, I soldered a small wire, connecting to the PixRacer I2C splitter.
Flashed the sonar module with a custom firmware measuring with NewPing library, then sends it over I2C when requested by the FMU.
The code is derived from what can be found here: http://diydrones.com/profiles/blogs/creating-an-i2c-sonar-for
This has a mode filter for sonar data. (I would like to create a small tutorial, github code, etc.. but for now please see this gdrive link: https://drive.google.com/folderview?id=0Bzz1m9D3igS9TGltYTAtYWVDUWs&usp=sharing )
Initial testing shows great results, although you need to know that HC-SR04 is
- probably the cheapest and worst performing sonar of all.
- its range is 0-200cm
- you wont get any reading when the floor is not hard enough to reflect sound OR you have about more than 10deg tilt.
Aaaaand thank you guys for the help provided so far.