Searching \ for 'AW: AW: AW: [PIC]:Floating point' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'AW: AW: [PIC]:Floating point'.

Truncated match.
PICList Thread
'AW: AW: AW: [PIC]:Floating point'
2003\05\08@111837 by eger Stefan Georg

flavicon
face
I need a 'float' because I have to display a voltage for example of 41.5V.

The following part of my program show´s the A/D- conversion and the
mathematic operations that I need (a voltage range  of 0-5V form the A/D-
result is conform to voltage range of 0-50V)


void ermittleDigitalenWert()
{
       digitalwert = 0;         digitaleAnzeige = 0;
       spannungsZehner = 0;
       spannungsEiner = 0;
       spannungsKomma = 0;
       stromZehner = 0;
       stromEiner = 0;
       stromKomma = 0;
       anzeigeSpannung = 0;
       anzeigeStrom = 0;
       
       digitalwert = ADRESH;
       digitalwert |= (digitalwert << 8);
       digitalwert |= ADRESL;
       digitaleAnzeige = (float)(digitalwert * 5 / 1023.0);          
       ADRESH = 0;
       ADRESL = 0;
}


void main(void)
{
       init();
       InitLCD();
       
       while(1)
       {
               if(anzeigeAD == TRUE)
               {
                       /************************A/D- Wandlung auf Kanal
0********************/
                       /*********************Spannung der ersten
Halbbruecke*****************/
                       ADCON0 = 0b10000001;
                       ADGO = 1;
                       while(ADGO == 1);
                       ermittleDigitalenWert();

                       spannung_HB1 = (digitaleAnzeige * 60.94) / 6.04;
                       DelayS(1);
                       
                       /************************A/D- Wandlung auf Kanal
1********************/
                       /********************Spannung der zweiten
Halbbruecke*****************/
                       ADCON0 = 0b10001001;
                       ADGO = 1;
                       while(ADGO == 1);
                       ermittleDigitalenWert();
                       spannung_HB2 = (digitaleAnzeige * 60.94) / 6.04;
                       
                       if(spannung_HB2 > spannung_HB1)
                       {
                               anzeigeSpannung = spannung_HB2 -
spannung_HB1;
                               spannungPositiv = FALSE;
                       }
                       else
                       {        
                               anzeigeSpannung = spannung_HB1 -
spannung_HB2;
                               spannungPositiv = TRUE;
                       }
                       anzeigeSpannung = spannung_HB1;
                       spannungsZehner = (unsigned char)(anzeigeSpannung /
10);
                       spannungsEiner = (unsigned char)(anzeigeSpannung -
(spannungsZehner * 10));
                       spannungsKomma = (unsigned char)((anzeigeSpannung -
(spannungsZehner * 10)
       
- spannungsEiner) * 10);
               
       
/****************************Spannungsanzeige*************************/
                       WriteInstrToLCD(Set_DDRAM_Address + 0x42);
                       WriteCharToLCD(' ');
                       
                       if(spannungPositiv == TRUE)
                       {
                               WriteCharToLCD('+');
                       }
                       else
                       {
                               WriteCharToLCD('-');
                       }

                       WriteCharToLCD(0x30 + spannungsZehner);
                       WriteCharToLCD(0x30 + spannungsEiner);
                       WriteCharToLCD('.');
                       WriteCharToLCD(0x30 + spannungsKomma);
                       spannung_HB1 = 0;
                       spannung_HB2 = 0;
                       DelayS(1);
                                               

-----Ursprüngliche Nachricht-----
Von: Rick Regan [spam_OUTrdrdr2kTakeThisOuTspamYAHOO.COM]
Gesendet: Donnerstag, 8. Mai 2003 17:09
An: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU
Betreff: Re: AW: AW: [PIC]:Floating point


> No, that4s not the problem.....after the A/D-
> conversion I make a type cast
> from "integer" to "float". And if I try to show at
> first the value of the
> variable "voltage_HB1" on the display and then the
> value of "voltage_HB2",
> then I get the right values for both A/D- channels.

Since A/D results are integer, could you explain
why you need to make them 'float' to compare
and display them?


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\05\08@112914 by Rick Regan

picon face
> I need a 'float' because I have to display a voltage
> for example of 41.5V.
>
> The following part of my program show4s the A/D-
> conversion and the
> mathematic operations that I need (a voltage range
> of 0-5V form the A/D-
> result is conform to voltage range of 0-50V)

Sorry, I've gotten a little confused with this thread
since it has been presented piecemeal.  I realize
now that you're converting to float to deal in
voltages and not A/D results.

Is the problem in your display algorithm?  That is,
can it display a negative value (larger voltage
subtracted from a smaller one) properly?
Can you look at your voltage variables in the
simulator to see if they are correctly computed
(and perhaps only displayed incorrectly)?


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\05\08@113122 by Mike Harrison

flavicon
face
This is a VERY inefficient way of doing things.
Most microcontroller apps deal with values from ADCs and the like which have nowhere near enough
dynamic  range to justify the huge code and RAM penalty of using floating point.
Just becase there's a decimal point in the display does not mean you need to use FP. You need FIXED point, so all the maths can be done as simple integer operations.
If you need precision, a 32 bit long, suitably scaled,  will generally have more accuracy, and use a
lot less code than a float.

so instead of representing, say 4.15V, you store 415, and write your display routine to simply
insert the decimal in the appropriate position.

On Thu, 8 May 2003 17:17:21 +0200, you wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\05\08@221624 by Bob Ammerman

picon face
Here is an untested routine to convert a 32-bit value to ascii, sticking in
a decimal point for you.


// Simple routine to convert a 32 bit signed long value to a null
// terminated character string, with insertion of a decimal point
// at a user specified location (untested code!)

// Arguments:
//
//    buf - a char array, should be at least 14 bytes long
//    value - the value to be formatted
//    nplaces - the numbers of assumed decimal places
//
// Returns:
//     A pointer to the start of the resulting string, which will
//     actually be placed at the end of 'buf'

char *format_fixed_long( char *buf, long value, int nplaces )
{
   unsigned char neg;

   // remember if it is negative
   neg = 0;    if ( value < 0 )
   {
       value = -1;
       neg = 1
   }

   char *p = buf + 14;    // point just past the last char

   // Process until we have either stored the whole
   // value, and filled in at least all the digits to the
   // right of the decimal point, plus one to the
   // left.
   do {
       // insert the decimal point (or comma!) here
        if ( nplaces == 0 )
           *--p = '.';

       // store the next digit
       *--p = (char) (value % 10 + '0');

       // what is left of the value?
       value /= 10;

       --nplaces;
   }
   while (nplaces > -1 || value != 0)

   // stick in the sign if needed
   if ( neg )
       *--p = '-';

   // return pointer to start of characters
   // actually used in 'buf'
   return p;
}

Bob Ammerman
RAm Systems





{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...