Shop OBEX P1 Docs P2 Docs Learn Events
chosing float or dec automatically (+other questions now) — Parallax Forums

chosing float or dec automatically (+other questions now)

BasilBasil Posts: 380
edited 2008-09-11 04:32 in Propeller 1
Hi All,

Not sure if this is dooable but thought i'd ask.
In my dataflash chip, I have a series of decimal and floats all stored in longs (well bytes really, but groups of 4 bytes)
I need to 'play them back' over serial to a com terminal.

Is there was way for the prop to tell wether its reading a decimal number or a float from the dataflash?...(This next part is easy)... and then either send it as decimal, or convert floattostring depening on its decision?

Thanks,

Alec

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

My our page

Post Edited (Basil) : 9/11/2008 12:38:03 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-10 23:20
    The best you can do is to look at the value in the long and make some assumptions about the likelihood that it's an integer vs. a floating point number. Because the floating point format stores the exponent in the high order portion of the long, it would look like a large integer except for the case of a very very small floating point value. For example, if your integers are greater than 23 bits, they're probably floating point.
    Here's the format information: en.wikipedia.org/wiki/IEEE_754
  • BasilBasil Posts: 380
    edited 2008-09-10 23:25
    Hi Mike,

    Hmmmm. Good ideas. I think the maximum length my integers will be is 12bits.

    So if I do the following, should that work.

    temp := value from memory
    temp := temp & %1111000000000000
    if temp <> 0
    temp is a float
    else
    temp is an int


    Thanks,

    Alec

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-10 23:32
    Not quite. Your bitmask has to be %01111111_10000000_00000000_00000000
    You also have to decide whether zero is an integer or floating point value. It's a special
    case of all zero bits.
  • BasilBasil Posts: 380
    edited 2008-09-10 23:37
    Ahhh ok, thanks Mike.

    That makes sense except for 1 part.

    If I send all 0's over serial, does it matter if i send serial.str(FloattoString(0.0)) or serial.dec(0)?

    Wouldn't the end result still be a whole lot of 0's?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-11 00:04
    It depends on what's listening on the other end. If the values are being converted back to IEEE
    floating point if they have a decimal point in them, you'll still end up with zero values since the
    IEEE floating point zero value is the same as the integer zero.
  • BasilBasil Posts: 380
    edited 2008-09-11 00:15
    Great,

    Thanks mike [noparse]:)[/noparse]

    Will try a few things and see how we go.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • BasilBasil Posts: 380
    edited 2008-09-11 00:33
    Sorry, I have another question semi related to this:

    When saving my data to the dataflash i'm currently doing the following:

    DF_Send(Circ_Buf_Start_byte, 32)
    DF_Send(DF_next_flight, 32)
    DF_Send(flighttime, 32)
    ...
    DF_Send(Pyro_Test, 32)
    DF_Send(Pyro_Test, 32)
    DF_Send(Pyro_Test, 32)

    All these variables are longs and are declared in the VAR section in the same order I write it to the DF.

    Are the varaibles actually stored in the RAM in the same order I declare them, so I can loop through the data using the memory address of the variable and incrementing it by 4 each iteration of the loop (I assume id increment 4 bytes to go to the next long, rather than 32bits).

    Also, I have a question about the EEPROM object (VarBackup/VarRestore)

    In either of these methods, I need to specify a start and end address.
    With the end address, is it the address of the first byte AFTER the data I want to save that I pass to the method, or the address of the first byte in the last long that I pass?

    As an example, using the above data. Assuming I want to store all longs from 'DF_Next_flight' to 'Pyro_Test[noparse]/noparse][b]2[/b', do I call"
    VarBackup(DF_Next_Flight, PyroTest[noparse]/noparse][b]2[/b) or VarBackup(DF_Next_Flight, PyroTest[noparse]/noparse][b]3[/b)

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-11 00:54
    Variables of the same size (byte, word, long) are stored in RAM in the order they're declared. Different sizes are grouped together to minimize padding.

    I have no idea about your EEPROM object. There are several in the Object Exchange. Usually the documentation (comments in the source) will explain what parameters are used for what purpose.
  • BasilBasil Posts: 380
    edited 2008-09-11 00:57
    Thanks Mike, so as long as I keep them all as longs they will all be sequential [noparse]:)[/noparse]

    I think I answered my own questions with the EEPROM.
    This line out of the EEPROM object...

    repeat addr from startAddr to endAddr - 1

    endAddr-1 would suggest I specify the first byte AFTER the data [noparse]:)[/noparse]

    Thanks for the help again,

    Alec

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • BasilBasil Posts: 380
    edited 2008-09-11 01:12
    Hi, one last questions hopefully [noparse]:)[/noparse]

    How would I pass the variable at address 'i' to a method which is expecting an actual variable not an address?

    Currently doing lots of DF_Send(Variable, 32) calls where Variable is a long containing a result.

    I want to do
    i := @First_Long
      repeat while i < (@Last_Long + 1)
        DF_Send([b]Variable at i[/b],32)
        i := i + 4
    
    



    Its the Variable at i part I cant get, Im missing something obvious I know it...

    Alec

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • hippyhippy Posts: 1,981
    edited 2008-09-11 04:32
      i := @First_Long
      repeat while i < (@Last_Long + 1)
        DF_Send( [b]long[noparse][[/noparse] i ][/b],32)
        i := i + 4
    
    
Sign In or Register to comment.