Home > other >  Based on the STM32F103ZET6 HC - SR04 drive problem
Based on the STM32F103ZET6 HC - SR04 drive problem

Time:10-02

I have a question the measuring distance, is not no, it is 1.7 cm carry, directly has jumped to 5.1 3.4, I set the alarm within 5 cm, the amount of distance is no problem, about 4.6 4.8 cm, but serial assistants according to 3.4 cm, very headache, bosses to look at, thank you!

CodePudding user response:

Brother, no matter what function you want to achieve, you also add delay in interrupt operation, while waiting, the operation itself is a serious problem, still learn how to correctly use break first, and what you want to describe, I didn't understand your problem,

CodePudding user response:

The delay is I intentionally added, or send data too fast, can't see clearly, I want to ask is, I the actual distance is 4.8 cm, for example, it shows that not to come out, only to 3.4, that is to say the next number is 5.1, 3.4 is not counted in the middle

CodePudding user response:

What is your sensor (analog/digital)? , detection range is how much of sensor and sensor precision is much

CodePudding user response:

Analog sensor, detection range of 2-450 - cm, accuracy of 2 mm

CodePudding user response:

Looked at you this sensor, if I to design, my train of thought is that
Considering your requirements for precision is more sensitive, I'm going to let the timer switch, only to count,
Reload timer Settings, 1 second, attention should be paid to reload time count value requires zero crossing detection,
High level duration, all the external interrupt configured to increase/decrease interrupt mode, the interrupt function, falling edge detection is rising along the interruption or disruption, rising along the interrupt for a Tim count, get a falling edge, the two results is presupposed,
The main function, the subtraction of the two results, as your sensor parameter calculation,
This design, no delay, real time would be much better, don't need to print in the interrupt, you only need the main function regularly calculate and print is ok

CodePudding user response:

This is to simulate? Are you? I see the Internet is that high level calculated duration?

CodePudding user response:

Digital number, wrong

CodePudding user response:

Oh oh, you can refer to I write to you in front of the train of thought, change, and see what the result is, in the interrupt must not add time-consuming operation, there will be many unknown problems, printing, also can not print is also time-consuming operation

CodePudding user response:

Ok, I will try, thank you
  • Related