Sujet : Re: Need help with PI PICO...
De : tnp (at) *nospam* invalid.invalid (The Natural Philosopher)
Groupes : comp.sys.raspberry-piDate : 28. Mar 2024, 12:56:14
Autres entêtes
Organisation : A little, after lunch
Message-ID : <uu3lsu$3i8u6$2@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
On 28/03/2024 08:35, Björn Lundin wrote:
On 2024-03-25 16:57, The Natural Philosopher wrote:
That is, some asynchrounous event in this sequence
>
gpio_put(ULTRASONIC_OUT,1);
sleep_us(10);
gpio_put(ULTRASONIC_OUT,0); //reset the input
//if asynch event lasting more than 100uS occurs here...
// wait for echo pulse start
while(!gpio_get(ULTRASONIC_IN))
;
//then the low-high-low echo pulse will never be detected.
if you change the wait body to include a counter then you could realize that when the counter had reached a high number - you missed the pulse.
Just try again then. Getting a reading is not that time sensitive - or?
That will be the next strategy.
I need to isolate exactly which bit is failing, and can remove all the other debug code.
If it turns out to be a one in a thousand issue it probably isn't worth trying to avoid it, as you say, simply take another sample
:START
int cnt = 0;
gpio_put(ULTRASONIC_OUT,1);
sleep_us(10);
gpio_put(ULTRASONIC_OUT,0); //reset the input
//if asynch event lasting more than 100uS occurs here...
// wait for echo pulse start
while(TRUE) {
if (! gpio_get(ULTRASONIC_IN)) {
cnt++
} else {
break;
}
if (cnt >= TOO_HIGH_VALUE) {
goto START;
}
}
-- “It is hard to imagine a more stupid decision or more dangerous way of making decisions than by putting those decisions in the hands of people who pay no price for being wrong.”Thomas Sowell