11-21-2009, 03:36 AM
Hi my program is not completely executing my exact instruction set. I want it to check two sensors and if the difference of the two sensors is greater than a certain constant assigned then make the move instructed. My code attached only compares the sensor and whenever there is a slight difference it execute. :
It looks like the values you are shifting to the ADC have been changed from the original program; which is what sets the mode and channel you are reading in. For example, if you are want to read Channel 0 in a single ended mode, you could use the following:
· LOW CS
· SHIFTOUT DataIn, Clock, MSBFIRST, [%11000\5 ]···· ' Select CH0, Single-Ended
· SHIFTIN DataOut, Clock, MSBPOST, [result0\13]·· ' Read ADC
· HIGH CS
From there, you could change the last two bits accordingly to select the channel you would like. In the datesheet there is a truth table that will explain how to use this function; so you can make sure you have the proper channels selected to get the inforamtion from?
11-21-2009, 04:32 AM
Your code says: IF (X1 - X0 = V) & (V > 400) THEN
There are at least two problems with this. For one, you're using "&" which is a bit-wise AND operation when what you need to use is "AND" which is a logical test. Look in the BASIC Stamp Syntax and Reference Manual for a more detailed description of these operators. You can also look in the help files of the Stamp Editor.
The 2nd problem is that you're testing for equality between X1 - X0 and V. Is that really what you want?
I think what you want is: IF ABS(X1 - X0) > 400 THEN