I had to realize that my casting operation returns complete ********.
Here's the failing code snippet:
dGainCorrFactor = ((double)(740000000000) / (double)(2300)) / (double)(u32CrntVal); dNewGain = (double)(u16Gain) * dGainCorrFactor; u32NewGain = (uint32_t)(dNewGain);
dGainCorrFactor and dNewGain result in the expected results.
In one example I calculated manually during debug. u32NewGain should have resulted in 0xe179 instead it became 0xe179e179.
Changing the line of u32NewGain to
u32NewGain = (uint32_t)((uint16_t)(dNewGain));
fixed the casting issue but this is not what I want since I'm not sure what would happen if dNewGain would be larger than 0xFFFF.
Does anybody know why this problem occured? Why would that cast ja write the lower two bytes the same way than the upper two bytes? The compiler I use i avr-gcc.
Thanks for your help!