A double is still a float, just a double precision float is 64bits long instead of 32bits. Any floating point operation is very expensive on an Arduino or AVR as they don't have a floating point arithmetic unit unlike say the CPU in your computer. Simply adding 2 doubles takes around 230 instructions. The fact you find a double works where a float doesn't may point to a compiler issue.
For efficient code you want to as avoid using any floats single or double (which means no decimal places) and avoid performing any math which results in a division that has a decimal place. Hence in the above code the /5 is an expensive instruction however the *410>>11 is not (this is the same as *410/2048 which is divide by 4.99512 so in our application effectively the same).
What "noise" are you talking about? You talking about ringing from the FET overshooting? You talking about actual radio noise being emitted every time the FET switches?
To limit the power loss you need two things, 1) a FET with a low Rds_on value (the resistance when fully on), and 2) you need to move through the linear state as quickly as possible into saturation. The longer the FET takes to switch from off to saturated the more power is lost. This can be achieved by either reducing the switching frequency (MOSFET power-loss becomes a big issue at high frequencies), or by increasing the rise time of the MOSFET gate (using a fast push-pull driver at the output of the microcontroller). If they are covered there's a chance you're not saturating the MOSFET.
|