This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Assignments of measured values from a spreadsheet (excel. Csv, etc.)

Hi, all.

I'm visiting a german technical school and we have do start a Project work in February. For the coarse advance planning I would like to have a Basic structure of the Programming with Keil µ-Vison. We already programmed some stuff with µ-Vision, but not deep enough

I would like to read the digitized value of a pressure sensor with a microcontroller, let the Software evaluate it, and show the pressure value on a Display.

so is it possible, to build a Table (like Excel, .csv, etc.) and let the programm compare the Value of the input Port from the microcontroller withe the values in the table and take appropriate pressure value.

Or is there another possibility, do assign the values, so that I can change the assignments quick and easy?

please excuse my bad english.

Thank you in advance!

Jonas

Parents
  • I want to use Keil µ-Vision3.

    Yes. I want to let µ-Vision compare Values from intput port with Values in a Table.

    BUT How???

    I only know something like an If-funktion

    like:

    if (P0 = 128)
    { pressure = "150bar";
    }

    if (P0 = 215)
    { pressure = "180bar";
    }

    etc...

    so itÂ's more easy, to have a Table where you can change the assinged Values.

Reply
  • I want to use Keil µ-Vision3.

    Yes. I want to let µ-Vision compare Values from intput port with Values in a Table.

    BUT How???

    I only know something like an If-funktion

    like:

    if (P0 = 128)
    { pressure = "150bar";
    }

    if (P0 = 215)
    { pressure = "180bar";
    }

    etc...

    so itÂ's more easy, to have a Table where you can change the assinged Values.

Children
  • But doesn't the measured value represent a discretisation of a continuous function? In that case, you don't need a table. You can use a formula to convert the measurement. Or, you may use a partial linear interpolation for translating the samples.

  • Because of there is no analog input on the microcontroller (we use Atmel T89C51CC01) the Voltage of the Pressure sensor is converted by an A/D converter.

    so we have values like:

    Pressure - Voltage - 8-Bit A/D
    10 bar --- 1,22V --- 42
    20 bar --- 1,43V --- 49
    30 bar --- 1,65V --- 57
    40 bar --- 1,86V --- 64
    50 bar --- 2,08V --- 71
    60 bar --- 2,30V --- 79
    ...
    300 bar --- 7,50V --- 255

    So there is no linear interpolationand and no continuous function can be used. I can solve the problem with many If - else loops but its laborious and I think, I can use this also for other projects.

    Thank you, for your help!

  • in the uVision manual:

    http://www.keil.com/support/man/docs/uv3/uv3_debug_functions.htm

    But this really isn't the sort of thing that uVision is designed for - it sounds like what you really need is to write a PC application in VB or whatever, and have it communicate with the microcontroller via a serial link

    Or perhaps you should be using something like LabView or Matlab:

    http://www.ni.com/labview/

    http://www.mathworks.com/

  • Having a built-in ADC or using an external one is completely irrelevant for the problem.

    How can you say that there are no continuous function and no interpolation possible? All ADC by definition has to convert a continuous analog value into discrete digital steps. If the analog value from the sensor changes linearly with the the change of the measured parameter, then you can convert from ADC value to measured unit (or the reverse) with a simple A*x + B formula, i.e. a scale factor and an offset.

    For each 10 bar, your AD value increases with just over 7 ticks. You can then convert from ADC value to pressure in bar by the A*x + B formula, since your sensor seems to produce a linear voltage. All you have to do is figure out the offset (corresponding to zero-crossing of the curve) and the scale factor (corresponding to the slope of the curve).

    Trying to set up a huge number of if statements - either one for each pressure to convert to ADC value, or one for each ADC value to convert to a pressure - is a huge waste of time.

  • Hi,
    I see a lot of users ask for the link to my attachment

    But ... my dear friends, please post your minds, repairs and opinions here!

    I'm working now on a conversion to Basic (I don't have skills about PC basics yet, as I wrote bee4).
    I somebody want to do this, my C source is very good and simple and well documented and very easy to understand but very clever I think...

  • If there isn't a convenient formula, a so-called Lookup Table is often an appropriate solution.

    The entries in the table are your pressure values, and the ADC 8-bit reading is used to index the table:

    unsigned int pressure[] =
    {
        :
        10,  // Value for index 42
        :
        20,  // Value for index 49
        :
        30,  // Value for index 57
        :
        40,  // Value for index 64
        :
        50,  // Value for index 71
        :
        60,  // Value for index 79
        :
       300   // Value for index 255
    };
    


    You can, of course, use Excel or similar to compute the table values - and even create the source text...

  • It seems that some simple high school algebra can be used here...

    y = m*x + b
    

    and

    m = (y2-y1)/(x2-x1)
    

    May be used for a given range of x1 to x2.

    Hint: m = slope.

    Jon

  • Except that if the sensor is linear, you never use just the two endpoints to find the two constants (except as possibly a quick and dirty to see if the system is linear enough or if a piece-wise or higher-order approximation is needed). You use a number of measurements all over the line and then do a least-square match.

    Then you get a quality factor R telling how well a straight line matches the samples, i.e. informing if the sensor (or ADC) isn't really linear, or if one or more measures are incorrect. It also better compensates for noise in individual samples and irregularities in individual ADC steps.

  • So - plenty more reading on the theory of measurements and interpretation of experimental data, then...

    That'll keep him busy over Christmas...

    ;-)

  • Ok, maby It can be solve by using an algebra.

    I give a nother Example not with Number, with Text.

    in a Table are the days and the arrival time (start work or Train arrival time, etc.)

    Day --- Time

    Monday --- 08:00
    Tuesday --- 08:15
    Wednesday --- 07:56
    Thursday --- 08:03
    Friday --- 08:25
    Saturday --- 09:23
    Sunday --- 08:11

    Now the program ask for witch day, the time schould be displayed. the user specifies the Day and on the Display appears the time.

    So I can change the time easily in the table.

  • this looks very interesting! I think, we've already done soething with "index-variables".
    I remember the []

    It's a great "Food for thought". ;-)

    Thank You!

  • This post discusses something completely different from your first post:
    I would like to read the digitized value of a pressure sensor with a microcontroller, let the Software evaluate it, and show the pressure value on a Display.

    Are you sure that you know exactly what you want to do?

    Your first example showed a perfectly linear conversion between measurement and ADC value.

    Your second example is on the other hand a perfect match for a lookup table, since there is no correlation between the input parameter and the requested answer.

    Note that for the masurement example, you can create a linear transfer function from analog pressure to expected ADC value, or from a ADC value to a pressure.

    For the time example, you are not guaranteed to be able to have a reverse transfer function or reverse lookup table, since several days may have the same time.

  • "I give another Example not with Number, with Text."

    Don't think of them as text; think of them as numbers

    enum
    {
       day_sun = 0;
       day_mon;
       day_tue;
       day_wed;
       day_thu;
       day_fri;
       day_sat;
    }
    


    So your table of times is just indexed by the day number.

    You can convert day numberse to text (for display) with a lookup table

    char *day_string[] =
    {
       "Sunday",
       "Monday",
       "Tuesday",
       "Wednesday",
       "Thursday",
       "Friday",
       "Saturday"
    }
    

    "So I can change the time easily in the table."

    Changing them in the table is easy;
    The question is, how will you get the data to the microcontroller; eg:
    A keypad?
    A serial link?
    Some kind of plug-in memory device?
    etc, etc,...