DIY Digital Caliper - Page 1
Forum section: electronics / projects

author: MitkoDyakov
author_rank: Contributor
timestamp: April 22, 2024, 08:36:33 am
content: Hey!I am trying to design a digital caliper. So far I have got my hands on a couple of cheap calipers and a few papers and patents. I have create footprints for both the scale and the sensor board and seem to be working quite well. You can follow the build log (link in the bottom) for more details, also the footprints are available if you want to check them out too.https://hackaday.io/project/194778-diy-digital-caliperThe difficulties I am having now are connected with conditioning of the signal I am receiving.I used this schema to get a reading with my scopeThe result is as follows:Now from what I gather I need to amplify or at least buffer this signal, then transform it to a sine wave and then detect the zero crossing. Compare the phase shift to a base sine frequency to determine the direction and displacement.1. Are my assumption of how the thing works correct at the first place?2. What should I be looking for when designing the amplification circuit?3. How do I choose R/C values for creating my sine?4. How do I detect zero crossing when my sine wave does not go negative?Cheers,M

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: April 22, 2024, 09:41:19 am
content: Just following the project, I think you can either choose hardware zero cross detection, say you would make an op-amp comparator with the one side of op-amp set to mid VCC scale, which does not works perfectly or you could choose the second option which is to apply DSP algorithms to Detect Zero crossing, which needs reading the wave form with ADC and apply some math formulas to it, and extract zero crossing.

author: tszaboo
author_rank: Super Contributor
timestamp: April 22, 2024, 10:32:34 am
content: For a quadrature encoder, which things are based on, you need two signals. So I'm going to assume you are only showing one of the signals. I think some of the issue comes from the 22 MOhm value that you have on the board. A smaller value would probably make the signal cleaner.Then about how to amplify the signal: Comparators. You feed the output of the opamp into a comparator with hysteresis (feedback resistor from the output to the DC input).

