Sunday 20 May 2018

Quadrature decoder ideas for glass scales and rotary encoders on Arduino and AVR

Ever wonder how the Heidenhain glass scales, can measure at increments of 0,5 µm? if the graduation on the scale is only 20um? If you come from the digital world, there are four transitions so the minimum should be 4um.
This mystery made me read up on the Heidenhain signals 1VPP or 11 µAPP ( 1VSS, 11 µASS ) These are analog signals, if you read the older literature it becomes clear that photo sensitive devices are used to generate the current, the 1Vpp signals are probably pre-loaded with a 90ohm resistor. 
Vernier scales are similar, so are modulation techniques like QAM, QPSK. With glass scales there is no amplitude or phase modulation on top of the carrier, only two orthogonal signals, the rotational relationship between the two base-band signals (I/Q) translates to position, speed and velocity. 
So what advantages do analog signals have over digital? The states are infinite, limited only by noise. But how to extract infinite states from two orthogonal signals? Run them through an AD converter and calculate the angle., this will work but the system response is limited by conversion rate and calculation performance.

Investigating further I stumbled on CORDIC https://en.wikipedia.org/wiki/CORDIC

With a search for CORDIC Quardrature decoder, I found various other methods of Sine/Cosine to Digital Conversion
http://www.ichaus.de/upload/pdf/WP7en_High-Precision_Interpolation_140124.pdf

  Flash Conversion

 Vector -Tracking Conversion

 SAR Conversion with Sample-and- Hold Stage

 Continuous -Sampling A/D Conversion
Out of pure curiosity, I will implement the continuous sampling conversion with CORDIS lookup on the Arduino, and perhaps try the vector tracking conversion on the Attiny2313
Should this work, I will try to convert my Sino Digital scales to analog and see what accuracy I can achieve. Perhaps even build a Heidenhain scale interface for the Touch DRO Project.

Resources 

CORDIC


https://eprints.soton.ac.uk/267873/1/tcas1_cordic_review.pdf

https://www.mikrocontroller.net/articles/AVR-CORDIC

Linear interpolation

https://www.mikrocontroller.net/articles/AVR_Arithmetik/Sinus_und_Cosinus_(Lineare_Interpolation) 

Fast Sampling on AVR
http://yaab-arduino.blogspot.com/2015/02/fast-sampling-from-analog-input.html


http://wiki.linuxcnc.org/cgi-bin/wiki.pl?ResolverToQuadratureConverter


Tuesday 15 May 2018

Useful code snips for working with XML, CSV, and other flat file formats in perl, groovy, python, java, c, c++

Lock files in Windows batch scripts, avoid more than one instance running

REM Check if another instance is running, and exit if true
IF EXIST ".lock" exit 0

echo Batch file start at %time% %date% by %username%.> .lock

REM Script processing starts here

REM Script processing ends here
del .lock


Replace XML tag data with Perl

use strict;
use warnings;
use XML::Twig;

for ( glob "*.xml" ) {
        print "process file $_\n";

XML::Twig->new(
    pretty_print  => 'indented',
    twig_handlers => {
         PaymentAmount => sub {
            $_->set_text( '0' )->flush
        },
    },
)->parsefile_inplace( $_, 'orig_*' );

Groovy and Tokenize or Split

While using tokenize() if you want to discard fields or lines with no data might work as such,

List myList =  inputStream.getText().tokenize("\n\r")

it can not be used if you want to retain the offset format of CSV or pipe delimited fields, since it will not yield the entries with no data.

As example the second field will be discarded. "Line1"|"""|"Name"

Here we will need to use split

List lHeader = sHeader.split("\\|")

Another odd behavior is if you split with a pipe without escapes, "|", split returns an array of characters. This is probably documented, but I did not have the time yet to read all the documentation and can not find any reference to this behavior.

Chipmaster Gear Cutting

  Calculate all the possible gear combinations for the gear selector to cut a 15TPI thread: Imperial TPI C 5 24 20 Imperial TPI ...