-
1. Re: PSoC4: UltraSonic Sensor based Distance Measurement
JoMe_264151 Apr 17, 2015 3:57 AM (in response to user_264716)Hi Shaunak,
are you facing a problem with the display, the formatting of the result or the values you compute?
Which hardware does the project run on?
Some comments:
It is always advisable to have a main loop running at a constant frequency instead of a loop that is governed by external hardware. In this case: the smaller the distance, the faster the loop will run. To avoid this and to shorten software, use a PWM that generates a 10µs pulse at the desired frequency of 40Hz, trigger the sensor with that pulse, clear/load the timer and so on.
Your documentation is very good, although I didn't find (maybe overlooked) the underlying hardware specs (board: Kit or custom)
Your program structure may be better using an initialization part, a sensor handler, a display handler and a handler for calculating distance. For more accuracy: Largest error influence comes from temperature, wikipedia helds a formula for that and the chip has got a raw measurement capability. Especially in your country where environment temps are comparably high the difference betweein conditioned inside and on the street may be remarkable.
Bob
-
2. Re: PSoC4: UltraSonic Sensor based Distance Measurement
user_264716 Apr 17, 2015 4:30 AM (in response to user_264716)Hi Bob
Thank you for the reply. I just debugged the code and found that the code gives me distance when I "watched" the variable in debugging environment. It means the LCD output is not coming properly. I checked other projects with LCD, they are running well.
Regards
Shaunak
-
3. Re: PSoC4: UltraSonic Sensor based Distance Measurement
JoMe_264151 Apr 17, 2015 5:02 AM (in response to user_264716)Anything on the LCD? Is the "Distance =" showing? -> Hardware issue.
else
There is some peculiar about "print float in PSoC4", have a keyword search (at top of this page) for that and take the newer infos from Robyn.
Bob
-
4. Re: PSoC4: UltraSonic Sensor based Distance Measurement
user_264716 Apr 17, 2015 5:10 AM (in response to user_264716)Hi Bob
I got it working by putting integer %d in sprintf instead of float %f. I did not know that float does not work with sprintf.
Regards
Shaunak
-
5. Re: PSoC4: UltraSonic Sensor based Distance Measurement
DaKn_263916 Apr 17, 2015 5:27 AM (in response to user_264716)You must enable the nano library to get the sprintf() working -
http://www.cypress.com/?id=4&rID=87354 newlib-nano
Regards, Dana.
-
6. Re: PSoC4: UltraSonic Sensor based Distance Measurement
user_264716 Apr 17, 2015 6:06 AM (in response to user_264716)Dana
I did the steps given on the above link to get sprintf working with float, but I am afraid it is still not working.
Regards
Shaunak
-
7. Re: PSoC4: UltraSonic Sensor based Distance Measurement
JoMe_264151 Apr 17, 2015 6:12 AM (in response to user_264716)I am using the Creator 3.2 early access and there is in the project settings an item to enable float formatting. This option costs you 14kB of flash. If that is too much, you may find some libraries using quite less program memory. Alternatively convert the float yourself by converting the fractional part separately as integer with the required precision
Intpart = (uint)MyFloat;
FracPart = (uint)((MyFloat-Intpart)*1000);
sprintf(Buffer,"%d.%d",Intpart,FracPart);
Will give your MyFloat converted with 3 decimal places. You must care for the sign separately.
Bob
-
8. Re: PSoC4: UltraSonic Sensor based Distance Measurement
user_264716 Apr 17, 2015 6:25 AM (in response to user_264716)Hi Bob
This method works quite well. Thank you.
Regards
Shaunak
-
9. Re: PSoC4: UltraSonic Sensor based Distance Measurement
JoMe_264151 Apr 17, 2015 6:44 AM (in response to user_264716)You are always welcome, Shaunak!
Bob
-
10. Re: PSoC4: UltraSonic Sensor based Distance Measurement
DaKn_263916 Apr 17, 2015 7:51 AM (in response to user_264716)I posted a minor update to project in PSOC 3 forum,
eg. a delay to allow sensor to start up. Seems to
be working fine with or without delay as original project
did not have.
Attached pin chart for Pioneer board in case you need it.
Regards, Dana.
-
11. Re: PSoC4: UltraSonic Sensor based Distance Measurement
DaKn_263916 Apr 17, 2015 7:54 AM (in response to user_264716)If you want to avoide sprintf( ) altogether -
Not sure of its general capability or limitations.
Regards, Dana.