Hi,
Yes, it really should go in software.
An off by one error with the value in the software if the encoder triggered an interrupt in the middle of that value being written.
I don't see how that should happen.
When an interrupt arrives, the
present instruction is finished, only
then the PC is pushed to the stack and the interrupt is serviced, so no fault as you describe can happen.
Programming in a HLL, you shouldn't need to worry about it at all - this is a job for the compiler.
Keeping in mind I was a much worse programmer back when I was doing these things so it may be obvious to me now how to avoid these problems. I just remember them being very frustrating and hard to debug. Ill just start writing code and post when I run into some current problems.
In Software please
One thing that might go wrong is, if you have several instructions that need to be executed in succession. But then you could disable interrupts while doing this and an eventual missing count from eg. an encoder can be extrapolated from the average frequency of these interrupts.
Another way to deal with such is, to let the interrupt just set a flag and return control to the main program, then do the deeds in the main program at the first available moment.