Wednesday, September 4, 2013

Midtronics A018 current clamp pinout and signal

Bought a 2nd handed Midtronics A018 DC/AC clamp (Midtronics calls it Midtronics MDT-A018 Inductive Amp Clamp) to build a low cost DCA/ACA clamp meter. The connector of it is a Neutrik RJ45 with aluminum housing.

Analysis of the circuit


Inside the plastic case. found 2 half ring magnetic cores, and a PCB with 2 Hall effect sensors(marked 602C, can't find part number), 1 TS952I operational amplifier, 1 MC33272 2-ch OPA, 1 Analog switch (guess, Top marking: E3D AA).

Looks like some instrumental amplifier structure, final stage gain can be switched by analog switch. 2 Hall effect sensors and ring magnetic core can eliminate earth magnetic field.

Pinout

 @RJ45 connector
1: red -  V+, should be 5V, 5V at least, and max rated 5.25V
4: green -  GND
6: white -  Sensor voltage output, High range: ~3mV/A, Low range:~30mV/A, neutral at around 2V
5: black -  GND
8: yellow -  range switch, H:700A, L:70A

The cable is shielded.


Input and output signal

DC

Power supply 5V +/- 5%
Range switch: should be normal CMOS/TTL level, i.e. VIL: 0.8V, VIH: 2V
Output signal: voltage, 2V for +/- 0A, and (30mV or 3mV) / A, when current flows alone the arrow, output voltage goes higher. Output


Frequency/pulse response. 

(Simple current step test, DC power supply with current limit, oscilloscope Rigol DS1102E, and some switch. Wire winded 10T. Maybe should use some MOSFET's and a signal generator to test)
Setup:
  DC supply current limit 3A
  Oscilloscope: y:200mV/div, DC, 1X, BW limit 20MHz, x: 50us/div, trigger: rising edge for tr, falling edge for tf
  Sensor Range: Low
Result:
  tr (0A to ~50A): 120us
  tf (30A to 0A):  200us


Thanks for reading!

Friday, November 23, 2012

Fast and easy fixed point arctangent2 function (update 20121127)


  This article is written by the me in my spare time. And the following code is provided entirely free of charge. Donations would be greatly appreciated. Please consider donating to the BitCoin address below.

1Hy25upwMTZvxUp8RQxg1CposF15bCDxew


  A fast and easy fixed point atan2 (arctangent) function. Uses only 1 DIV and 2 MUL operations(and some add/sub). Way faster than float version when no FPU available. Reasonable result error, within  +/-0.0058rad (about 1 degree)
Currently written in highly portable standard C. Can be easily ported to any other. Include *HDL's, can be implemented on FPGA's / ASIC's, maybe, utilizing just 100-200 gates.
Suitable for phase / phase diff demodulation.
Even can be modified into an 8-bit version, runs even much faster on 8-bit MCU's(MCS51/Z80/PIC...), not tested yet.

  Thanks to David Wheeler's for his 'dirty' method :-)
references:
http://ostro.ced.berkeley.edu/~crisr/discuss/comments.php?DiscussionID=1208

To do:
1. A little bit more precise version, say, ~0.0001rad error
2. An 8-bit version for my favorite MCS51
3. A Verilog HDL version

Source code: (with test main(), and measures error)
update 20121127:
  New parameters, for better RMS/average/max error. And slightly modified test method

// intmath_atan2.c
//
// arctangent2 function in both FixedPoint and Floating Point
// using only 1 DIV's and 2 MUL's
//
// ** 16 bit signed integers as 16-bit fixed point in 0.16 format.
//      can be implemented on FPGA/ASIC
//
// Any very fast float version? What's the point? It's canceled!
// 
// TODO: a 3rd order version for higher precision?
//
// revisions:
//
//  0.1, Terrance, 20121123, int16_t version
//  0.2, Terrance, 20121127, selectable const list for better result

#include <stdint.h>

#ifdef TEST_MAIN
    #include <math.h>
    #include <stdio.h>

    // simple but (VERY VERY) unsafe min / max macros
    // NEVER EVER use these with function call nor ++/-- operants!
    #define MIN(a,b) (((a) < (b)) ? (a) : (b))
    #define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif

#define FIXP_PI   (0x7fff)
#define FIXP_H_PI (0x4000)

#define CONSTLIST 1

#if  1 == CONSTLIST
    // least rms error (error: avgabs 0.0012, rms:0.0015, max 0.0049rad)
    #define C1 4186
    #define KX 750
    #define KP 732
#elif 2 == CONSTLIST
    // least avg error (error: avgabs 0.0011, rms:0.0020, max 0.0081rad)
    #define C1 4205
    #define KX 782
    #define KP 740
#elif 3 == CONSTLIST
    // least max error (avg abs error 0.0015, rms:0.0018, max 0.0024rad)
    #define C1 4170
    #define KX 719
    #define KP 720
#endif


/*
 * fixed point arctangent function
 *
 * returns: theta = arctan(y/x)
 *   32767 for +Pi
 *  -32767 for -Pi
 *
 * patameters:
 *  x, y: [-32768..32767], any combinations, (0, 0) returns 0
 *
*/
int16_t fixpAtan2(int16_t y, int16_t x)
{
    // z, z05 and result can use only one 
    int16_t z, z05;  
    int16_t result;    
    int16_t absx, absy;

    absx = abs(x);
    absy = abs(y);
     
    // fold input values into first 45 degree sector
    if (0 == y && 0 == x) 
    {
        result = 0;
    } 
    else
    {
        if (absx > absy)
        {
            z = ((int32_t)absy << 13) / absx;
        }
        else
        {
            z = ((int32_t)absx << 13) / absy;
        }
        // z - 0.5 ........
        // z = abs(x / y) or abs(y / x), which is smaller than 1.0
        // fixed point, 8192 means 1.0
        z05 = z - C1;
        result = z - (((((int32_t)z05 * z05) >> 12) * KX) >> 12)  + KP;

        if (absx < absy)
        {
            result = FIXP_H_PI - result;
        }

        if(x < 0)
        {
            result =  FIXP_PI - result;
        }

        if(y < 0)
        {
            result = -result; 
        }
    } 
    return result;
}


#ifdef TEST_MAIN

int main()
{
    int16_t x = 0;
    int16_t y = 0;
    int32_t i = 0;
    int32_t n;
    float omega = 0;
    float phiReal, phiTest;

    //int16_t i;
    float errMax, errMin;
    float e;
    double sumerr, sumerr2, sumabserr;
    int32_t errSign;

    errMin =  1000;
    errMax = -1000;
    errSign = 0;
    sumerr2 = 0;
    sumerr = 0;
    sumabserr = 0;
    n = 10000000;
    for(i = 0; i < n; i++)
    {
        omega = ((float)(i % 65536)) / 32768 * M_PI;
        x = cos(omega) * (i >> 14);
        y = sin(omega) * (i >> 14);
        phiTest = (float)fixpAtan2(y, x) / 32767.0f * M_PI;
        phiReal = atan2f(y, x);
        e = phiTest - phiReal;
        // fix error around Pi and -Pi
        if(e > 6.0)
        {
            e -= 2 * M_PI;
        }
        else if(e < -6.0)
        {
            e += 2 * M_PI;
        }

        errMax = MAX(errMax, e);
        errMin = MIN(errMin, e);
        sumerr += e;
        sumerr2 += e * e;
        sumabserr += fabs(e);
    }



    printf("max error: (%f, %f), avg abs %f, rms %f\n"
            , errMin
            , errMax
            , sumabserr / n
            , sqrt((sumerr2 - sumerr * sumerr / n) / (n - 1))
          );


    return 0;
}
#endif
// <EOF> intmath_atan2.c

Have fun :-P

Friday, October 12, 2012

Nikon D2H/D2X shutter circuit and operating procedure

Nikon D2H/X shutter unit


This article is written by the me in my spare time. Donations would be greatly appreciated. Please consider donating to the BitCoin address below.

1Hy25upwMTZvxUp8RQxg1CposF15bCDxew



    Well, my D2H's shutter died at shutter count #49985, after showing 3+ years of annoying Err message, and the rear curtain shattered. The I bought a shutter unit of D2X (used part), and... Long story short, it's alive~~~~ Now, another 50k or 100k shutter life?

    I dig into the broken shutter. Ok, when you look into the F-mount of a D2, there're 4 gray shutter blades behind the mirror, which is the front curtain.

    Wanna see the Rear curtain? Not that simple. Normally, when a shot fired, the camera charges the shutter immediately. There's a way, use M mode, set to bulb, press the shutter button and hold your finger down, pull out the battery, lift the mirror carefully, then you will see the black rear blades, also 4 of them. Insert the battery, the top LCD will blink "Err". Relax, this is quite ok and harmless. Just press the shutter button, D2 will charge the shutter.

    Let's talk about circuit. There's a FPC connecting the shutter and body electronics. On the shutter, are 4 capacitors, 2 solenoid, 1 SOT23-5 device(dual NPN transistor with integrated resistors), and a gold plated leaf switch connected via 2 PVC wires, one green one red. The FPC connector, has 6 contacts, from left(according the photo) to right, i call then pin 1 to 6. The pinout is: 1:SW-FC, 2:V+(most likely 3.3~5V), 3:FC hold, 4:RC hold, 5:GND, 6:SW-RC. The switch is X-sync switch(shutter slower than 1/250s). When the FC open, this switch closes, that fires the flash, then the rear closes, a flashed photo is taken.

The schematics of FPC. R is about 20kohm, solenoid DCR 180ohm. (updated 20121016)

 

    Under the FPC, theres block of very complex mechanism with gears, springs, and levers. I'm a electronics engineer, don't know very well about that. But I know, the top lever with a bearing is the shutter charging lever, and the one at right side, near shutter blades, is shutter release lever.

Shutter unit detail


    That's it. The following is shutter operating steps:
    for shutter slower than 1/250s
  1. Shutter charged.
  2. Shutter button pressed
  3. pin 3, 4 goes high, FC and RC solenoid are powered. keeps both curtain from releasing.
  4. Electronics fires the mirror mechanism.
  5. Mirror lifted up, Shutter release lever is pressed by mirror mechanism.
  6. Shutter "safety off, ready to fire"
  7. pin 3 goes low, FC released,
  8. FC fully open (this takes about, let me guess, 3ms), SW_FC closes, flash fires
  9. Wait for time of shutter speed, for example 1/60s
  10. pin 4 goes low, RC release.
  11. 3ms later, RC fully closed, SW_RC close. if this time-out, "Err" message shows.
  12. Shutter charger pushes the charge lever, charges the shutter again, and mirror back down, both SW'es open.

for shutter faster than 1/250s

  1. Shutter charged.
  2. Shutter button pressed
  3. pin 3, 4 goes high, FC and RC solenoid are powered. keeps both curtain from releasing.
  4. Electronics fires the mirror mechanism.
  5. Mirror lifted up, Shutter release lever is pressed by mirror mechanism.
  6. Shutter "safety off, ready to fire"
  7. pin 3 goes low, FC released,
  8. Wait for time of shutter speed, for example T=1/1000s, 
  9. pin 4 goes low, RC release.
  10. FP flash fires, one pulse each time of T (or less). so the flash illuminates whole frame by multiple stripes, through the shutter gap. For FP sync detail, check http://www.scantips.com/lights/flashbasics2b.html and  http://www.photozone.de/hi-speed-flash-sync
  11. FC fully open, 3ms after FC released
  12. 3ms after RC released, RC fully closed, SW_RC close.
  13. Shutter charger pushes the charge lever, charges the shutter again, and mirror back down, both SW'es open.


  Thanks for reading!

Wednesday, July 11, 2012

Panorama hugin 攻略 V1.0



revision 1.0, 20120712

目录
just kidding, there's no TOC.




****拍摄阶段, 按重要性排列,第一条可以作为checklist


1. 要用手动曝光或者AE-L, 最好是M档
固定白平衡
手动感光度
手动聚焦或者AF-L,最好是MF
拍摄过程中绝对不要zoom,
拍摄的时候抓稳当然是基本的传统美德了。

2. 尽量不要拍到近景,近景因为透视问题,永远对不准,这一点可以后期mask掉然后crop掉。

3. 每一图都要有固定的物体,一定是建筑物。树木、洋大爷、浮云这些都是对不准的,而且要手动剔除非常繁琐,
如果画面里有移动物体,一定要等在那里,等物体移开了再拍一两张
如果不放心,每一个位置可以多拍几张,

4. 画面覆盖问题,广角的话图可以多一些密集一些,方便修正透视,长焦的只要中心移到上一张边缘即可

5. 注意覆盖区域的问题,以防出现木桶效应。


**** hugin阶段,按操作顺序排列

1. 先拼,后调片,原图直接转tiff 16 bit ,如果HDD不是问题,不要压缩tiff

2. hugin导入tiff或者jpg,选定一张中心照片,anchor之,

3. do NOT press the "Align..."  button!!!

4. 设置cpfind , 在cmd+, CP detecter那里,最好是new一个啦
建议参数 --celeste --linearmatch -o %o %s,
这个参数适合1行或者1列的pano,请注意--linearmatch 的意思是只对准相邻图片,这样会快无数倍,但是要注意图片顺序

5. 检查一下其他设置,
general:
  Image cache: 2047MB, 不够用的话就小一点咯
assistant:
  Remove cloud like CP (Celeste), check!
  Points per Overlap 60
  downscale final pano: 100 100 100!!! no fucking 70%
CP editor:
  patch width 32
  search area width 1~3
  local searcharea width: no change ,or 14
  Correlation threashoad: 0.95 (for high quality  DSLR photos)
Celeste
  SVM threshold: 0.35~0.4  低过0.3可能会导致所有的CP被删掉

6. 在 Images 那里,检查设置  Points per Overlap 60~100,多一点没关系的,后面会删掉很多,
然后按 Create CPs
照我建议的设置,这个步骤会很快

7 CMD+t
会看到统计数据,平均误差,标准差和最大误差,这些都没关系
最大误差在几十以内是正常的,平均值应该很小,不超过10,如果看到几千,就要手工对准了


8。极其重要的!!!!!!!!!!!!
点一下 GL那个按钮,看看是不是所有图片都放对地方了,
然后 设置投影类型 projection,如果是接近或者超过180度的pano,建议用cylindrical,窄范围的单个建筑,可以用rectilinear
drag一下,把东西都放正
crop那里,auto一下
调整这些会影响后面的对准,对准之后再调投影的话,可能会偏离很远


9. 按一下 Show Controll points按钮,把CP按照distance排序
a. Edit -> Fine Tune All CPs, 然后在列表里删掉 distance小于0.9左右的点,悠着点,不要一次删掉一半问题应该不大
b. CMD+T , 然后删掉列表里 distance 远大于(比如5)的点
c. 到images tab, 选中所有图片(点第一个,然后shift点最后一个),点"Run
Celeste",如果remove掉的点很少,可以减小前面设置的 SVM threashold,如果所有的点都被干掉了,cmd+z
反复上面的abcabcabab
每一次都可以更严格一点。c不用每次都做,原则就是保持至少图片数量x20个cp,如果有闲心,可以检查一下每一个cp,手动删掉各种五星红旗、墙头草、洋大爷、飞驰的法拉利、女优、肉灵芝、浮云之类的东西上面的cp。
最后如果图片质量比较好,应该可以有足够多的cp使对准误差远小于1,最大值也就在1附近,如果最大值都小于1,那么应该使完全无法分辨出接缝的了。

optimizer那里有兴趣可以研究一下,不要同时optimize太多东西,否则可能会导致算法不收敛。一般 y,p,r,v,b就足够了
customize的时候要注意一定要有至少1图是没有选中的,用来定位。

10. exposure, 如果锁定了曝光量而且当时天气比较稳定,就不要做exposure里的optimize

cmd + s, 显然,应该随时cmd + s.如果有什么灾难发生, cmd + z

****输出阶段
水果上输出很容易crash,要注意一下

在stitcher tab
点 Calculate FOV, 然后点 calculate optimal size
Pano outputs: 只选 exposure corrected, LDR
remapped Image, 只选 exposure corrected, LDR
不管输出什么,都不要压缩, compression: none
底下blender options,写 -l 12 --fine-mask --no-optimize, 也可以不写,万一crash后面再处理

现在, press "Stitch Now..."
等待完成或者crash
如果完成,爱干嘛干嘛去吧

如果crash
会有一个输出窗口
找到命令行
比如

/Applications/Hugin/PTBatcherGUI.app/Contents/MacOS/enblend
--compression=LZW -f9152x3085+0+418 -o DSC_5447-DSC_5465.tif --
DSC_5447-DSC_54650000.tif DSC_5447-DSC_54650001.tif
DSC_5447-DSC_54650002.tif DSC_5447-DSC_54650003.tif
DSC_5........ 一大串

copy到某处
修改一下,加上一些参数

/Applications/Hugin/PTBatcherGUI.app/Contents/MacOS/enblend
--compression=none  -l 12 --fine-mask --no-optimize  -f9152x3085+0+418
-o DSC_5447-DSC_5465.tif -- DSC_5447-DSC_546500??.tif

在这个工作目录里的terminal里运行即可
如果还TMD crash,减小 -l 12 那个数值, 如果照片是按照本攻略拍摄的,减小到1都不会有大的质量问题,只是接缝会硬一点

--终了--