10 Replies Latest reply on Apr 21, 2012 5:54 AM by eilremf_

    Sonar for Robot Navigation Issues

      Hey all,


      For the senior design project at my university, my group was assigned a robot that would serve as a wandering information kiosk for the campus.  I was placed in charge of sensor integration.  The sonars that our group decided to use can output an analog voltage level that corresponds to detected range or a pulse whose width corresponds to the detected range.  To get a handle on the PSoC 3 I created a quick proof of concept program that would take in the analog votlage level and convert it to a digital value.  To test it out I breadboarded the PSoC 3 and hooked it up to a power supply so I could easily and precisely change the voltage.  The problem is that no matter what I change the voltage level to, GetResult always returns a value that is approx 22,000 or 0x5850 in hex.


      So far in my troubleshooting efforts I have assumed, from talking to friends on similar projects, that the ADC returns a value that is scaled so that the resolution matches the acceptable input voltage range IE 0-6.14 volt range divided by 2^16 (16 bits of resolution). 




      Attached is my simple project so far,

        • 1. Re: Sonar for Robot Navigation Issues

          Hi RealChemist,




          You have made a mention that the sonars you have chosen can give output in the form of analog voltage level that corresponds to the detected range or a pulse whose width corresponds to detected range.


          I presume that you are testing out the former method. Is that right?




          After looking into the project, here are the following points that needs attention:




          1) The Conversion Mode of ADC has to be "Continuous" in this case as a single channel ADC is used.


          2) How are you measuring the ADC counts? You can use the character LCD while testing so that you can see visually the change in ADC counts when voltage is changed.


          3) SInce you are ADC with 16-bit resolution, use ADC_DelSig_1_GetResult32() API to get the ADC value and the variable can be unsigned integer (uint32) rather than integer as the ADC is in single ended mode.

          • 2. Re: Sonar for Robot Navigation Issues

            Yes the voltage level method is the one that I am using. 


            After making the changes you suggested it seems to work to voltages up to 3V. 




            0V   ~14 (decimal)


            1V    ~11000 (decimal)


            2V    ~23000 (decimal)


            3V    ~32000 (decimal)


            4V    ~35000 (decimal)


            5V    ~36000 (decimal)


            The acceptable input voltage is up to 6V so I do not know why it cannot detect anything much higher than 3V.  I uploaded the updated project.  Thanks for the help!

            • 3. Re: Sonar for Robot Navigation Issues

              Hi RealChemist,




              Which kit are you using?


              If you are using CY8CKIT-001 kit, please make sure that the power supply of the board is set to 5V.


              The input signal given to PSoC should never exceed the Vdda supply voltage. Hence, if you are powering up the device at 3.3V, then the maximum voltage which you can apply is 3.3V


              When you have chosen the Vref as internal 1.024V reference, and set the input range to 6 times Vref (6.144V), it means that theoritically if the input analog voltage reaches 6.114V, the ADC will give its full scale reading.


              However, you are limited by the power supply which is provided to PSoC. You can measure upto 5V, if you power up the device with 5V.

              1 of 1 people found this helpful
              • 4. Re: Sonar for Robot Navigation Issues

                I was given the PSoC 3 first touch starter kit by a teacher to use.  I tried researching this morning but couldnt find what pins I needed to use to supply the board with an external voltage.  There are 28 external I/O pins which didnt match what I found.  I went into the system tab to make sure VDDA was set to 5V and it was.  Mind you I am currently running it off USB so that I am able to debug it.

                • 5. Re: Sonar for Robot Navigation Issues

                  I could just run it at 3.3V and power the sonar with 3.3V volts as well and the sonar output will only go up to 3V.

                  • 6. Re: Sonar for Robot Navigation Issues

                    You may download the schematics for your first-touch-kit from the Cypress website at:  http://www.cypress.com/?docID=31295 


                    If possible, you ought to run your sonar with the same voltage as your PSoC runs.


                    In my opinion it is easier to measure a pulse-width than a voltage, especially when multiple sensors have to be attached.





                    1 of 1 people found this helpful
                    • 7. Re: Sonar for Robot Navigation Issues

                       Im assuming you would use a timer for that?  I looked into doing that but it seemed more complicated to implement.

                      • 8. Re: Sonar for Robot Navigation Issues

                        You may use a counter-module (UDB), Up-Counter, set the capture-input as needed (depends on the polarity of your signal to measure) enable(hardware only) the counter with your signal and set re-load on capture, TC and reset. Set the clock to Bus-Clock and the count input to a frequency giving a reasonable  resolution. Take care that the input-clock is synchron to bus-clock.


                        That's it


                        In the main-loop read the status of the timer and look for a captured value.


                        Very easy approach even when you need to handle multiple sensors which can be annoying with only one ADC





                        • 9. Re: Sonar for Robot Navigation Issues

                          Here is the data sheet for the sonar we are using FYI






                          According to the data sheet, is it safe to assume at the period of the output pulse is going to be 47ms + Pulse Width?  In the timing description it says that rangings are available every 47 ms.  Assuming this is correct, in order to use a counter I would have to be able to measure the period of measurement as well.  To clarify, I would have to  be able to determine how many clock periods went by while the counter was enabled (when the input signal is high)




                          Sorry for any silly questions.  Its been awhile since Ive programmed anything and I am far out of my comfort range considering my favorite courses in my curriculum were the semiconductor ones...

                          • 10. Re: Sonar for Robot Navigation Issues

                            Use a count-frequency of 27,211Hz which will give a resolution of 1/4 inch. 


                            Max measure is 37.338 ms giving a max count of about 1000.


                            Period is 50ms, so period value should be 1360. Seems as if a 16-bit counter is enough, set period to 30000, then capturing will always reset the counter, when counter overflows (there is a status-bit for that) sonar doesn't work.


                            But there is something in your device making everything easier, it has a built-in UART with which you can communicate. Voltages are ok, just drop a UART module and configure it as a receiver with a buffer. 





                            • 11. Re: Sonar for Robot Navigation Issues

                              Why not use a resistor ladder in the input? Same resistor values will will allow you to double the input voltage range.