General > General Technical Chat

what's your recent fail?

<< < (9/14) > >>

RichC:
Laid out my board, got it made up (luckily a DIY job on the CNC not a fab) and mounted everything on it. It didn't work. Checked things over. I had swapped drain and source on a mosfet.  :palm:
I can't even easily fix it because it's half of a single package pair so it would mean swapping pin 2 to pin 4 (on a 6 pin package). Guess I'm making a new PCB for that one.

AlfBaz:

--- Quote from: RichC on April 30, 2021, 04:12:08 pm ---Laid out my board, got it made up (luckily a DIY job on the CNC not a fab) and mounted everything on it. It didn't work. Checked things over. I had swapped drain and source on a mosfet.  :palm:
I can't even easily fix it because it's half of a single package pair so it would mean swapping pin 2 to pin 4 (on a 6 pin package). Guess I'm making a new PCB for that one.

--- End quote ---
Dead bug the IC, small bare wire and steady hands might let you test the rest of the board until your re-spin arrives
Never mind, you're cncing the pcb

exe:

--- Quote from: mindcrime on April 30, 2021, 01:51:45 pm ---I live in the USA. To us, Celsius barely exists... it's some weird abomination that's used by people from weird places like the UK, Europe, Australia, etc.

--- End quote ---

I can imagine how weird it is to use a "wrong" scale. When I was in the UK they measured my weight in ... stone. What is that, a measure system from the stone edge? (kidding).


--- Quote from: RichC on April 30, 2021, 04:12:08 pm ---I had swapped drain and source on a mosfet.  :palm:

--- End quote ---

Ouch, that must be painful  :'(

harerod:
mindcrime, if you don't mind a suggestion from an old German guy who went to uni in Konrad-Zuse-Strasse:
No need for float, if you can make sure that your integer accumulator is large enough.
Make sure to tell your MCU in which order to process the numbers. If you don't trust brackets and precedence, do:

int16_t accu; // (adequate till 2^15 / 9 )
accu = maxtemp.readCurrentTemperature();
accu *= 9;
accu /= 5;
accu += 32;
Serial.println( accu );

or:

Serial.println( (int)(( maxtemp.readCurrentTemperature() * (9./5) ) + 32));

T3sl4co1l:
You can even take the remainder (from the division) and, if it's 3 or 4, add 1 to the result to get correct rounding.

Or uh... add 2 before the division, I suppose.

Or to maintain accuracy, multiply by say 16 (or << 4), to get 12.4 fixed point -- this shift has to be un-done for printing, so it may be a bit inconvenient, or the 62mK resolution may simply be unnecessary.

That is:


--- Code: ---accu = readCurrentTemperature() * 9;
accu <<= 4;
accu /= 5;
accu += 32 << 4;
printf("%d", accu >> 4);
printf(".%03d\n", ((accu & 0x0f) * 125) >> 1);

--- End code ---

Or if you want to write out the print routine yourself, take the fractional part (accu & 0x0f), multiply by 10 to get a new digit above the decimal, print the digit, mask it off, and repeat:


--- Code: ---for (...) {
frac = frac * 10;
printf("%d", (frac & 0xf0) >> 4);
}

--- End code ---

Only a few digits are needed, since 4 bits of fraction = (0..15) / 16, which by itself doesn't fit into 1 digit (but the fifth in the present problem handily does), does easily fit into 2 digits (100ths), and terminates after 4 digits (0.0625000, etc.).

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. :-+


I can report my own partial fail in this regard, as I had a recent problem with just too much dynamic range in play to handle easily even in 32 bit fixed point; as I couldn't justify spending time figuring it out, I fell back on floating point, which actually only added about 2kB to the binary, and my MCU had plenty of cycles to spare for the operation.  (This was math in the complex domain, a bit weightier than whole numbers -- that's already 64 bits per complex number.  Doing it with [32 bit] floats, takes up as much memory, but I don't have to pay any attention at all to dynamic range and shifting -- that's really what it's about, a "floating point" is literally just doing that every time.)

Tim

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