point float & picaxe?

giokal

New Member
Greetings to all in the forum, I am developing a project with the um-FPU v.3 .. and still does not understand how the picaxe (in my case 40x2) to handle these floating point values​​?
I understand that by reading the value of the FPU floating point (32 bit format) I require 4 bytes in picaxe: b0, b1, b2, b3 ... however these 4 bytes contain the picaxe floating point value fpu (being b0: MSB) .. but this content does not reflect its value in decimal (which is what I need!) ... how I can solve this???
 

KeithRB

Senior Member
You will probably need to use the FTOA instruction which will give you the ASCII string for the result.
 

giokal

New Member
While observing this instruction FTOA .... I see that the content is stored in the buffer of the FPU, but my question is: this value corresponds to ascii floating point? ..
using these lines of code:
Code:
              gosub Fpu_wait
              writei2c 0, (FREADA)
	      readi2c 0, (b10,b11,b12,b13)
	      sertxd ("byte0=",#b10,  " byte1=",#b11, "byte2=",#b12, " byte3=", #b13,cr,lf)
got this:
byte0=66 byte1=156byte2=64 byte3=0
floating point value: 78.1
studying the method to convert "simple binary floating point" is summarized in the following equation:
number.JPG
http://meseec.ce.rit.edu/eecc250-winter99/250-1-27-2000.pdf
where "s" is the sign, "E" is the exponent and "F" the floating...in this case following the equation "number" are:
78.1
b0 b1 b2 b3
01000010 10011100 01000000 00000000
0 10000101 00111000100000000000000
s e f
+ 133
that is:
N=(-1)^0 *(1.1001110001)*2^(133-127) ==> 1001110.001 ==>78.1

is that this is the method to follow?
 
Last edited:

westaust55

Moderator
It is difficult to provide a firm answer without knowledge of the task and what (and why) further processing is to be undertaken when a value is returned to the PICAXE.

I am not entirely sure what you mean by the statement:
While observing this instruction FTOA .... I see that the content is stored in the buffer of the FPU, but my question is: this value corresponds to ascii floating point? ..[/quote

By way of some information:
The FTOA converts a floating point value to an ASCII string in the specified format.
The format is a 2 digit value where the 10’s digit identifies the total number of digits/characters (including the decimal point) and the units digit identified the number of decimal places.
It is up to the user to ensure the total number of characters is sufficient. If the total number of characters is insufficient then digits are replaced (from memory) with the hash (#) character.
As the PICAXE cannot handle floating numbers, if it is desired to use the result for further math within the PICAXE there are two option:
1. Read back the result from the uMFPU chip in ASCII format and reconstruct the value and multiply by some order of 10 for internal handling
2. Multiply the result by some order of 10 within the uMFPU to reduce PICAXE program work load and read the ASCII string into the PICAXE.

If wishing to perform further math within the PICAXE this begs the question why not perform all the math within the uMFPU chip.
If you have a result of a calculation which is say 78.1 as per you example
Then when you use the FTOA command the result is a character string “78.1” which if the format is set as 41 (decimal) will be returned as the characters “7”, ”8”, “.” and “1”.
To extract a decimal value (0 to 9) from each ASCII character we subtract $30 or “0” or 48 (decimal).
Keep in mind a PICAXE chip can natively only handle positive integer numbers, so we need to introduce multipliers such as 10 or 100 to keep the decimal portion. Then when displaying we must introduce the decimal point at the right position which in itself is easy if we know what magnitude values are multiplied by.

Once an ASCII string is stored within the PICAXE in variables or scratchpad it is easy to create a decimal value:
Value = 1st digit – “0” * 10 + 2nd digit – “0” * 10 + 3rd digit – “0” * 10 + 4th digit – “0” . . . . ; continuing as necessary for the total number of digits.
If one character returned is a decimal point then test for that and remove from the equation and keep track of the resultant multiplication factor that is in effect applied (ie 10, 100, etc)
 

giokal

New Member
for westaust55:
ok ... delivering the FPU values ​​are the result of a physical phenomenon ADC monitored by the FPU port, so the result is a floating point value ...
instruction regarding FTOA understand that the result of this transformation format is deposited on the buffer FPU ... I have not tried to extract this value, so I have not clear when:

The format is a 2 digit value .....hash (#) character.
delivering results FPU, are used to take action according to the value received ... this value can be treated as a whole which saves me calculation for decimal portion ...
Now thinking about your proposal to treat each character received considering its position within the number received (unit hundred, ten, unit) .. I seem viable ... however initially thought collecting the four bytes (b0, b1, b2, b3) containing the floating point number and work these values ​​with the aforementioned equation.

number.JPG

I've tried manually and the results are satisfactory..
I understand that the proposed method is based on data received treatment without delving into the characteristics of the data and that seems very practical!, so I will consider two options: a) work the ascii data received, b) the mathematical equation to work with the original values ​​(floating point) .....

see the complexity of both codes..!
 

giokal

New Member
considering the above suggestions I made a first version of the idea, this is the code:
Code:
;code fpu:
 gosub fpu_wait
writei2c 0,(STRSET,0,SELECTA,freqO,FREADA)
gosub fpu_wait
writei2c 0,(FTOA,50) ;format: xxx.x =>"x" "x" "x" "." "x"
gosub fpu_wait
writei2c 0,(READSTR)

let w25=0
let ptr=56
readi2c 0,(@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc)
#rem
as registers 56 and 57 of the scratchpad is loaded with CHR: "32" (space) which we are not interested
work from the reg 58 to 60 to have the chr's Hundreds, Tens and Units and transform..
#endrem
 
get 57,b53 
 if b53=32 then goto jumpMIL
 w25=b53-$30*1000
jumpMIL: get 58,b53 

          if b53=32 then jumpCHR 
	   w27=b53-$30*100  
	    
  	   w25=w27+w25
jumpCHR: get 59,b53  
		  b53=b53-$30*10
		  w25=b53+w25 

get 60,b53 
b53=b53-$30 
w25=w25+b53 ; Finally obtain the decimal value of STRING BUFFER!!! into reg[w25]
		
	endif
with this method of avoiding calculations cumbersome floating number (32bits) originally contained in the FPU ... Another interesting exercise is to get the original value of the FPU floating-point and develop the conversion equation using "NUMBER" earlier ..

it should be noted that the code of communication with the FPU can be enhanced to improve its execution..
 

westaust55

Moderator
I believe where you have the line:
writei2c 0,(FTOA,50) ;format: xxx.x =>"x" "x" "x" "." "x"​
that will give the format format: xxxxx =>"x" "x" "x" "x" "x" with 0 decimal places

and for the format xxx.x =>"x" "x" "x" "." "x" you should use”
writei2c 0,(FTOA,51)
 
Top