Hello Ross,
What is the nature of the tachometer signal you are attempting to simulate? Is it a square wave, or thereabouts, as Peg has assumed, or something with a much shorter pulse duration? If the latter, to simulate a 100RPM signal would require a prescaler division of 16, rather than 8 (for 4MHz bus frequency). This would further reduce the available resolution at higher rates, if using a single prescale value.
To achieve sufficient resolution at the upper rev limit (assuming 9999RPM), the prescaler division will need to be 1, or if more resolution is needed, a higher bus frequency used. With this prescale value, the minimum RPM that can be simulated will be something like 900RPM (depending on pulse duty). With 4MHz bus frequency, the resolution at the upper limit, as follows -
Pulse repetition: Equivalent RPM:
1500.25 us 9998.3
1500.50 us 9996.7
You will need to increase the prescale value for low simulation frequencies.
I assume you would "dial up" the required RPM value. Within the output compare ISR, you will need to calculate the next required output compare setting, based on a 16-bit "increment" value. This increment value would be derived from the required RPM setting. The calculation will involve more lengthy multiplication and division operations (presumably fixed point integer rather than floating point), so should be done outside of the ISR.
Regards,
Mac