General > General Technical Chat

what's your recent fail?

<< < (10/14) > >>

Vovk_Z:

--- Quote from: harerod on May 01, 2021, 03:32:32 pm ---or:
Serial.println( (int)(( maxtemp.readCurrentTemperature() * (9./5) ) + 32));

--- End quote ---
Why not this (I'm not C, C++ developer):
Serial.println((int)(( (maxtemp.readCurrentTemperature() * 9)/5 ) + 32)); ?

nctnico:

--- Quote from: T3sl4co1l on May 01, 2021, 07:30:45 pm ---This is, in part, how you work with fixed point numbers.  Once you get a feel for them, it's not much harder to work with than floats in most problems, and goes much faster on most embedded platforms. :-+

--- End quote ---
A more natural way is to use a unit which has enough resolution by itself. Like milli-Fahrenheit in this case. It is a good practise to always use clear SI units in software.

T3sl4co1l:
I avoid units where possible, as numbers are just that: numbers, dimensionless and arbitrary.

For example, an ADC reading isn't any particular voltage or current or whatever: it's some ratio to whatever VREF was at that instant.  If VREF is very well known, it also corresponds to a meaningful (calibrated) value, but it's not necessary to track it as such.  And with the ADC reading being scaled to a power of 2, you're only going to lose dynamic range by using different units in software.  Most applications do eventually need to record or display units, but that can be done entirely at the end: a gain factor (and offset if applicable) before printing and you're set.

(So yes, I find those special-value references a bit amusing.  2.048V, 4.096V, who cares? ;D )

(I will add, this is particularly useful for core operations, heavy on numeric analysis and independent of application.  At higher levels -- especially if floats are heavily involved -- using units is probably a good idea.  Scientific computation for example.)

Tim

nctnico:

--- Quote from: T3sl4co1l on May 01, 2021, 10:56:37 pm ---I avoid units where possible, as numbers are just that: numbers, dimensionless and arbitrary.

For example, an ADC reading isn't any particular voltage or current or whatever: it's some ratio to whatever VREF was at that instant.  If VREF is very well known, it also corresponds to a meaningful (calibrated) value, but it's not necessary to track it as such.  And with the ADC reading being scaled to a power of 2, you're only going to lose dynamic range by using different units in software.  Most applications do eventually need to record or display units, but that can be done entirely at the end: a gain factor (and offset if applicable) before printing and you're set.

--- End quote ---
In theory yes, but software is much easier to maintain if the next person doesn't need to figure by what odd value a variable is scaled. When I read a value from an ADC I always convert it to Volts. That the reading is accurate to the extend of the quality of the reference should go without saying. Trouble shooting is much easier when the firmware says it is reading 3.22 Volts and the DMM connected to the input of the circuit says the same.

David Hess:

--- Quote from: exe on April 22, 2021, 08:43:16 pm ---
--- Quote from: David Hess on April 22, 2021, 12:21:05 am ---while I decided whether to refurbish it
--- End quote ---

I guess the decision has been made :)
--- End quote ---

If it was only that simple.  After several days of randomly changing various things with no positive result, I was inspired to leave it powered up, and after several more days it POSTed.  Now it reliably POSTs, so far.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod