This is a follow-up to my project using an older Mitutoyo DRO to control threading on my lathe. See here and related posts:
https://www.eevblog.com/forum/mechanical-engineering/mitutoyo-acu-rite-dro-zero-setting/msg5624315/#msg5624315Due to other factors, my work on that project was suspended until now. It turns out there are two easy methods to set "zero" on those and most likely other current similar models from Mitutoyo: 1) Toggle the low-voltage (1.5V) to the sensor; and 2) Subtract the reference reading from current reading to give a zero. Toggling must have a short time off, perhaps a few milliseconds that I have yet to determine, and mathematical correction is probably quicker. While Microchip Assembly for 8-bit enhanced midrange devices may be archaic, I thought presenting it here for comment might help improve it and save others the rather dull task of writing it themselves. Unfortunately, PICList, which served as a repository for such things is now dead. Those archives have code for a single byte of packed BCD. My code was developed for the full 7 digits of BCD plus sign necessary for the Mitutoyo (e.g., ab.cdef in inches or abc.def in mm).
Two versions are presented. The first is is simple linear code ("Subtr") without indirect addressing. The second version uses the two indirect FSRn registers for those who may be short of instruction flash memory ("FSR_Subtr").
The attached code is not simply Plug&Play. It includes code for testing various combinations of minuend ("x") and subtrahend ("y"). The difference is saved in registers z(n) for the non-FSR method and in registers x(n) for the FSR method. Be sure to add leading zeros if those registers are used. In the FSR method, the jump table for test values relies on having those registers. That is, the jump is 17 (2 lines of code + 14 values + 0) because of the way the "decfsz" instruction works. A disassembly listing will calculate the correct jump between two test entries, if you are not sure.
Timing shows that the FSR method is slower, as expected. For the FSR method, time for calculation of the difference was approximately 181 Tcy for negatives and 103 Tcy for positives. Calculation of the 10's complement for negatives of 77 Tcy is included. The non-FSR method took 58 to 62 Tcy and 54 Tcy for subtraction and 10's complement , respectively.
EDIT: I forgot to mention I use MPLab 8.92. Some of the Assembler macros I used may not work with current versions.