??? 11/02/04 06:39 Read: times |
#80247 - RE: Help - Digital calibration of analog I/P Responding to: ???'s previous message |
This is a common problem! For a linear calibration the usual scale and offset works fine. The thing to watch (as you've pointed out) is loosing precision by doing integer calculations. The solution is to use fixed point - you still use integer calcs but you have an implied decimal point - how many decimal places you require is upto yourself - obviously if your a/d is 10 bits your calculations need to have more bits. In 'c' I would use a 'long' variable (32 bits). In fixed point, your values are multiplied by a fixed value (say 100 if you want two decimal places). Therefore a value of 1 would be stored internally as 100, 2.34 would be 234. As you divide, the integer rounding will loose precision, so do multiplies first, divides last. To makes thing a little easier - especially if you're writing code in assembler is to pre-multiply by a binary number (1,2,4,8,16...256) - 256 or 65536 are popular as you only need to shuffle the registers to divide by 256 (1 byte) or 65536 (2 bytes) rather than do a bit shift or a division. Some 'c' compilers recognise this and do the register shuffle rather than a division or bit shift. This code is an example: #define RHT_OFFSET 105460 //1.0546 * 10,000 #define RHT_SCALE 216 //0.00216 * 10,000 // //calc the temperature correction 1.0546 - (t * 0.00216) // long ltmp,ldiv; ldiv = (long)temp; //get the temperature ldiv *= RHT_SCALE; //scale it ldiv = RHT_OFFSET - ldiv; //offset it ltmp = ltmp/ldiv; //do the scaling - result should be in RHT% * 10 tmp = (int)ltmp; //16 bit result |
Topic | Author | Date |
Help - Digital calibration of analog I/P | 01/01/70 00:00 | |
RE: Help - Digital calibration of analog I/P | 01/01/70 00:00 | |
Hello Mr.erik malund | 01/01/70 00:00 | |
RE: Hello Mr.erik malund | 01/01/70 00:00 | |
RE: Help - Digital calibration of analog I/P![]() | 01/01/70 00:00 |