??? 06/27/05 09:06 Read: times |
#95998 - I was being carelessly loose............ Responding to: ???'s previous message |
Sorry. I was being carelessly loose with terms when I referred to the #define macros and the subsequent computations that are done with them as all the work of the pre-processor alone. I actually meant to include the compiler in the process too!!
When I made my original post I was trying to report on my own personal experience with the IAR compiler (the AVR version) and the Keil Compiler (the 8051 version). I now have to say that I cannot rightly recall if the actual Keil C51 compiler can reduce carefully crafted floating point arithmetic expressions to simply integer expressions for run time use. To determine if it can or to see if such expressions automatically force inclusion of floating point library would require futher testing on my part. On the other hand the I can say for sure that code like that shown below definately results in integer constants in the run time code when the IAR AVR compiler is used. #define AD_REF 3.0 // A/D converter reference voltage #define AD_CNT_RANGE 1024.0 // count range of the A/D converter #define VIN_R1 47.5E3 // value of upper resistor in the VIN divider #define VIN_R2 10.0E3 // value of lower resistor in the VIN divider #define VIN_OFF 0.3 // VIN drop through diode to the VIN divider #define VIN_MIN 6.5 // minimum VIN volts for device operation #define VIN_MAX 13.5 // maximum VIN volts for device operation #define VIN_HYS 0.2 // hystersis of VIN voltage for recovery #define VIN_MIN_CNT ((unsigned int)(((((VIN_MIN - VIN_OFF) * VIN_R2)/(VIN_R1 + VIN_R2))*AD_CNT_RANGE)/AD_REF)) #define VIN_MAX_CNT ((unsigned int)(((((VIN_MAX - VIN_OFF) * VIN_R2)/(VIN_R1 + VIN_R2))*AD_CNT_RANGE)/AD_REF)) #define VIN_HYS_CNT ((unsigned int)((((VIN_HYS * VIN_R2)/(VIN_R1 + VIN_R2))*AD_CNT_RANGE)/AD_REF)) Michael Karas |