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 middleCodePudding user response:
What is your sensor (analog/digital)? , detection range is how much of sensor and sensor precision is muchCodePudding user response:
Analog sensor, detection range of 2-450 - cm, accuracy of 2 mmCodePudding user response:
Looked at you this sensor, if I to design, my train of thought is thatConsidering 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, wrongCodePudding 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 operationCodePudding user response:
Ok, I will try, thank you