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

Bar graph

Hi

In my project iam measuring the leak rate.

The range of leak rate is 1.0E-11 to 1.0E-02.Up now I measured leak rate and displayed
On the 7 segment display with 0.1 resolution. Here I used look up table method I taken hole Range values In the table and iam displaying the value for corresponding voltage .
I stored values in the farm Of (1011 =1.0E-11) here "." ,"E","-" are constants.

Now I want display the leak rate on BAR graph display.
For 20 digits I have to take one led.

The fallowing values I have to show on bar graph
1E-11, 3E-11, 5E-11, 7E-11, 9E-11, 1E-10,
3E-10, 5E-10…………………………………………2E-02

ex:
1E-11 = one led should glow
3E-11 = 2 leds should glow
5E-11 = 3 leds should glow
:
:
:


How to convert table values in to bar graph display.

Thanks

Regards

Parents
  • The Threshold values are the values above which each LED turns ON (or OFF, depending which way you look at it). You have basically given this information in your post already!

    IF value > threshold_1 THEN led1 := on;
    IF value > threshold_2 THEN led2 := on;
    IF value > threshold_3 THEN led3 := on;
    etc
    etc

Reply
  • The Threshold values are the values above which each LED turns ON (or OFF, depending which way you look at it). You have basically given this information in your post already!

    IF value > threshold_1 THEN led1 := on;
    IF value > threshold_2 THEN led2 := on;
    IF value > threshold_3 THEN led3 := on;
    etc
    etc

