Shop OBEX P1 Docs P2 Docs Learn Events
Eeprom and Floating point — Parallax Forums

Eeprom and Floating point

grasshoppergrasshopper Posts: 438
edited 2008-11-17 18:21 in Propeller 1
I am trying to put some numbers in EEprom that are in floating point. I was converting them to an integer by multiplying them by 100 and truncating them. My problem is that it works for one number but when I put in more numbers it wont work.

Here is a clip of my code. I am using the BS2 object.


Pub WriteEEprom   | Temp, Temp2
 
  
  Temp := Ft.Fmul(Software_Version,(Ft.Ffloat(100)))
  Temp2 := ft.FTrunc(Temp)
  
  Memory.Write_HighMem(10,Temp2,4)
     
  ser.str(@F1_CV)                                                                               
  ser.dec(Temp2)
  ser.str(@CB)

  Temp := Ft.Fmul(Mode_Value,(Ft.Ffloat(100)))
  Temp2 := ft.FTrunc(Temp) 

  Memory.Write_HighMem(20,Temp2,4)
  
  ser.str(@F1_CV)                                                                               
  ser.dec(Temp2)
  ser.str(@CB)





Software_Version should be 2.34
and mode could be 100.23

Is this the correct approach?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-17 17:05
    Why convert them to integers? Why not just write the floating point value to EEPROM. As far as the EEPROM routines are concerned, the floating point values are like any other 32-bit (4 byte) value. You'd do:

    Memory.Write_HighMem(10,Software_Version,4)
    Memory.Write_HighMem(20,Mode_Value,4)

    Post Edited (Mike Green) : 11/17/2008 5:12:53 PM GMT
  • grasshoppergrasshopper Posts: 438
    edited 2008-11-17 17:15
    mike ill give it a try thanks as always.
  • grasshoppergrasshopper Posts: 438
    edited 2008-11-17 17:40
    So it worked but I had to increment the eeprom location by a factor of 10. Can you explain why?
    This worked below
    Memory.Write_HighMem(10,Software_Version,4)
    Memory.Write_HighMem(20,Mode_Value,4)
    
    



    This below would not work
    Memory.Write_HighMem(1,Software_Version,4)
    Memory.Write_HighMem(2,Mode_Value,4)
    
    



    Thanks
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-17 18:21
    I don't have the EEPROM routines handy, but I assume the first parameter is some (probably relative) address in EEPROM. It would be a byte address, so, since the values are each 4 bytes, you'd need addresses that allow for that. Addresses 0, 4, 8 would work as would 1, 5, 9. 10 and 20 work because they allow for 10 bytes between starting addresses.

    I did look at the BS2 routines. The first parameter is an EEPROM byte address from 0 to 32767 that applies to the 2nd 32K of EEPROM.
Sign In or Register to comment.