uMFPUV2 math co-processor, data conversion problems
TimN
Posts: 32
For the project i am working on, i need to use a uMFPUV2 math co-processor. but, currently, i can only read data from it in zero-terminated string format. but i later need to be able to view that data as a decimal instead of a string. I used the sample program included in the co-processor documentation for BS2 series microcontrollers to base my program off of, just to let you know as background in case that might help anyone answer my question, which is: does anyone have any suggestions as to how i can either read the data from the co-processor in a format that can be convertered to decimal, or know of a way to convert string data from the co-processor to decimal form?
Comments
On the other hand, you could take a value from 0.000 to 9.999 and represent it on the Stamp as an integer from 0 to 9999 and easily do fixed point arithmetic on it. For example, you could take a value of 0.628 and multiply it by 2.3. On the Stamp, you would represent this as 628 (an integer) and 23 (another integer). You would multiply them and scale the result back to 3 decimals as 628*23/10. If you were displaying the results from the Stamp, you could insert the decimal point character on output in a routine that would check for the number of significant digits, add leading zeros, etc.
If it's the last one, you do most of the work on the uMFPUV2. Let's say you had a floating point value ranging from 0.000 to 0.999. You'd multiply it by 1000.0 to change the range to 000.0 to 999.0, then use the FIX operation to convert floating point to integer, then READWORD to read in the two byte value most significant byte first (look in the uMFPUV2 instruction manual for the descriptions of these operations).
There's an example of reading an integer from the uMFPUV2 on page 11 of the tutorial manual. Be sure to specify that you're reading 16 bits into a word variable (look at the SHIFTOUT Stamp command description).
Post Edited (Mike Green) : 10/8/2006 3:44:20 AM GMT
and to answer your question, the example i was basing my program off of the example program that used the uMFPUV2 to calculate the temperature in farenheit based off of data collected from a DS1620 temperature sensor. the only changes i made were to remove all debug lines of code, add in a SEROUT command to send the data and a prefix HIGH signal to trigger the POLL function in the receiving stamp.
What problems have you had before with trying to read a word from the co-processor? What was the actual code you used? Please look at the examples in the tutorial for the use of FIX and READBYTE. READWORD is similar, just transfers two bytes.
What is the range of values you want to transfer? You might be able to transmit the string from the co-processor with the decimal point and do the conversion to a fixed point value at the 2nd Stamp by using the decimal point just as punctuation. For example, if you had values with 2 decimal places always and they were from 0.00 to 250.00, you could use a SERIN statement like "SERIN pin,Baud,[noparse][[/noparse]DEC first,DEC second]" followed by "result = first * 100 + second". This would give an integer from 0 to 25000 which would represent your fixed point value.
LOW 6
GOSUB Read_DS1620 ' get temperature reading from DS1620
' send rawTemp to uM-FPU
' convert to floating point
' store in register
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]DegC, LOADWORD, rawTemp\16, FSET]
' divide by 2 to get degrees Celsius
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]LOADBYTE, 2, FDIV]
' degF = degC * 1.8 + 32
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]DegF, FSET+DegC, ATOF, "1.8", 0, FMUL]
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]DegF, FSET+DegF, LOADBYTE, 32, FADD]
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]DegF, FSET+DegF, ROUND]
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]DegF, FSET+DegF, FIX]
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]DegF]
format = 51
GOSUB Print_FloatFormat
HIGH 6
PAUSE 100
SEROUT 6, 188, [noparse][[/noparse]dataByte]
LOW 6
PAUSE 1900 ' delay, then get the next reading
GOTO Main"
the part receiving the data is: "reciever PIN 10
inches VAR Word
inputtemp VAR Word
SERIN 10, 188, [noparse][[/noparse]DEC3 inputtemp]
DEBUG CRSRXY, 0, 1, "temp input received"
READ 0, Word inches
DEBUG CRSRXY, 0, 3, "distance = ", DEC3 inches
DEBUG CRSRXY, 0, 4, "temp = ", DEC3 inputtemp
RUN 0"
in terms of how the stamps are connected, the sending basic stamp, as you can see, has a wire going from pin 6 to pin 10 on the receiving stamp. i have been able to get this system to work, if both stamps are running the same type of data. so far, all i receive is "255," "048," or "000" depending on where i place the DEC formatter