What happens if you analogWrite() a negative number?

What happens if you analogWrite(-3) or analogWrite(10,000)?

I'm having a strange overflow. I'm driving a panel meter with an analog pin. I have a knob that I can turn that could make the value written to the analog pin anything from -254 to 1024. As I turn the knob, though, I get this thing where the needle will max out and then flop back to zero and start rising again as if the quantity had overflowed. But the numbers are ints, so I wouldn't expect overflow to happen. The only thing I can think is that analogWrite doesn't truncate the values it 'gets', but does a byte type cast on whatever you feed it, and that converted byte value is somehow overflowing.

I think the value is directly assigned to the corresponding register.

You could cast/truncate before calling analogWrite but I think this might be something to look into?

Correct, the value is assigned directly to an 8 bit register. Therefore it would get what ever the unsigned 8 bit value would be. For example -1 is 0xffff which would be 0x00ff which would be 255

-2 would be 0xfffe which would be 0x00fe which would be 254

etc

Mark

Ok. Guess I'll have to truncate my code to be on the safe side.