Shop OBEX P1 Docs P2 Docs Learn Events
Passing data problems - FloatToSting issue? — Parallax Forums

Passing data problems - FloatToSting issue?

Martin HebelMartin Hebel Posts: 1,239
edited 2007-03-11 18:36 in Propeller 1
Well,
I finally took the punge into video for a research project I'm involved in, and it support my long-time desire to do plotting with the Propeller video, but I've ran into an issue I can't seem to resolve.· I'm reading several channels of an ADC, plotting it, and showing some information in the text area.

As seen in the pic, the plots work fine, they are being sent raw ADC data.· The text at the top is converted to a string float before being passed.· When I call it·with the following, it seems to work fine:
Vid.UpdateText(FS.FloatToString(VoltFloat[noparse][[/noparse]0]),string("0"),string("1"),string("1"))


Pub UpdateText (Vapp1,Vapp2,CH1,Ch2)| Time
  gr.width(0)
  gr.color(0)
  gr.box(0,151,256,40)
  PlaceText
  gr.text(45,151,Vapp1)
  gr.text(45,166,Vapp2)
  gr.text(180,151,Ch1)
  gr.text(180,166,Ch2)
  Time := fp.fdiv(FP.FFloat(timer),10.0)
  gr.text(215,177,fs.floattostring(Time)) 


But when I change it to this, the value of Vapp1 always follow Vapp2 as shown in the image.
        Vid.UpdateText(FS.FloatToString(VoltFloat[noparse][[/noparse]0]),FS.FloatToString(VoltFloat[noparse][[/noparse]2]),string("1"),string("1"))   


I've tested it everywhich way, and the values are also sent via RF to StampPlot so I know they hold what they are suppose to.· Am I missing something or is there simply a glitch in FloatToString perhaps?

Once I get a few more things ironed out, I'll post the object for plotting a couple channels revised for general use.

Thanks all
Martin


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting, and XBee Wireless Adapters
Southern Illinois University Carbondale, Electronic Systems Technologies
1127 x 845 - 133K

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-11 17:15
    I change the other 2 values from string to float to strings, and what I guess is happening is that the all the coversions to strings are performed at the same memory address, which is passed, and the last conversion is contained there, so they are all pointing to the same string.

    Ok.... now to figure out how to get around this....

    Thanks! Gosh, you guys are great! Once I post a problem, I start thinking what you may be thinking! It's like talking out-loud I guess [noparse]:)[/noparse]
    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-11 17:33
    Martin,
    Yes, the Float to String routines use the same temporary buffer to store the string until it's used. You can get around this by declaring two instances of the FloatToString object or an array of instances (OBJ FS[noparse][[/noparse] 2] : .....). Each will have its own set of variables, but there'll be only one copy of the code. You'd do "FS[noparse][[/noparse] 0].FloatToString(VoltFloat[noparse][[/noparse] 0])" and "FS[noparse][[/noparse] 1].FloatToString(VoltFloat[noparse][[/noparse] 2])".

    Another possible choice would be to copy the string to your own temporary string area, then do the second conversion.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-11 17:38
    Thanks Mike, I simply did the conversion in the Update Text routine instead, made the call a lot cleaner and shorter too.

    Appreciate it!
    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-11 17:55
    One other Q on this that has me confused, I'm using a DAC, whose value is a constant at this point, but when I convert it to a float, the value bounces all around (0.5123, 0.5267, .5035, etc).· Since this is nothing more than a calculation, I would think it would come up with the same each time.· Thoughts?
    fV_DACA := fp.fmul(fp.fdiv(2.048,4095.0),FP.FFloat(V_DACA * 2))
    

    -Martin
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-11 18:17
    Update: It appears that fs.floatToString becomes quirky when going into the hundreths place. Seems odd the same data would result in varying results, but it does. Ah well.

    -Martin
    ·
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-11 18:36
    Ok, getting closer, I hate to keep posting, but I feel like I can almost see it, but can't get there.
    Depending on the order of the following code for showing the values, it makes a big difference in which values get jumpy and don't use the precision set. I'd tried a few things between each to see if I could calm it down, but nothing works, just changing the order makes a difference, and it really doesn't seem to follow a pattern.
    Thoughts?· I'm not good enough to dig into Chip's FloatString object to try to debug it if that is the issue.
      fs.setprecision(3)
      gr.width(0)
      gr.color(0)
      gr.box(0,151,256,40)
      PlaceText
      gr.text(180,166,FS.FloatToString(Ch2))
      gr.text(180,151,FS.FloatToString(CH1))
      gr.text(45,166,FS.FloatToString(Vapp2))
      gr.text(45,151,FS.FloatToString(Vapp1))
      Time := fp.fdiv(FP.FFloat(timer),10.0)
      gr.text(215,177,fs.floattostring(Time)) 
    

    ·-Martin
Sign In or Register to comment.