author: MitkoDyakov
author_rank: Contributor
timestamp: April 22, 2024, 11:27:27 am
content: Quote from: tszaboo on April 22, 2024, 10:32:34 amThe dotted line on the first row is the resultant sine wave if sense pad is located on top of all excitation pads. I call this the base frequency, mind you that it does not exists physically (you can't measure it with a scope).And depending which way you shift the caliper head the resulting sine wave you measure on the sense pad get phase shifted to the right or to the left.So I don't have two signal in the sense that a quadrature encoder has, but rather one signal to measure to determine the phase shift.

author: moffy
author_rank: Super Contributor
timestamp: April 22, 2024, 12:25:23 pm
content: You are talking about a sine wave but it looks like you are using a square wave for excitation is that the case?

author: MitkoDyakov
author_rank: Contributor
timestamp: April 22, 2024, 01:52:11 pm
content: Quote from: moffy on April 22, 2024, 12:25:23 pmThis is correct. The signals bellow are one of four pair of signal generated. Each pear is shifter 90 deg from the one before it. And inside the pair each signal is 180 degree shifted.You can see that it is PWM with variable duty cycle. In my mind this is like digitizing the sine wave and encode the duty cycle corresponding to each sample point.*in my case it does not go negative just goes to 0

author: moffy
author_rank: Super Contributor
timestamp: April 22, 2024, 08:09:13 pm
content: That makes some sense, I think personally, that I would filter the PWM signal to sinusoidal before applying it to the sensor, that way you are only adding sine waves of a single frequency and you have a direct comparison between excitation and output without the need of phase shifting filters. You might need a buffer amp, that's a small disadvantage but it would make problem solving much easier to visualise, even if it is only for development purposes.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: April 23, 2024, 08:25:12 am
content: MitkoDyakov would you please share kicad project files including schematic and PCB into the project repo, also for easier access please mention the GitHub repo in here too.This is a working Zero crossing code that I have implemented before on some industrial equipment, it uses 64 samples per sine wave cycle to calculate the Zero crossingCode:#define ADC_samples64//we need two cycles to calculate the Frequency, ok!short oldSamples;const int BLOCK_SIZE =ADC_samples;const int NUM_TAPS =32;arm_fir_instance_q15 S;q15_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1];q15_t firCoeffs32 = {-1, -2, 8, 39, 83, 97, 14, -213, -535,-762, -596, 232, 1778, 3773, 5659, 6810, 6810, 5659,3773, 1778, 232, -596, -762, -535, -213, 14, 97,83, 39, 8, -2, -1};void init_myFilter(void){/* Call FIR init function to initialize the instance structure. */arm_fir_init_q15(&S, NUM_TAPS, firCoeffs32, firStateF32, BLOCK_SIZE);}void dsp_zero_cross(short* input,int size,float* zero_1st,float* zero_2st, float* zero_3st){int i;float first_zero = 0,second_zero = 0,third_zero = 0;int index = {0};int index_index = 0;int x1 = 0;int x2 = 0;int x3 = 0;short temp;//first copy from the last portion to the first portionfor(i=64;i<128;i++)oldSamples[i-64] = oldSamples;//now copy the input to the last portionfor(i=64;i<128;i++)oldSamples= input[i-64];arm_fir_fast_q15(&S,oldSamples,temp,BLOCK_SIZE);arm_fir_fast_q15(&S,oldSamples+64,temp,BLOCK_SIZE);for (i = 1; i < size; i++){if((temp<=0 && temp[i-1]>0) || (temp>=0 && temp[i-1]<0)){index = i;index_index++;if(index_index == 4){break;}}}if(index_index == 0){*zero_2st=-1;*zero_1st=-1;*zero_3st=-1;return;}else if(index_index == 1){*zero_2st=-1;*zero_1st=-1;*zero_3st=-1;return;}else if (index_index == 2){x1 = index;x2 = index;if((temp[x1 - 1] - temp) == 0 || (temp[x1 + 1] - temp) == 0 || (temp[x2 - 1] - temp) == 0 || (temp[x2 + 1] - temp) == 0 || x2 == (size - 1) || x1 == (size - 1)){*zero_2st=-1;*zero_1st=-1;*zero_3st=-1;return;}else{first_zero = ((float)(temp * temp[x1 + 1])/((float)(temp[x1 - 1] - temp)*(float)(temp[x1 - 1] - temp[x1 + 1]))) * (x1 - 1);first_zero += ((float)(temp[x1 - 1] * temp[x1 + 1])/((float)(temp - temp[x1 - 1])*(float)(temp - temp[x1+ 1]))) * (x1);first_zero += ((float)(temp[x1 - 1] * temp)/((float)(temp[x1 + 1] - temp[x1 - 1])*(float)(temp[x1 + 1] - temp))) * (x1 + 1);////////////////////second_zero = ((float)(temp * temp[x2 + 1])/((float)(temp[x2 - 1] - temp)*(float)(temp[x2 - 1] - temp[x2 + 1]))) * (x2 - 1);second_zero += ((float)(temp[x2 - 1] * temp[x2 + 1])/((float)(temp - temp[x2- 1])*(float)(temp - temp[x2 + 1]))) * (x2);second_zero += ((float)(temp[x2 - 1] * temp)/((float)(temp[x2 + 1] - temp[x2 - 1])*(float)(temp[x2 + 1] - temp))) * (x2 + 1);*zero_1st = first_zero;*zero_2st = second_zero;*zero_3st=-1;return;}}else if (index_index == 3){x1 = index;x2 = index;x3 = index;if((temp[x1 - 1] - temp) == 0 || (temp[x1 + 1] - temp) == 0 || (temp[x2 - 1] - temp) == 0 || (temp[x2 + 1] - temp) == 0|| (temp[x3 - 1] - temp) == 0 || (temp[x3 + 1] - temp) == 0 || x3 == (size - 1) || x2 == (size - 1) || x1 == (size - 1)){*zero_2st=-1;*zero_1st=-1;*zero_3st=-1;return;}else{first_zero = ((float)(temp * temp[x1 + 1])/((float)(temp[x1 - 1] - temp)*(float)(temp[x1 - 1] - temp[x1 + 1]))) * (x1 - 1);first_zero += ((float)(temp[x1 - 1] * temp[x1 + 1])/((float)(temp - temp[x1 - 1])*(float)(temp - temp[x1+ 1]))) * (x1);first_zero += ((float)(temp[x1 - 1] * temp)/((float)(temp[x1 + 1] - temp[x1 - 1])*(float)(temp[x1 + 1] - temp))) * (x1 + 1);////////////////////second_zero = ((float)(temp * temp[x2 + 1])/((float)(temp[x2 - 1] - temp)*(float)(temp[x2 - 1] - temp[x2 + 1]))) * (x2 - 1);second_zero += ((float)(temp[x2 - 1] * temp[x2 + 1])/((float)(temp - temp[x2- 1])*(float)(temp - temp[x2 + 1]))) * (x2);second_zero += ((float)(temp[x2 - 1] * temp)/((float)(temp[x2 + 1] - temp[x2 - 1])*(float)(temp[x2 + 1] - temp))) * (x2 + 1);///////////////////third_zero = ((float)(temp * temp[x3 + 1])/((float)(temp[x3 - 1] - temp)*(float)(temp[x3 - 1] - temp[x3 + 1]))) * (x3 - 1);third_zero += ((float)(temp[x3 - 1] * temp[x3 + 1])/((float)(temp - temp[x3 - 1])*(float)(temp - temp[x3+ 1]))) * (x3);third_zero += ((float)(temp[x3 - 1] * temp)/((float)(temp[x3 + 1] - temp[x3 - 1])*(float)(temp[x3 + 1] - temp))) * (x3 + 1);*zero_1st = first_zero;*zero_2st = second_zero;*zero_3st= third_zero;}}}

author: MitkoDyakov
author_rank: Contributor
timestamp: April 23, 2024, 07:35:37 pm
content: You can find the all I have here:https://github.com/MitkoDyakov/BluePillCaliper/Documents - are all written I could find on the subject, patents, paper, work done by others.Hardware - the footprints for the t-scale and sensor and also gerbers and schematicsSoftware - I need to update that but, for the software I have written just the excitation of the pads and the display.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: April 24, 2024, 09:49:01 am
content: QuoteThanks for sharing, But it would be nicer if you could share the Kickad files for schematics and PCB, since We can modify it easier.

author: MitkoDyakov
author_rank: Contributor
timestamp: April 25, 2024, 06:40:55 pm
content: Quote from: ali_asadzadeh on April 24, 2024, 09:49:01 amYou can find it in BluePillCaliper/Hardware /Footprints - KICA

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: April 27, 2024, 07:46:47 am
content: QuoteThere is only footprints, Kicad project files extensions is like this .kicad_pcb .kicad_pro .sch unless, I'm missing something :'(

author: MitkoDyakov
author_rank: Contributor
timestamp: April 27, 2024, 05:11:36 pm
content: here there arehttps://github.com/MitkoDyakov/BluePillCaliper/tree/main/Hardware/Footprints%20-%20KICAD/CaliperPCBhttps://github.com/MitkoDyakov/BluePillCaliper/tree/main/Hardware/Footprints%20-%20KICAD/CaliperBlade

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: April 28, 2024, 08:14:14 am
content: QuoteThanks for sharing, is there any updates regarding zero crossing?

author: MitkoDyakov
author_rank: Contributor
timestamp: May 07, 2024, 09:20:28 pm
content: I was looking at this schema on electronics stack exchange. Which seems to be what I need given the fact that I would power it from 3VAnd I build a prototype... a few prototypesThe ones I designed were tragic. I have questions for the design from stack exchange and they are the following:1. How do I choose values for C1 and C22. I understand why R1 and R2 are there, but I don't get why some people choose Mohm values for them but here 10k is fine3. I did not had MCP6021, but I did had MCP6V11. Is there anything special about MCP6021?And for people who will ask me about pictures from the scope. The "thing" had nothing resembling the original signal, looks random noise at 1.5V 50mV peak to peak.

author: tooki
author_rank: Super Contributor
timestamp: May 07, 2024, 11:17:28 pm
content: Quote from: MitkoDyakov on May 07, 2024, 09:20:28 pmPlease attach your images as attachments here, rather than embedding external URLs that don’t work.

author: notsob
author_rank: Frequent Contributor
timestamp: May 08, 2024, 01:57:24 am
content: How about these analogue oneshttps://ceeshop.com.au/products/limted-banana-calipers

author: MitkoDyakov
author_rank: Contributor
timestamp: May 08, 2024, 09:08:39 am
content: Quote from: notsob on May 08, 2024, 01:57:24 amthe hell with my project I am jumping ship to the banana calipers

author: MitkoDyakov
author_rank: Contributor
timestamp: June 29, 2024, 05:50:34 pm
content: I have updated the schematics. You can find my solution on the git hub repo and build logs are on the hackaday page - link in my first post.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 30, 2024, 08:40:07 am
content: Quotewhat are the updates? tell us the good newsThere is no software in the repo, is there any plan to add them too?

author: MitkoDyakov
author_rank: Contributor
timestamp: July 03, 2024, 07:39:10 pm
content: Hey Ali,I have added MCP6S21 and a fixed ref voltage using ADR510 and AD8603 wombo combo. This way I can amplify the signal and offset it to the middle of the ADC range. And also the amp gain is configurable with SPI which is great.There is no code because I just got the signal conditioning acceptable. I have send some boards to contributors that will help with this part.Stay tuned, to get the update you can like thehackadaypage. I will post here from time to time also.Cheers!

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: July 04, 2024, 10:30:24 am
content: QuoteThanks for the update, I think you should definitely add code and kickad project files to the repo (we have only Gerber files for now), so we can build and test and give feedback on every level, this way the project moves faster.

author: MitkoDyakov
author_rank: Contributor
timestamp: July 14, 2024, 06:33:03 pm
content: I can't figure something. Lets say we have this setup. Three plates the red one is connected to a MCU output and it is driven HIGH or LOW. The grey plate spans bellow the red and the blue plates but it is not connected to anything and finally the blue plate is connected to the ADC of the MCU.When we set the output of the MCU to HIGH we get this on the scope (which is kind of what we expect, but why does it go down):But when we go and set the output to LOW we get this:Now why does it dip bellow 0 volts?To take the screenshots I also connected the scope ground to the MCU ground. The measurements are taken from the "input" lead.

author: moffy
author_rank: Super Contributor
timestamp: July 14, 2024, 11:01:39 pm
content: It is a low value capacitor coupling the output of the MCU to the input of the ADC, which has resistance to 0V/gnd. The capacitor removes the DC and the resistor discharges the cap, a C-R circuit hence what you see.

author: jwet
author_rank: Frequent Contributor
timestamp: July 15, 2024, 04:28:06 am
content: I've done some playing with this kind of stuff over the years- I developed the DRO system for Sherline after looking at a bunch of low cost solutions. Here are a couple of inputs that I haven't seen in the discussion so far.Book- "Capacitive Sensors" by Baxter, IEEE press. Only text I've seen that covers these in detail. A small part of the book- engineering library?There was a project in "Home Shop Machinist"- Village Press many years ago on this topic. The guy ended up CNC engraving the spars himself. He couldn't get 1 meter length and the PCB accuracy wasn't great. The builder made the spars but used off the shelf readout heads that he could buy cheap that had something like SPI outputs. I've never seen the asics in these things for sale anywhere. I googled this article and it didn't pop right up- try Village Press.Good luck.

author: MitkoDyakov
author_rank: Contributor
timestamp: July 15, 2024, 03:29:00 pm
content: Quote from: jwet on July 15, 2024, 04:28:06 amOh this is gold, thank you so much.

author: MitkoDyakov
author_rank: Contributor
timestamp: July 21, 2024, 10:38:46 am
content: This analog stuff is a gift that keeps on giving. Now I have a new issue.My amplified signal rides on a crispy 50hz signalFrom what I read this could be remedied with Notch Filter. To implement this filter I need split power supply.Are there any options to do this with solution with single power supply?p.s. I am not complaing this is actually fascinating!

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: July 22, 2024, 09:27:19 am
content: My gift to your projectConnect the PWM signal with 50% duty cycle to STM32 the PWM frequency in my case is 64KHz,Please share the project kicad files along MCU code.

author: MitkoDyakov
author_rank: Contributor
timestamp: July 24, 2024, 08:47:56 pm
content: Quote from: ali_asadzadeh on July 22, 2024, 09:27:19 amUpdates, you can find on the hackaday page. What is this circuit called?

author: amyk
author_rank: Super Contributor
timestamp: July 26, 2024, 03:25:30 am
content: It will be hard to beat the cost of the cheap ones, but maybe you can decap one and see if they're using an MCU (4-bit? 8-bit?) or an ASIC.There is some more information about the type of capacitive sensor they use here:https://www.mdpi.com/2076-3417/8/12/2419/pdf?version=1543401417

author: MitkoDyakov
author_rank: Contributor
timestamp: August 01, 2024, 07:16:08 pm
content: Quote from: amyk on July 26, 2024, 03:25:30 amI have no delusions that I can make it cheaper. Cost is not the only factor. There is no module you can get to play around with regardless of price.On the decapping part there is this guyI had made progress after adding a simple notch filter. Also a hardware redesign could also improve the noise level.https://photos.app.goo.gl/LLSTbh9mK8QkKRbe8

author: MitkoDyakov
author_rank: Contributor
timestamp: November 14, 2024, 08:41:16 pm
content: I made a kit out of the project you can see it here:https://www.tindie.com/products/mdyakov/calipatron/

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: November 16, 2024, 02:28:58 pm
content: what's the new progress?