I have a 4808 running Arduino code using the MegaCoreX library. If I run the chip with its internal 20MHz oscillator, millis and micros run too fast. I have tried setting a #define F_CPU value, but it doesn't help.
It works fine if I set the clock to 16MHz, but it would be great if I could use that extra bit of speed the chip is capable of. Does anyone know if this is possible?
Just spent some hours on the same issue, so in case anyone else stumbles into this:
The base frequency of the internal RC oscillator can only be controlled via the OSCCFG fuse, therefore changing F_CPU between a 16MHz-derived value and a 20MHz-derived value (see the table here) requires reprogramming the fuses.
If you flash a firmware compiled with F_CPU based on a different oscillator frequency, and forget updating OSCCFG, only the clock prescaler will be set -- so you get a +/- 25% error in timekeeping.
The problem is that you get a timekeeping error even if you have both the fuse and F_CPU set to 20MHz. I don't understand well enough the code Nigel posted in order to see if there's any way to compensate other than doing it in the main program anywhere a timer is used.