Modbus_cccal

Communicating with a Cheap Chinees Caliper

I bought a caliper at the Gamma (dutch D.I.Y.) for Euro 9,80 . It came in a plastic box with foam lining and two battery´s.  I wanted to find out if these could be used in a DRO (Digital Read Out) system.

  


 





To interface this signal to a uController we use a simple transistor , ( you can also use a 74LVxx gate they work down to Vcc 1.0Volt)





First step, look with oscilloscope at data coming from caliper.
In the scope image below we see a
Clock signal (ch2)
Data signal : (ch1)  caliper displaying 0.00mm
Data signal : (chA)  caliper displaying 0.01mm
Voltages ~1.5 volt

Data should be clocked in on rising flank.
LSBit is send first
Signals normaly high (also when caliper is OFF)
 



A frame is made up of 6 nibbles / 3 Bytes / 24 bits.
Framelength is about 15msec.
Frames a send every 200msec.

The pictures to the right show [1.68mm]
binary 168 =  128+32+8
lsb->  00010101  <-msb

Pushing the Inch/mm button we see bit 23 (last bit) of the frame toggle.
when a measurement becomes negative we see bit 20 toggle.
 



Opening the Caliper

 Remove the sticker from the backside.
Remove the 4 screws.
Carefully lift the plastic housing from the metal caliper-base.

We now se the backside from the pcb where the measuring surfaces are.

Remove the two rubber dust/dirt sliders left and right.
Remove the 4 screws.

Carefully lift the pcb from the plastic housing.
Don´t bump the lcd, you want it to stay
 
 
We solder some wires to the pcb :
Black - Ground
Orange - Data
Brown - Clock
Red  - Supply (Soldered at Capacitor)

note. Both outer pad´s are Ground
 


The firmware for the microcontroller
To make some testcode I use a microchip PICDEM2 prototyping board with a PIC16F877.
I wrote the Code in 'C' using the CCS compiler.
I use the hardware SPI of the PIC (RC4,SDI) (RC3,SCL)
Results are dumped to the RS232 (19200bps) port and to the LCD.



Conclusion :

We see that it is very easy to read the value from these calipers.

We need a minimum on hardware interfacing providing voltage level translation.
When using the caliper hardware in a CNC (lathe/mill) enviroment or other harsh situations extra hardware is needed (esd-protection, optocouplers, DC-DC converters, TIA485 bus, etc..)

The base firmware is simple and needs code added to catch all the exceptions, this firmware example can easily be combined with the CCS MODBUS (serial communication bus) routines to connect this caliper to Mach3 (CNC control software).



Connecting a cheap Chinees Caliper to Mach3 over ModBus

To make the cccal firmware run nicely in conjunction with the modbus routines we make SPI reception interupt based and put SPI synchronisation in a state-machine to prevent any dedicated wait locations in the firmware.

You can see the base firmware on the bottom of the page.

Configure Mach3 for ModBus

Make sure the modbus serial bus is activated in Mach3.   Tick the box and restart mach3.


To test the modbus we use the "Modbus Serial Control Monitor" located in the [Function Cfg´s -> Setup serial modbus control] menu.  Then select the [Test ModBus] button.
Make sure all the settings are correct Port nr, bitrate, etc.  and push the [Read] Button and data should appear in the box on the right.


Once you receive the data its time to display the Caliper data somewhere in the Mach3 screens.

There are several ways to do this ,  we begin with Macro´s  , using the macropump.  ( another (better) way is BRAINS )
First we set up mach3 to receive the data and make it available in mach3 through inputs 64..66 (3 words)


Writing a Macro

go to menu [Operator -> VB scripts editor]
this will open the Visual Basic editor.

We receive data in input 64, 65 and 66.
input 66  is the LSbyte
input 65  is the MSbyte
input 64  has the flags  Neg, inch/mm

On the right we see the result of the macro.
The caliper displays 10.78mm on its displays. through the modbus mach3 received the same data.  It is then displayed on the main X axis DRO (has nr 0) .
 
Finishing the Macro

When you get some numbers you can add the negative and inch/mm bits.

Save the macro as [macropump.m1s] if you want to run it as a macropump.
To run the macropump activate it in menu [Config -> General Config] and active the tickbox [run macropump].
You have to restart Mach to make it active.

You should now see you X-axis DRO display the caliper information.
 

The Firmware for the PIC

ToDo list :
Test/streamline firmware , this is just a throw together of some code.
Handle the autopower off of the Caliper.  ( We can probably send data to the caliper too )

Comments