Code Mystery, need extra eyes
T Chap
Posts: 4,223
I must be burnt, over an hour on this and can't understand what I am missing here.
This code watches a pin that has an XBAND. The XBAND outputs a positive going pulse relative to how much it is detecting. It sits low when it sees nothing. So to create a sensitivity method, I put in a variable Xbandvar[0] which is now set to 110. This is the number of repeats the loop can make before returning a 0(no detection). The return value is always correct based if I debug with the timeout local var.
The Xbandvar[2] is the user sensitivity level. Which is a count of how many actual pulses were detected from the Xband. I have this set to a value of 207, which should not be allowed because the code is definitely returning 0, if no pulses detected. But, if pulses are detected, the local variable is counting to 207. It should not be possible to have a pulse count greater than the first loop which times out at the local variable TImeout(set to 110)
The concept is, the repeat loop sets how long to watch the Xband, the sensitivity is set by how many actual pulses are seen in that period.
This code watches a pin that has an XBAND. The XBAND outputs a positive going pulse relative to how much it is detecting. It sits low when it sees nothing. So to create a sensitivity method, I put in a variable Xbandvar[0] which is now set to 110. This is the number of repeats the loop can make before returning a 0(no detection). The return value is always correct based if I debug with the timeout local var.
The Xbandvar[2] is the user sensitivity level. Which is a count of how many actual pulses were detected from the Xband. I have this set to a value of 207, which should not be allowed because the code is definitely returning 0, if no pulses detected. But, if pulses are detected, the local variable is counting to 207. It should not be possible to have a pulse count greater than the first loop which times out at the local variable TImeout(set to 110)
The concept is, the repeat loop sets how long to watch the Xband, the sensitivity is set by how many actual pulses are seen in that period.
PUB CheckXband(the_pin) | pulse, timeout, indexx case the_pin auxin1 : indexx := 0 auxin2 : indexx := 1 pulse~ timeout~ repeat ' This section pauses the code waiting for a response from Xband(a 1), then returns. after ' A user defined repeat count is set by xbandvar[0] (a repeat time out) repeat while ina[the_pin] == 0 if timeout == Xbandvar[indexx] return 0 ' quit the loop if timeout exceeded (debug this with a return timeout) beep(19, 3000, 2) timeout++ pulse++ '' count the number of times the repeat while was exited on xband pulse (1) ' This section determines sensitivity, xbandvar[2] here determines ' how many pulses needed to consider a detection if pulse == Xbandvar[indexx+2] + 100 ' xbandsensitivity cannot be > than xbandtimeout, but it IS test value is 207! DoorToggle GoZeroClear case the_pin auxin1 : ser.str(3, string("XB1 ")) auxin2 : ser.str(3, string("XB2 ")) 'beep2500 ' debug only w(80000000) return 1 'debug this with a return pulse
Comments
The bigger mystery is, why is it that within 30 seconds of posting does the answer finally come after an hour.
Quick solution
repeat while ina[the_pin] == 1 'wait until previous HIGH goes low.
repeat while ina[the_pin] == 0
Welcome to my world...