Shop OBEX P1 Docs P2 Docs Learn Events
Lookdown and Strange Return Value — Parallax Forums

Lookdown and Strange Return Value

TJHJTJHJ Posts: 243
edited 2008-05-31 01:17 in Propeller 1
Ok So I am trying to get this thermocouple thing to work and my most recent thought is to use a lookdown table useing the known voltages.
But it does odd things. To create a search method of sorts it adds until it finds a match, not the best, but I am ok with a premant rounding up solution.
The table is very large it has approx 1500 data points.

PUB Look(Vi) | Table  
 
 Table := 0
 Table := Lookdown(Vi:0,0039,0079,0119,0158,0198,0238,0277,0317,0357,0397,0397,0437,0477......
 Repeat 
    Vi := Vi+1
    Table := Lookdown(Vi:0,0039,0079,0119,0158,0198,0238,0277,0317,0357,0397,0397,0437,0477.....
    If Table > 0
      Quit     
Return Table-1

It works if I call Look(0037) or Look(37) It returns 1, as it should,or Look(0075) Gives 2.
But if I put in Look(0030) it returns 857. Or Look(0031) gives 82.
And Ideas what is going on here?

Thanks as always
TJ

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-30 22:15
    This is a terrible way to search a table, especially one as large as this. I suggest you define your table using a DAT section. Assuming you've got values less than 32767, you could use one word for each entry and fill the last entry with $7FFF. You'd search it with
    PUB look(v) : i ' Note: i is always initialized to zero
       repeat while v > myTable[noparse][[/noparse]i++]
    


    The table starts with the first value greater or equal to v.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-05-30 22:40
    TJ,

    Where does the data in your table come from? If it's mathematically-defined, perhaps a formula (either continuous or piecewise continuous) would provide a more compact way to arrive at the desired result.

    -Phil
  • RaymanRayman Posts: 14,162
    edited 2008-05-31 00:49
    First, I don't think your first Lookdown statement does anything and can be removed.

    I bet it's finding your values 30, 31 in the table somewhere... Try examining V1 during the iterations to see what's happening...

    Who knows, you may have found a bug... Or, maybe theres a mistake in your table.

    Or, maybe the memory space for the table is being corrupted somehow...

    You might try a test look for the last entry in the table and see if that works right...
  • TJHJTJHJ Posts: 243
    edited 2008-05-31 00:56
    Here is the Calc program I came up with which I think is even worse.

    CON 
    A0 = -0.0176004136860
    A1 =  0.0389212049750
    A2 = 0.0000185587700320
    A3 = -0.000000994575928740
    A4 = 0.000000000318409457190
    A5 = -0.000000000000560728448890
    A6 = 0.000000000000000560750590590
    A7 = -0.000000000000000000320207200030
    A8 = 0.0000000000000000000000971511471520
    A9 = -0.0000000000000000000000000121047212750
    OBJ
    F : "Float32"
    ADC : "CD_LTC1298"
    PUB Init'(AD1)
      f.Start
      'ADC.Start(AD1)
    PUB DEGC(V) |  VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9, V1, V2, V3, V4, V5, V6, V7, V8, V9, AI1, AI2, AI3, AI4, AI5, AI6, AI7, AI8, AI9
      'V := F.FFloat(Vin)   ' Convert V to Float
      VP2 := F.Pow(V, F.FFloat(2))
      VP3 := F.Pow(V, F.FFloat(3))
      VP4 := F.Pow(V, F.FFloat(4))
      VP5 := F.Pow(V, F.FFloat(5))
      VP6 := F.Pow(V, F.FFloat(6))
      VP7 := F.Pow(V, F.FFloat(7))
      VP8 := F.Pow(V, F.FFloat(8))
      VP9 := F.Pow(V, F.FFloat(9))
     
      
      V1 := F.FMul(A1, V)
      V2 := F.Fmul(A2, VP2)
      V3 := F.Fmul(A3, VP3)
      V4 := F.Fmul(A4, VP4)
      V5 := F.Fmul(A5, VP5)
      V6 := F.Fmul(A6, VP6)
      V7 := F.Fmul(A7, VP7)
      V8 := F.Fmul(A8, VP8)
      V9 := F.Fmul(A8, VP9)
      
      AI1 := F.FAdd(A0, V1)
      AI2 := F.Fadd(AI1, V2)
      AI3 := F.Fadd(AI2, V3)
      AI4 := F.Fadd(AI3, V4)
      AI5 := F.FAdd(AI4, V5)
      AI6 := F.Fadd(AI5, V6)
      AI7 := F.FAdd(AI6, V7)
      AI8 := F.Fadd(AI7, V8)
      AI9 := F.Fadd(AI8, V9)
      Return F.FRound(AI9)
       
    



    What Do you guys think?



    So I ended up creating the table to 1500 degrees, even though they limit out at accuracy at somewhere around 1350.



    Post Edited (TJHJ) : 5/31/2008 1:21:14 AM GMT
  • TJHJTJHJ Posts: 243
    edited 2008-05-31 01:17
    Rayman said...

    bet it's finding your values 30, 31 in the table somewhere... Try examining V1 during the iterations to see what's happening...
    It seems to me that it is finding values which contain 30, 31 ect. I counted out the 83 number and its 1231. Is this is how this should be working.
    Rayman said...
    First, I don't think your first Lookdown statement does anything and can be removed.
    Yeah sorry I have been expermenting and was dumping the 1st lookup value out to a screen just to see if it was finding something before the actuall seach began. Its not needed but I was useing it for examination. Thanks for the help.

    I hope it is not a bug, but on the upside I would know I am not insane.

    Thanks for all the help as always.

    TJ
Sign In or Register to comment.