
Curious problem with sonar sensor
Hello,
first of all I'm new to RobotC, although I'm not not new to C-programming/programming in general. I really like most of this language so far and I'm thinking of purchasing it. Up to now I was using RobotC 1.10 and yesterday for testing also 1.40 public RC1, both under Vista. Irrespective of the version I discovered a strange bug which made me almost crazy. Here is the problem:
I was writing my first program for my first self-build tribot-like robot. So far I managed to let him travel and rotate and then I wanted him to measure also the distance via the sonar sensor. After checking the examples I included the appropriate code into my program. Unfortunately it didn't read any useful values from the sensor. Hence I first tried the sample program itself and found it was running like a charm (Displaying Sonar Value to LCD.c). Because I was not able to find the mistake, I put the sample code into my program. This way only the sample code was executed, because of the infinite loop in it. But my program was still generating wrong values. In particular it is generating values between 900 and something above 1000, without showing real distance dependence. When disconnecting the sensor it says something about 100. Then I started to comment out everything which was not needed. But this didn't work. So I deleted almost everything in the code to make it equal with the sample program, but this also didn't change the situation. Then I deleted also all comments from both programs. When compiling and downloading the sample code, suddenly the following code appeared in the beginning of the program:
After deleting these lines and compiling/downloading again, another similar line appeared. So far the code was working. After deleting these lines again it showed the same strange behavior as found for my own program. In the end I'm really confused now. Has anybody any clue what is happening here? If there is any way to attach files, I would like to attach my program files, since I don't think posting them makes sense, because both programs are in principle the same. Anyway, here is the code:
The original program (not working):
The sample code with deleted comments (not working after deleting the sudden comments on top):
Sample code with sudden comments (working):
My program condensed to the core parts of the sample program, which starts producing correct number after inserting the first comment-lines:
I'm sorry for the lengthy post, but after all I'm really confused and don't know how to explain shortly. Thank you very much for reading (if you reached this point

).[/code]