AVR Atmega169 help

Jan 02, 2004 10 Replies

Can anyone help with a problem I have with a file from:

formatting link



It's in the temperature.c file and the statement is:



Temperature = (Beta / ((log(V_ADC/(V_ref-V_ADC))/log(__E)) + (Beta/T_amb))) - T_zero;



But I can find no reference to "__E" in any of the files? I am using ICCAVR and this was written for IAR EWAAVR 2.27b.



Anyone help?



Thanks



Phil


"Phil" wrote in news:bt4jtv$ms4$ snipped-for-privacy@titan.btinternet.com:

Since it starts with two underscores, it is defined by the implementation (compiler vendor or library author). Look in the library or compiler documentation for '__E'. Developers are not supposed to name variables with leading underscores (even in assy. if you want to mix C and assy) unless you are writing a compiler. Well there are some exceptions but why risk it?

- Mark -> --

This is just a guess as my math is rusty. According to the app note, you want ln(V_ADC/(V_REF-V_ADC)

ln() is not the same as log(). I believe ln (natural log) is the log with respect to the mathematical constant e. So, I assume the extra /log(__E) is to adjust log to be a natural log. So, I believe __E is supposed to represent the math constant e. I just don't remember what the value of e is.

The original formula calls for a ln() function (natural log) and it was written using log() function (base 10). In order to convert to base 'e' you need to divide by log(e).

Somewhere 'e' must be defined. If you can't find it just define it as

2.718281828. That should get you going.

Randy Ott

From the context, __E is "e" (2.71828...). They're just getting a natural log using a base-10 log function by the conversion

log[base a] (x) = log[base b] (x) / log[base b] (a)

Rich Webb Norfolk, VA

And since e is a constant, there is no need to calculate its log or reciprocal every time the function is called.

#define RECIP_LOG_E (2.302585093)

Temperature = (Beta / ((log(V_ADC/(V_ref-V_ADC))*RECIP_LOG_E) + (Beta/T_amb))) - T_zero;

Hold right there.... Since it's a C source we appear to be talking about here, that had better be false. The C standard library function log() _is_ the natural logarithm. If you want the log10(), you can get that too, but that would be pretty pointless in the circumstances.

I'm saying this under the assumption that the compiler makers at least tried to act reasonably regarding ISO C standard compliance, where it makes sense to do so. I.e. if your C compiler has a function named log() in declared in , and that computes anything else but the natural logarithm, that's IMHO sufficient grounds for immediately firing whoever bought it (and never talking to its maker again until they fix that error).

Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

Good point. I assumed from looking at the code that log() was log to the base

  1. The OP might need to modify his code to remove the /log(__E) if the compiler he is using follows the C standard.

I like your reference, (still laughing) it was very very enlightening.

Phil

Well, that depends.

If they're writing in C (and using the standard C library routine log), then RECIP_LOG_E should be defined as

#define RECIP_LOG_E (1.0)

Regards,

-=Dave

Change is inevitable, progress is not.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required