Shop OBEX P1 Docs P2 Docs Learn Events
Table/Lookup with SX/B? — Parallax Forums

Table/Lookup with SX/B?

amg6975amg6975 Posts: 3
edited 2008-05-05 18:36 in General Discussion
Hey everyone, I've been using Stamps for a little while now and have been arond but first time poster because I'm starting to play around with the SX for fun. I'm a car guy so my ultimate goal is to get a fuel injection engine running on an SX. I've alread done traction control and shifting control with a BS2sx. I'm sure I'll have tons of questions but here's the first:

I need to make a table (fuel map) and from what I've read so far it seems like DATA/WDATA is the way to do it but I can't figure out how to READ a specific value. Here's an example of the table I made (values are just in there as place holder... it'll be tuned if it ever gets connected to an engine tongue.gif)

'========================================

FuelLoad   var word

FuelMap:

'LOAD   x         xx        xxx                                                     'RPM
WDATA 65535, 65535, 65535, 65535, 65535, 65535, 65535 ...   '500
WDATA 65535, 65535, 65535, 65535, 65535, 65535, 65535 ...   '1000
WDATA 65535, 65535, 65535, 65535, 65535, 65535, 65535 ...   '1500
...

'=========================================



I've read up the examples on displaying the whole string but I just want to grab a data based on the load and RPM

So far I've got: (say for 1,000 RPM and xx load)

READ FuelMap + 2, FuelLoad



I just have no idea how to get over to the xx word.

I could also be completely in left field so if that's the case, please point me in the correct direction.

Thanks!
Adam

Comments

  • BeanBean Posts: 8,129
    edited 2008-05-05 10:57
    Adam,
    · Each WDATA entry is 2 bytes. So it depends on how many entries are in each line.
    · If you had 10 entries in each RPM linel, you would have to add 20 to get to the 1000 RPM line, 40 to get to the 1500 RPM line, etc.

    · Something like:
    offset = RPM - 500     ' First entry is 500 RPMs
    offset = offset / 500  ' Get RPM line (500 RPMs per line)
    offset = offset * 20   ' Assume 10 entries per line
    offset = offset + xVar ' which entries on this line
    offset = offset + xVar ' Need 2 times xVar (each entry is 2 bytes) so add it twice
     
    Read FuelMap + offset, FuelLoad
    

    · Of course this could be optimized, but I wanted to show the logic behind it.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 5/5/2008 11:04:17 AM GMT
  • amg6975amg6975 Posts: 3
    edited 2008-05-05 17:58
    Oh ok, so the offset counts bytes like we read a book. I assumed it was just counting down lines and something else was needed to move to the right.

    So, I'm assuming that when I point it at a byte it's going to read in a word value through, right? or do I have to do READ twice and combine the bytes?

    Thanks, Bean and whoever fixed the spacing in my example. [noparse]:)[/noparse]
  • BeanBean Posts: 8,129
    edited 2008-05-05 18:35
    If the FuelLoad variable is a word, it will read both bytes automatically.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • amg6975amg6975 Posts: 3
    edited 2008-05-05 18:36
    Awesome, thanks again.
Sign In or Register to comment.