Page 2 of 2

Re: SR04 Ultrasonic Sensor

Posted: Fri May 17, 2024 1:22 pm
by chipfryer27
Hi

Following on from the above.

This time I used the same setup as documented in the above posts but using software mode with the following results

Measured (cm) / Displayed (cm) / Pulse Width (mS)

109 / 78 / 6.27462
120 / 86 / 6.9197
140 / 100 / 8.0691
144 / 103 / 8.32248
162 / 116 / 9.3676

I have only attached the shot from 162

162cm.jpg
162cm.jpg (54.98 KiB) Viewed 3905 times

Regards

Re: SR04 Ultrasonic Sensor

Posted: Mon May 20, 2024 12:23 pm
by medelec35
Hi Iain
I have just looked into this, and its not a bug but a setting in which I gave incorrect advice.
What I have done is exposed the timer rollover time which is in seconds
The furthest distance that can be measured is 310 cm = 18ms.
Therefore, the value exposed can't be below the maximum ms time.
If using a clock speed of 32MHz, then you will need to set the prescaler to 1:4.
Timer Rollover time.png
Timer Rollover time.png (10.24 KiB) Viewed 3599 times
That gives a maximum time of 32ms which is ample.
Rollover time needs to be a low as possible but higher than the ms max distance time (e.g 18ms).

To try the component.
Browse to this location using file explorer , it's hidden by default so just paste the link into your address bar.

Code: Select all

C:\ProgramData\MatrixTSL\FlowcodeV10\Components
Place the attached component.
If Flowcode is already open, then you will need to reload your project for the new component to work
If you run any component updates, then the component you added will be overwritten, so it will stop working again (unless the component update has been pushed).

Re: SR04 Ultrasonic Sensor

Posted: Mon May 20, 2024 1:49 pm
by chipfryer27
Hi Martin

Thanks for that. I'll try as soon as I can and get back to you.

Regards

Re: SR04 Ultrasonic Sensor

Posted: Mon May 20, 2024 4:22 pm
by chipfryer27
Hi Martin

Just did a quick test, not much time. Downloaded and set Prescaler 1:4

Measured (cm) / Read (cm)
162 / 160
187 / 180
213 / 211

Looking very good so far... :)

I'll do some more tests later but things seem sorted now.

Thanks again.