Children
  • Thanks for reply

    If we write 50 IF LOOPS means program become large and complex.

    In another method what elements we have to store in ARRAY.

    can give any logic for this problam.

    Regards

    sri

  • If we write 50 IF LOOPS means program become large and complex.

    1) there is no such thing as an "IF LOOPS"
    2) what is 'large and complex' about 50 lines of code?

    In another method what elements we have to store in ARRAY.
    you can di like this (based on the 50 if) with 2 tables

    IF value > threshold[index] THEN led[index] := on;

    Erik

  • #define NumLeds 12
    Value Threshold[NumLeds] =
        {
        // for each LED, list the value at which
        // the LED should turn on
        };
    
    
    currentValue = GetCurrentValue();
    
    // go through all LEDs, lowest to highest,
    // and turn on all those LEDs for which the
    // current value is greater than its threshold
    for (led = 0; led < NumLeds; ++led)
       {
       if (currentValue >= Threshold[led])
           {
           // current value is at least high enough
           // to activate this LED
           SetLed (led, LedOn);
           }
       else
           { // turn off LEDs
           // current value no longer high enough
           // to activate this LED
           SetLed (led, LedOff)
           }
       }
    
    


    If you just want one segment of the bar to turn on, at the current level, then instead of turning on LEDs all the way up, you could just remember the index of the highest value matched, and then turn the corresponding LED on. (You'll also have to remember the last LED activated so you can turn it off.)

  • Thanks for reply

    Here I wane glow 50 leds means I have to send 50 ones on to the port.

    My doubt is how to store the 50 ones in the array?

    Here I well use 7 latches (8 bit data * 7 latches =48 bits).

    So I well send only 8 bits on to the port. For 48 bits I want send 7 times on to the PORT.

    Ex:


    /* First 8 bits */

    C1=0;/* latch disable*/
    P1=8 bit data;
    C1=1;/* latch enable*/


    /*Second 8 bits */

    C1=0;/* latch disable*/
    P1=8 bit data;
    C1=1;/* latch enable*/


    /* Third 8 bits */

    C1=0;/* latch disable*/
    P1=8 bit data;
    C1=1;/* latch enable*/

    :
    :


    /* Seven 8 bits */

    C1=0;/* latch disable*/
    P1=8 bit data;
    C1=1;/* latch enable*/


    How to divide the 48-bit number in to seven 8-bit numbers?

    Regards
    Sri

  • "If we write 50 IF LOOPS means program become large and complex."

    As already noted, there is no such thing as an "IF LOOP"

    50 'if' statements doesn't even fill a single page of source code - that's not really a lot.
    And it certainly isn't complex: it is very simple indeed - just a lot of tedious repetition.

    And 'if' statements should compile to something fairly simple - so the generated code should not be that large or complex either.

    The alternative is to store the comparison values in an array, a use a loop to check through each value for each LED see Drew's example.

    This is actually more "complex" - since you still need to do exactly the same comparisons, but you have added the "overhead" of the array and the loop!

    The loop-based code may or may not be smaller, due to the space occupied by the array...

    Whichever actually turns out to be smaller, the difference is likely to be not terribly significant.
    Why don't you try both and post back your conclusions?

  • "How to divide the 48-bit number in to seven 8-bit numbers?"

    Why 48 bits?
    If you have 50 LEDs, you need 50 bits!

    Keil C51 doesn't have any data type larger than 32 bits anyhow, so you can't do it directly.

    Easiest way is probably to have a 7-byte array:

    array[0] holds bits 0-7;
    array[1] holds bits 8-15;
    :
    :
    array[6] holds bits 48-55 (note you have some spare bits here).

    Hint: Look up the Modulus operator, '%' (percentage sign), in your 'C' textbook - it will come in useful in deciding which bit to set in which byte of the array...

  • Thank for reply

    Iam using 50 Ifs in my program.

    IF value > threshold_1 THEN led1: = on;
    IF value > threshold_2 THEN led2: = on;
    IF value > threshold_1 THEN led3: = on;
    IF value > threshold_2 THEN led4: = on;
    IF value > threshold_1 THEN led5: = on;
    IF value > threshold_2 THEN led6: = on;
    .
    .
    .
    IF value > threshold_1 THEN led49 := on;
    IF value > threshold_2 THEN led50 := on;


    EX:
    0000 0001 – led1 glow
    0000 0011 – led2 glow
    0000 0111 – led3 glow
    0000 1111 – led4 glow
    0001 1111 – led5 glow
    0011 1111 – led6 glow
    0111 1111 – led7 glow
    1111 11111 – led8 glow

    How to send control word on to the PORT 6 times?

    How to display on the leds means what type of hardware I have to use?

    Regards
    Sri

  • "...what type of hardware I have to use?"

    So this is now off-topic - no longer a question about Keil tools.

    But I thought you'd already decided:

    "iam using HDSP4830 bar graph displays"

  • Avago Technologies; formerly Agilent; previously Hewlett-Packard (HP).

    As always, when using any electronic device, your first port of call should be the Support section of the manufacturer's website. There you should search for the Data sheet, Application Notes, and other supporting materials.


    Try this:

    http://www.avagotech.com/products/product-detail.jsp?navId=HDSP-4830

  • "EX:
    0000 0001 – led1 glow
    0000 0011 – led2 glow
    0000 0111 – led3 glow
    0000 1111 – led4 glow
    0001 1111 – led5 glow
    0011 1111 – led6 glow
    0111 1111 – led7 glow
    1111 11111 – led8 glow"


    Do you mean:

    0000 0001 – LED  1 glows
    0000 0011 – LEDs 1,2 glow
    0000 0111 – LEDs 1,2,3 glow
    0000 1111 – LEDs 1,2,3,4 glow
    0001 1111 – LEDs 1,2,3,4,5 glow
    0011 1111 – LEDs 1,2,3,4,5,6 glow
    0111 1111 – LEDs 1,2,3,4,5,6,7 glow
    1111 1111 – LEDs 1,2,3,4,5,6,7,8 glow
    or:
    0000 0001 – LED 1 glows
    0000 0010 – LED 2 glows
    0000 0100 – LED 3 glows
    0000 1000 – LED 4 glows
    0001 0000 – LED 5 glows
    0010 0000 – LED 6 glows
    0100 0000 – LED 7 glows
    1000 0000 – LEd 8 glows