Post Go back to editing

Impedance and Phase error when measuring sub 45Hz using EVAL AD5940ELCZ

Hello AD team,

I connected a 3.9uF capacitor in parallel with 1M Ohm resistor using red and green probe of EVAL AD5940 ELCZ.

I performed impedance measurement from 1Hz-100Hz using sensor pal.

I have attached the results below.

The red curve is output we got from sensorpal while black curve is what we got by theoretical calculation .

There is huge deviation in impedance phase values and magnitude values in the sub 45Hz.

How do I overcome this hurdle ?

The RTIA was 1Kohm and Rcal was 10Kohm.

Attached the results for reference 

Resistor Value Capacitor Value Frequency Impedance Phase Expected Magnitude Expected Phase (Radian) Amplitude RTIA RCal Phase (Radian)
9.80E+05 3.80E-06 1.00 1.35E+04 -18.39813995 4.09E+04 -1.529036328 600 mVpp 1000 Ohms 10000 Ohms -0.3211081184
9.80E+05 3.80E-06 1.13 8.61E+03 -0.238496557 3.62E+04 -1.533835918 600 mVpp 1000 Ohms 10000 Ohms -0.004162550174
9.80E+05 3.80E-06 1.28 8.44E+03 -0.292796552 3.20E+04 -1.538163938 600 mVpp 1000 Ohms 10000 Ohms -0.005110263871
9.80E+05 3.80E-06 1.45 8.27E+03 -0.37071538 2.82E+04 -1.541987547 600 mVpp 1000 Ohms 10000 Ohms -0.006470203969
9.80E+05 3.80E-06 1.65 8.10E+03 -0.47057274 2.48E+04 -1.545477925 600 mVpp 1000 Ohms 10000 Ohms -0.008213043683
9.80E+05 3.80E-06 1.87 7.95E+03 -0.577355921 2.19E+04 -1.548455504 600 mVpp 1000 Ohms 10000 Ohms -0.01007676178
9.80E+05 3.80E-06 2.11 7.80E+03 -0.727155626 1.94E+04 -1.550995933 600 mVpp 1000 Ohms 10000 Ohms -0.01269125985
9.80E+05 3.80E-06 2.40 7.66E+03 -0.917663276 1.71E+04 -1.553387964 600 mVpp 1000 Ohms 10000 Ohms -0.01601624559
9.80E+05 3.80E-06 2.71 7.54E+03 -1.140491366 1.51E+04 -1.555378991 600 mVpp 1000 Ohms 10000 Ohms -0.01990532943
9.80E+05 3.80E-06 3.08 7.44E+03 -1.432727814 1.33E+04 -1.557230831 600 mVpp 1000 Ohms 10000 Ohms -0.02500581764
9.80E+05 3.80E-06 3.48 7.36E+03 -1.808647871 1.18E+04 -1.558789924 600 mVpp 1000 Ohms 10000 Ohms -0.03156686036
9.80E+05 3.80E-06 3.95 7.32E+03 -2.282594681 1.04E+04 -1.56021842 600 mVpp 1000 Ohms 10000 Ohms -0.03983879267
9.80E+05 3.80E-06 4.47 7.33E+03 -2.909442186 9.16E+03 -1.561448883 600 mVpp 1000 Ohms 10000 Ohms -0.05077934554
9.80E+05 3.80E-06 5.07 7.39E+03 -3.756836414 8.08E+03 -1.562555036 600 mVpp 1000 Ohms 10000 Ohms -0.06556916488
9.80E+05 3.80E-06 5.74 7.54E+03 -4.923104763 7.13E+03 -1.563516962 600 mVpp 1000 Ohms 10000 Ohms -0.08592438753
9.80E+05 3.80E-06 6.50 7.80E+03 -6.59972477 6.30E+03 -1.564368063 600 mVpp 1000 Ohms 10000 Ohms -0.115186927
9.80E+05 3.80E-06 7.37 8.24E+03 -9.132715225 5.56E+03 -1.565126877 600 mVpp 1000 Ohms 10000 Ohms -0.1593959503
9.80E+05 3.80E-06 8.35 8.95E+03 -13.22070694 4.90E+03 -1.565792262 600 mVpp 1000 Ohms 10000 Ohms -0.2307448655
9.80E+05 3.80E-06 9.46 1.01E+04 -20.33692932 4.33E+03 -1.566379411 600 mVpp 1000 Ohms 10000 Ohms -0.3549463764
9.80E+05 3.80E-06 10.71 1.17E+04 -33.50328827 3.82E+03 -1.566894919 600 mVpp 1000 Ohms 10000 Ohms -0.5847426906
9.80E+05 3.80E-06 12.14 1.27E+04 -57.7800293 3.37E+03 -1.567354471 600 mVpp 1000 Ohms 10000 Ohms -1.008451753
9.80E+05 3.80E-06 13.75 1.03E+04 -87.74534607 2.98E+03 -1.567757479 600 mVpp 1000 Ohms 10000 Ohms -1.531445192
9.80E+05 3.80E-06 15.58 6.61E+03 253.3288116 2.63E+03 -1.568114415 600 mVpp 1000 Ohms 10000 Ohms 4.421421853
9.80E+05 3.80E-06 17.65 4.20E+03 247.0557861 2.32E+03 -1.568428949 600 mVpp 1000 Ohms 10000 Ohms 4.311936904
9.80E+05 3.80E-06 20.00 2.89E+03 -111.9496994 2.05E+03 -1.568707115 600 mVpp 1000 Ohms 10000 Ohms -1.953890851
9.80E+05 3.80E-06 21.00 2.12E+03 -116.5593948 1.95E+03 -1.568806601 600 mVpp 1000 Ohms 10000 Ohms -2.034345213
9.80E+05 3.80E-06 21.68 2.40E+03 -109.9438782 1.89E+03 -1.568869009 600 mVpp 1000 Ohms 10000 Ohms -1.918882667
9.80E+05 3.80E-06 22.38 2.25E+03 -109.2482681 1.83E+03 -1.568929292 600 mVpp 1000 Ohms 10000 Ohms -1.90674198
9.80E+05 3.80E-06 23.10 2.12E+03 -108.7293472 1.77E+03 -1.568987485 600 mVpp 1000 Ohms 10000 Ohms -1.897685102
9.80E+05 3.80E-06 23.84 2.00E+03 -108.4245148 1.72E+03 -1.569043632 600 mVpp 1000 Ohms 10000 Ohms -1.892364773
9.80E+05 3.80E-06 24.61 1.88E+03 -108.2996368 1.66E+03 -1.56909847 600 mVpp 1000 Ohms 10000 Ohms -1.890185241
9.80E+05 3.80E-06 25.41 1.76E+03 -108.2882767 1.61E+03 -1.569151925 600 mVpp 1000 Ohms 10000 Ohms -1.88998697
9.80E+05 3.80E-06 26.23 1.65E+03 -108.2441635 1.56E+03 -1.569203332 600 mVpp 1000 Ohms 10000 Ohms -1.889217049
9.80E+05 3.80E-06 27.07 1.52E+03 -108.0353699 1.51E+03 -1.569252764 600 mVpp 1000 Ohms 10000 Ohms -1.885572913
9.80E+05 3.80E-06 27.95 1.41E+03 -107.3981247 1.47E+03 -1.569301362 600 mVpp 1000 Ohms 10000 Ohms -1.874450886
9.80E+05 3.80E-06 28.85 1.29E+03 -106.1757889 1.42E+03 -1.569347999 600 mVpp 1000 Ohms 10000 Ohms -1.853117102
9.80E+05 3.80E-06 29.78 1.19E+03 -104.1839371 1.38E+03 -1.569393229 600 mVpp 1000 Ohms 10000 Ohms -1.81835273
9.80E+05 3.80E-06 30.74 1.10E+03 -101.4736099 1.33E+03 -1.569437047 600 mVpp 1000 Ohms 10000 Ohms -1.771048597
9.80E+05 3.80E-06 31.73 1.03E+03 -98.09866333 1.29E+03 -1.569479457 600 mVpp 1000 Ohms 10000 Ohms -1.712144667
9.80E+05 3.80E-06 32.76 9.83E+02 -94.40154266 1.25E+03 -1.569520861 600 mVpp 1000 Ohms 10000 Ohms -1.647617738
9.80E+05 3.80E-06 33.81 9.52E+02 -90.65748596 1.21E+03 -1.569560471 600 mVpp 1000 Ohms 10000 Ohms -1.582271622
9.80E+05 3.80E-06 34.90 9.37E+02 -87.31919098 1.17E+03 -1.56959907 600 mVpp 1000 Ohms 10000 Ohms -1.524007383
9.80E+05 3.80E-06 36.03 9.33E+02 -84.60423279 1.14E+03 -1.569636619 600 mVpp 1000 Ohms 10000 Ohms -1.476622423
9.80E+05 3.80E-06 37.19 9.33E+02 -82.69508362 1.10E+03 -1.569672792 600 mVpp 1000 Ohms 10000 Ohms -1.443301484
9.80E+05 3.80E-06 38.39 9.34E+02 -81.48303986 1.07E+03 -1.569707911 600 mVpp 1000 Ohms 10000 Ohms -1.42214733
9.80E+05 3.80E-06 39.63 9.32E+02 -80.84385681 1.03E+03 -1.569741967 600 mVpp 1000 Ohms 10000 Ohms -1.410991481
9.80E+05 3.80E-06 40.91 9.25E+02 -80.56869507 1.00E+03 -1.569774956 600 mVpp 1000 Ohms 10000 Ohms -1.406189003
9.80E+05 3.80E-06 42.23 9.12E+02 -80.48643494 9.70E+02 -1.569806881 600 mVpp 1000 Ohms 10000 Ohms -1.404753293
9.80E+05 3.80E-06 43.59 8.96E+02 -80.42145538 9.39E+02 -1.569837752 600 mVpp 1000 Ohms 10000 Ohms -1.403619186
9.80E+05 3.80E-06 45.00 8.79E+02 -80.39859009 9.10E+02 -1.569867787 600 mVpp 1000 Ohms 10000 Ohms -1.403220111
9.80E+05 3.80E-06 46.00 8.97E+02 -81.8403244 8.90E+02 -1.569887973 600 mVpp 1000 Ohms 10000 Ohms -1.428383122
9.80E+05 3.80E-06 46.51 8.60E+02 -80.43099976 8.80E+02 -1.569897933 600 mVpp 1000 Ohms 10000 Ohms -1.403785766
9.80E+05 3.80E-06 47.03 8.53E+02 -80.45091248 8.71E+02 -1.569907867 600 mVpp 1000 Ohms 10000 Ohms -1.404133309
9.80E+05 3.80E-06 47.55 8.47E+02 -80.50719452 8.61E+02 -1.569917583 600 mVpp 1000 Ohms 10000 Ohms -1.405115616
9.80E+05 3.80E-06 48.08 8.40E+02 -80.55807495 8.52E+02 -1.569927269 600 mVpp 1000 Ohms 10000 Ohms -1.406003647
9.80E+05 3.80E-06 48.62 8.32E+02 -80.64744568 8.42E+02 -1.569936922 600 mVpp 1000 Ohms 10000 Ohms -1.40756346
9.80E+05 3.80E-06 49.16 8.25E+02 -80.72372437 8.33E+02 -1.569946362 600 mVpp 1000 Ohms 10000 Ohms -1.408894775
9.80E+05 3.80E-06 49.71 8.17E+02 -80.82434845 8.24E+02 -1.569955766 600 mVpp 1000 Ohms 10000 Ohms -1.410650996
9.80E+05 3.80E-06 50.26 8.09E+02 -80.92531586 8.15E+02 -1.569964964 600 mVpp 1000 Ohms 10000 Ohms -1.41241321
9.80E+05 3.80E-06 50.82 8.01E+02 -81.01837158 8.06E+02 -1.569974125 600 mVpp 1000 Ohms 10000 Ohms -1.414037339
9.80E+05 3.80E-06 51.39 7.91E+02 -81.115448 7.97E+02 -1.569983245 600 mVpp 1000 Ohms 10000 Ohms -1.415731642
9.80E+05 3.80E-06 51.96 7.82E+02 -81.19120789 7.88E+02 -1.569992164 600 mVpp 1000 Ohms 10000 Ohms -1.417053901
9.80E+05 3.80E-06 52.54 7.72E+02 -81.23768616 7.79E+02 -1.570001042 600 mVpp 1000 Ohms 10000 Ohms -1.4178651
9.80E+05 3.80E-06 53.12 7.62E+02 -81.25326538 7.71E+02 -1.570009725 600 mVpp 1000 Ohms 10000 Ohms -1.418137009
9.80E+05 3.80E-06 53.71 7.52E+02 -81.24104309 7.62E+02 -1.570018366 600 mVpp 1000 Ohms 10000 Ohms -1.41792369
9.80E+05 3.80E-06 54.31 7.42E+02 -81.17084503 7.54E+02 -1.570026961 600 mVpp 1000 Ohms 10000 Ohms -1.416698502
9.80E+05 3.80E-06 54.91 7.32E+02 -81.06838989 7.46E+02 -1.570035367 600 mVpp 1000 Ohms 10000 Ohms -1.414910323
9.80E+05 3.80E-06 55.53 7.22E+02 -80.92446899 7.37E+02 -1.570043864 600 mVpp 1000 Ohms 10000 Ohms -1.412398429
9.80E+05 3.80E-06 56.14 7.12E+02 -80.73553467 7.29E+02 -1.57005204 600 mVpp 1000 Ohms 10000 Ohms -1.409100903
9.80E+05 3.80E-06 56.77 7.03E+02 -80.50836945 7.21E+02 -1.570060299 600 mVpp 1000 Ohms 10000 Ohms -1.405136122
9.80E+05 3.80E-06 57.40 6.95E+02 -80.26184082 7.13E+02 -1.570068378 600 mVpp 1000 Ohms 10000 Ohms -1.400833386
9.80E+05 3.80E-06 58.04 6.87E+02 -79.99280548 7.06E+02 -1.570076405 600 mVpp 1000 Ohms 10000 Ohms -1.396137834
9.80E+05 3.80E-06 58.69 6.79E+02 -79.71038055 6.98E+02 -1.570084378 600 mVpp 1000 Ohms 10000 Ohms -1.391208589
9.80E+05 3.80E-06 59.34 6.72E+02 -79.43531799 6.90E+02 -1.570092176 600 mVpp 1000 Ohms 10000 Ohms -1.386407841
9.80E+05 3.80E-06 60.00 6.65E+02 -79.14955139 6.82E+02 -1.570099922 600 mVpp 1000 Ohms 10000 Ohms -1.381420273
9.80E+05 3.80E-06 61.00 6.59E+02 -77.99105835 6.71E+02 -1.570111339 600 mVpp 1000 Ohms 10000 Ohms -1.361200755
9.80E+05 3.80E-06 61.69 6.50E+02 -78.55979156 6.64E+02 -1.570119 600 mVpp 1000 Ohms 10000 Ohms -1.371127022
9.80E+05 3.80E-06 62.39 6.44E+02 -78.35709381 6.56E+02 -1.5701266 600 mVpp 1000 Ohms 10000 Ohms -1.367589279
9.80E+05 3.80E-06 63.10 6.39E+02 -78.18309784 6.49E+02 -1.570134135 600 mVpp 1000 Ohms 10000 Ohms -1.364552477
9.80E+05 3.80E-06 63.82 6.33E+02 -78.02707672 6.42E+02 -1.570141606 600 mVpp 1000 Ohms 10000 Ohms -1.361829394
9.80E+05 3.80E-06 64.55 6.27E+02 -77.89477539 6.34E+02 -1.57014901 600 mVpp 1000 Ohms 10000 Ohms -1.359520301
9.80E+05 3.80E-06 65.28 6.22E+02 -77.77585602 6.27E+02 -1.570156249 600 mVpp 1000 Ohms 10000 Ohms -1.357444766
9.80E+05 3.80E-06 66.02 6.16E+02 -77.65982819 6.20E+02 -1.570163423 600 mVpp 1000 Ohms 10000 Ohms -1.355419698
9.80E+05 3.80E-06 66.77 6.10E+02 -77.55241394 6.13E+02 -1.570170532 600 mVpp 1000 Ohms 10000 Ohms -1.353544966
9.80E+05 3.80E-06 67.53 6.04E+02 -77.43624878 6.06E+02 -1.570177575 600 mVpp 1000 Ohms 10000 Ohms -1.351517502
9.80E+05 3.80E-06 68.30 5.98E+02 -77.32582855 6.00E+02 -1.570184551 600 mVpp 1000 Ohms 10000 Ohms -1.349590305
9.80E+05 3.80E-06 69.07 5.93E+02 -77.22029877 5.93E+02 -1.570191371 600 mVpp 1000 Ohms 10000 Ohms -1.347748463
9.80E+05 3.80E-06 69.86 5.87E+02 -77.10623932 5.86E+02 -1.570198212 600 mVpp 1000 Ohms 10000 Ohms -1.34575775
9.80E+05 3.80E-06 70.65 5.81E+02 -77.00614166 5.80E+02 -1.5702049 600 mVpp 1000 Ohms 10000 Ohms -1.344010716
9.80E+05 3.80E-06 71.45 5.76E+02 -76.91431427 5.73E+02 -1.570211522 600 mVpp 1000 Ohms 10000 Ohms -1.342408026
9.80E+05 3.80E-06 72.27 5.70E+02 -76.8363266 5.67E+02 -1.570218158 600 mVpp 1000 Ohms 10000 Ohms -1.341046884
9.80E+05 3.80E-06 73.09 5.65E+02 -76.76275635 5.60E+02 -1.570224644 600 mVpp 1000 Ohms 10000 Ohms -1.339762841
9.80E+05 3.80E-06 73.92 5.59E+02 -76.69864655 5.54E+02 -1.570231063 600 mVpp 1000 Ohms 10000 Ohms -1.338643914
9.80E+05 3.80E-06 74.76 5.53E+02 -76.63687897 5.48E+02 -1.570237414 600 mVpp 1000 Ohms 10000 Ohms -1.337565866
9.80E+05 3.80E-06 75.61 5.48E+02 -76.58422089 5.42E+02 -1.570243698 600 mVpp 1000 Ohms 10000 Ohms -1.33664681
9.80E+05 3.80E-06 76.47 5.42E+02 -76.5246048 5.35E+02 -1.570249913 600 mVpp 1000 Ohms 10000 Ohms -1.335606313
9.80E+05 3.80E-06 77.33 5.35E+02 -76.4522934 5.30E+02 -1.570255989 600 mVpp 1000 Ohms 10000 Ohms -1.334344241
9.80E+05 3.80E-06 78.21 5.29E+02 -76.36476898 5.24E+02 -1.570262069 600 mVpp 1000 Ohms 10000 Ohms -1.332816651
9.80E+05 3.80E-06 79.10 5.23E+02 -76.23710632 5.18E+02 -1.57026808 600 mVpp 1000 Ohms 10000 Ohms -1.330588517
9.80E+05 3.80E-06 80.00 5.17E+02 -76.08773041 5.12E+02 -1.570274023 600 mVpp 1000 Ohms 10000 Ohms -1.327981416
9.80E+05 3.80E-06 81.00 5.09E+02 -75.47273254 5.06E+02 -1.570280471 600 mVpp 1000 Ohms 10000 Ohms -1.317247678
9.80E+05 3.80E-06 81.71 5.06E+02 -75.73214722 5.01E+02 -1.570284954 600 mVpp 1000 Ohms 10000 Ohms -1.321775319
9.80E+05 3.80E-06 82.43 5.01E+02 -75.56130219 4.97E+02 -1.57028942 600 mVpp 1000 Ohms 10000 Ohms -1.31879351
9.80E+05 3.80E-06 83.16 4.97E+02 -75.39727783 4.92E+02 -1.57029387 600 mVpp 1000 Ohms 10000 Ohms -1.315930745
9.80E+05 3.80E-06 83.90 4.93E+02 -75.21935272 4.88E+02 -1.570298302 600 mVpp 1000 Ohms 10000 Ohms -1.312825366
9.80E+05 3.80E-06 84.64 4.89E+02 -75.04027557 4.84E+02 -1.570302656 600 mVpp 1000 Ohms 10000 Ohms -1.30969988
9.80E+05 3.80E-06 85.38 4.85E+02 -74.87744904 4.80E+02 -1.570306935 600 mVpp 1000 Ohms 10000 Ohms -1.306858021
9.80E+05 3.80E-06 86.13 4.82E+02 -74.71611786 4.75E+02 -1.570311196 600 mVpp 1000 Ohms 10000 Ohms -1.304042261
9.80E+05 3.80E-06 86.89 4.78E+02 -74.56777954 4.71E+02 -1.57031544 600 mVpp 1000 Ohms 10000 Ohms -1.301453269
9.80E+05 3.80E-06 87.66 4.74E+02 -74.42116547 4.67E+02 -1.570319664 600 mVpp 1000 Ohms 10000 Ohms -1.298894371
9.80E+05 3.80E-06 88.43 4.71E+02 -74.28987885 4.63E+02 -1.570323814 600 mVpp 1000 Ohms 10000 Ohms -1.296602987
9.80E+05 3.80E-06 89.21 4.67E+02 -74.16022491 4.59E+02 -1.570327946 600 mVpp 1000 Ohms 10000 Ohms -1.294340099
9.80E+05 3.80E-06 90.00 4.64E+02 -74.04009247 4.55E+02 -1.570332057 600 mVpp 1000 Ohms 10000 Ohms -1.292243392
9.80E+05 3.80E-06 90.79 4.60E+02 -73.91745758 4.51E+02 -1.570336097 600 mVpp 1000 Ohms 10000 Ohms -1.290103009
9.80E+05 3.80E-06 91.59 4.57E+02 -73.80146027 4.47E+02 -1.570340117 600 mVpp 1000 Ohms 10000 Ohms -1.288078474
9.80E+05 3.80E-06 92.40 4.53E+02 -73.67075348 4.43E+02 -1.570344116 600 mVpp 1000 Ohms 10000 Ohms -1.285797211
9.80E+05 3.80E-06 93.22 4.50E+02 -73.54994965 4.39E+02 -1.570348094 600 mVpp 1000 Ohms 10000 Ohms -1.283688786
9.80E+05 3.80E-06 94.04 4.46E+02 -73.43888855 4.35E+02 -1.570352002 600 mVpp 1000 Ohms 10000 Ohms -1.281750404
9.80E+05 3.80E-06 94.87 4.43E+02 -73.31381989 4.32E+02 -1.570355889 600 mVpp 1000 Ohms 10000 Ohms -1.279567544
9.80E+05 3.80E-06 95.70 4.40E+02 -73.20078278 4.28E+02 -1.570359709 600 mVpp 1000 Ohms 10000 Ohms -1.277594675
9.80E+05 3.80E-06 96.55 4.36E+02 -73.10075378 4.24E+02 -1.570363553 600 mVpp 1000 Ohms 10000 Ohms -1.275848839
9.80E+05 3.80E-06 97.40 4.33E+02 -72.98841858 4.20E+02 -1.57036733 600 mVpp 1000 Ohms 10000 Ohms -1.27388822
9.80E+05 3.80E-06 98.26 4.30E+02 -72.88853455 4.17E+02 -1.570371085 600 mVpp 1000 Ohms 10000 Ohms -1.272144915
9.80E+05 3.80E-06 99.13 4.26E+02 -72.79193115 4.13E+02 -1.570374817 600 mVpp 1000 Ohms 10000 Ohms -1.270458867
9.80E+05 3.80E-06 100.00 4.23E+02 -72.6969986 4.09E+02 -1.570378484 600 mVpp 1000 Ohms 10000 Ohms -1.268801982
  • Hi,

    You may modify the Impedance.c file as below and check.

    /*!
     *****************************************************************************
     @file:    Impedance.c
     @author:  Neo Xu
     @brief:   standard 4-wire or 2-wire impedance measurement sequences.
     -----------------------------------------------------------------------------
    
    Copyright (c) 2017-2019 Analog Devices, Inc. All Rights Reserved.
    
    This software is proprietary to Analog Devices, Inc. and its licensors.
    By using this software you agree to the terms of the associated
    Analog Devices Software License Agreement.
     
    *****************************************************************************/
    #include "ad5940.h"
    #include <stdio.h>
    #include "string.h"
    #include "math.h"
    #include "Impedance.h"
    
    /* Default LPDAC resolution(2.5V internal reference). */
    #define DAC12BITVOLT_1LSB   (2200.0f/4095)  //mV
    #define DAC6BITVOLT_1LSB    (DAC12BITVOLT_1LSB*64)  //mV
    
    /* 
      Application configuration structure. Specified by user from template.
      The variables are usable in this whole application.
      It includes basic configuration for sequencer generator and application related parameters
    */
    AppIMPCfg_Type AppIMPCfg = 
    {
      .bParaChanged = bFALSE,
      .SeqStartAddr = 0,
      .MaxSeqLen = 0,
      
      .SeqStartAddrCal = 0,
      .MaxSeqLenCal = 0,
    
      .ImpODR = 0.0000000000000001,           /* 20.0 Hz*/
      .NumOfData = -1,
      .SysClkFreq = 16000000.0,
      .WuptClkFreq = 32000.0,
      .AdcClkFreq = 16000000.0,
      .RcalVal = 10000.0,
    
      .DswitchSel = SWD_CE0,
      .PswitchSel = SWP_CE0,
      .NswitchSel = SWN_AIN1,
      .TswitchSel = SWT_AIN1,
    
      .PwrMod = AFEPWR_HP,
    
      .HstiaRtiaSel = HSTIARTIA_5K,
      .ExcitBufGain = EXCITBUFGAIN_0P25,//EXCITBUFGAIN_2,
      .HsDacGain = HSDACGAIN_0P2,//HSDACGAIN_1,
      .HsDacUpdateRate = 7,
      .DacVoltPP = 800.0,
      .BiasVolt = -0.0f,
    
      .SinFreq = 100000.0, /* 1000Hz */
    
      .DftNum = DFTNUM_16384,
      .DftSrc = DFTSRC_SINC3,
      .HanWinEn = bTRUE,
    
      .AdcPgaGain = ADCPGA_4,//ADCPGA_1,
      .ADCSinc3Osr = ADCSINC3OSR_2,
      .ADCSinc2Osr = ADCSINC2OSR_22,
    
      .ADCAvgNum = ADCAVGNUM_16,
    
      .SweepCfg.SweepEn = bTRUE,
      .SweepCfg.SweepStart = 1000,
      .SweepCfg.SweepStop = 100000.0,
      .SweepCfg.SweepPoints = 101,
      .SweepCfg.SweepLog = bFALSE,
      .SweepCfg.SweepIndex = 0,
    
      .FifoThresh = 4,
      .IMPInited = bFALSE,
      .StopRequired = bFALSE,
    };
    
    /**
       This function is provided for upper controllers that want to change 
       application parameters specially for user defined parameters.
    */
    int32_t AppIMPGetCfg(void *pCfg)
    {
      if(pCfg)
      {
        *(AppIMPCfg_Type**)pCfg = &AppIMPCfg;
        return AD5940ERR_OK;
      }
      return AD5940ERR_PARA;
    }
    
    int32_t AppIMPCtrl(uint32_t Command, void *pPara)
    {
      
      switch (Command)
      {
        case IMPCTRL_START:
        {
          WUPTCfg_Type wupt_cfg;
    
          if(AD5940_WakeUp(10) > 10)  /* Wakeup AFE by read register, read 10 times at most */
            return AD5940ERR_WAKEUP;  /* Wakeup Failed */
          if(AppIMPCfg.IMPInited == bFALSE)
            return AD5940ERR_APPERROR;
          /* Start it */
          wupt_cfg.WuptEn = bTRUE;
          wupt_cfg.WuptEndSeq = WUPTENDSEQ_A;
          wupt_cfg.WuptOrder[0] = SEQID_0;
          wupt_cfg.SeqxSleepTime[SEQID_0] = 4;
          wupt_cfg.SeqxWakeupTime[SEQID_0] = (uint32_t)(AppIMPCfg.WuptClkFreq/AppIMPCfg.ImpODR)-4;
          AD5940_WUPTCfg(&wupt_cfg);
          
          AppIMPCfg.FifoDataCount = 0;  /* restart */
          break;
        }
        case IMPCTRL_STOPNOW:
        {
          if(AD5940_WakeUp(10) > 10)  /* Wakeup AFE by read register, read 10 times at most */
            return AD5940ERR_WAKEUP;  /* Wakeup Failed */
          /* Start Wupt right now */
          AD5940_WUPTCtrl(bFALSE);
          /* There is chance this operation will fail because sequencer could put AFE back 
            to hibernate mode just after waking up. Use STOPSYNC is better. */
          AD5940_WUPTCtrl(bFALSE);
          break;
        }
        case IMPCTRL_STOPSYNC:
        {
          AppIMPCfg.StopRequired = bTRUE;
          break;
        }
        case IMPCTRL_GETFREQ:
          {
            if(pPara == 0)
              return AD5940ERR_PARA;
            if(AppIMPCfg.SweepCfg.SweepEn == bTRUE)
              *(float*)pPara = AppIMPCfg.FreqofData;
            else
              *(float*)pPara = AppIMPCfg.SinFreq;
          }
        break;
        case IMPCTRL_SHUTDOWN:
        {
          AppIMPCtrl(IMPCTRL_STOPNOW, 0);  /* Stop the measurement if it's running. */
          /* Turn off LPloop related blocks which are not controlled automatically by hibernate operation */
          AFERefCfg_Type aferef_cfg;
          LPLoopCfg_Type lp_loop;
          memset(&aferef_cfg, 0, sizeof(aferef_cfg));
          AD5940_REFCfgS(&aferef_cfg);
          memset(&lp_loop, 0, sizeof(lp_loop));
          AD5940_LPLoopCfgS(&lp_loop);
          AD5940_EnterSleepS();  /* Enter Hibernate */
        }
        break;
        default:
        break;
      }
      return AD5940ERR_OK;
    }
    
    /* generated code snnipet */
    float AppIMPGetCurrFreq(void)
    {
      if(AppIMPCfg.SweepCfg.SweepEn == bTRUE)
        return AppIMPCfg.FreqofData;
      else
        return AppIMPCfg.SinFreq;
    }
    
    /* Application initialization */
    static AD5940Err AppIMPSeqCfgGen(void)
    {
      AD5940Err error = AD5940ERR_OK;
      const uint32_t *pSeqCmd;
      uint32_t SeqLen;
      AFERefCfg_Type aferef_cfg;
      HSLoopCfg_Type HsLoopCfg;
      DSPCfg_Type dsp_cfg;
      float sin_freq;
    
      /* Start sequence generator here */
      AD5940_SEQGenCtrl(bTRUE);
      
      AD5940_AFECtrlS(AFECTRL_ALL, bFALSE);  /* Init all to disable state */
    
      aferef_cfg.HpBandgapEn = bTRUE;
      aferef_cfg.Hp1V1BuffEn = bTRUE;
      aferef_cfg.Hp1V8BuffEn = bTRUE;
      aferef_cfg.Disc1V1Cap = bFALSE;
      aferef_cfg.Disc1V8Cap = bFALSE;
      aferef_cfg.Hp1V8ThemBuff = bFALSE;
      aferef_cfg.Hp1V8Ilimit = bFALSE;
      aferef_cfg.Lp1V1BuffEn = bFALSE;
      aferef_cfg.Lp1V8BuffEn = bFALSE;
      /* LP reference control - turn off them to save power*/
      if(AppIMPCfg.BiasVolt != 0.0f)    /* With bias voltage */
      {
        aferef_cfg.LpBandgapEn = bTRUE;
        aferef_cfg.LpRefBufEn = bTRUE;
      }
      else
      {
        aferef_cfg.LpBandgapEn = bFALSE;
        aferef_cfg.LpRefBufEn = bFALSE;
      }
      aferef_cfg.LpRefBoostEn = bFALSE;
      AD5940_REFCfgS(&aferef_cfg);	
      HsLoopCfg.HsDacCfg.ExcitBufGain = AppIMPCfg.ExcitBufGain;
      HsLoopCfg.HsDacCfg.HsDacGain = AppIMPCfg.HsDacGain;
      HsLoopCfg.HsDacCfg.HsDacUpdateRate = AppIMPCfg.HsDacUpdateRate;
    
      HsLoopCfg.HsTiaCfg.DiodeClose = bFALSE;
    	if(AppIMPCfg.BiasVolt != 0.0f)    /* With bias voltage */
    		HsLoopCfg.HsTiaCfg.HstiaBias = HSTIABIAS_VZERO0;
    	else
    		HsLoopCfg.HsTiaCfg.HstiaBias = HSTIABIAS_1P1;
      HsLoopCfg.HsTiaCfg.HstiaCtia = 31; /* 31pF + 2pF */
      HsLoopCfg.HsTiaCfg.HstiaDeRload = HSTIADERLOAD_OPEN;
      HsLoopCfg.HsTiaCfg.HstiaDeRtia = HSTIADERTIA_OPEN;
      HsLoopCfg.HsTiaCfg.HstiaRtiaSel = AppIMPCfg.HstiaRtiaSel;
    
      HsLoopCfg.SWMatCfg.Dswitch = AppIMPCfg.DswitchSel;
      HsLoopCfg.SWMatCfg.Pswitch = AppIMPCfg.PswitchSel;
      HsLoopCfg.SWMatCfg.Nswitch = AppIMPCfg.NswitchSel;
      HsLoopCfg.SWMatCfg.Tswitch = SWT_TRTIA|AppIMPCfg.TswitchSel;
    
      HsLoopCfg.WgCfg.WgType = WGTYPE_SIN;
      HsLoopCfg.WgCfg.GainCalEn = bTRUE;
      HsLoopCfg.WgCfg.OffsetCalEn = bTRUE;
      if(AppIMPCfg.SweepCfg.SweepEn == bTRUE)
      {
        AppIMPCfg.FreqofData = AppIMPCfg.SweepCfg.SweepStart;
        AppIMPCfg.SweepCurrFreq = AppIMPCfg.SweepCfg.SweepStart;
        AD5940_SweepNext(&AppIMPCfg.SweepCfg, &AppIMPCfg.SweepNextFreq);
        sin_freq = AppIMPCfg.SweepCurrFreq;
      }
      else
      {
        sin_freq = AppIMPCfg.SinFreq;
        AppIMPCfg.FreqofData = sin_freq;
      }
      HsLoopCfg.WgCfg.SinCfg.SinFreqWord = AD5940_WGFreqWordCal(sin_freq, AppIMPCfg.SysClkFreq);
      HsLoopCfg.WgCfg.SinCfg.SinAmplitudeWord = (uint32_t)(AppIMPCfg.DacVoltPP/800.0f*2047 + 0.5f);
      HsLoopCfg.WgCfg.SinCfg.SinOffsetWord = 0;
      HsLoopCfg.WgCfg.SinCfg.SinPhaseWord = 0;
      AD5940_HSLoopCfgS(&HsLoopCfg);
      if(AppIMPCfg.BiasVolt != 0.0f)    /* With bias voltage */
      {
        LPDACCfg_Type lpdac_cfg;
        
        lpdac_cfg.LpdacSel = LPDAC0;
        lpdac_cfg.LpDacVbiasMux = LPDACVBIAS_12BIT; /* Use Vbias to tuning BiasVolt. */
        lpdac_cfg.LpDacVzeroMux = LPDACVZERO_6BIT;  /* Vbias-Vzero = BiasVolt */
        lpdac_cfg.DacData6Bit = 0x40>>1;            /* Set Vzero to middle scale. */
        if(AppIMPCfg.BiasVolt<-1100.0f) AppIMPCfg.BiasVolt = -1100.0f + DAC12BITVOLT_1LSB;
        if(AppIMPCfg.BiasVolt> 1100.0f) AppIMPCfg.BiasVolt = 1100.0f - DAC12BITVOLT_1LSB;
        lpdac_cfg.DacData12Bit = (uint32_t)((AppIMPCfg.BiasVolt + 1100.0f)/DAC12BITVOLT_1LSB);
        lpdac_cfg.DataRst = bFALSE;      /* Do not reset data register */
        lpdac_cfg.LpDacSW = LPDACSW_VBIAS2LPPA|LPDACSW_VBIAS2PIN|LPDACSW_VZERO2LPTIA|LPDACSW_VZERO2PIN|LPDACSW_VZERO2HSTIA;
        lpdac_cfg.LpDacRef = LPDACREF_2P5;
        lpdac_cfg.LpDacSrc = LPDACSRC_MMR;      /* Use MMR data, we use LPDAC to generate bias voltage for LPTIA - the Vzero */
        lpdac_cfg.PowerEn = bTRUE;              /* Power up LPDAC */
        AD5940_LPDACCfgS(&lpdac_cfg);
      }
      dsp_cfg.ADCBaseCfg.ADCMuxN = ADCMUXN_HSTIA_N;
      dsp_cfg.ADCBaseCfg.ADCMuxP = ADCMUXP_HSTIA_P;
      dsp_cfg.ADCBaseCfg.ADCPga = AppIMPCfg.AdcPgaGain;
      
      memset(&dsp_cfg.ADCDigCompCfg, 0, sizeof(dsp_cfg.ADCDigCompCfg));
      
      dsp_cfg.ADCFilterCfg.ADCAvgNum = AppIMPCfg.ADCAvgNum;
      dsp_cfg.ADCFilterCfg.ADCRate = ADCRATE_800KHZ;	/* Tell filter block clock rate of ADC*/
      dsp_cfg.ADCFilterCfg.ADCSinc2Osr = AppIMPCfg.ADCSinc2Osr;
      dsp_cfg.ADCFilterCfg.ADCSinc3Osr = AppIMPCfg.ADCSinc3Osr;
      dsp_cfg.ADCFilterCfg.BpNotch = bTRUE;
      dsp_cfg.ADCFilterCfg.BpSinc3 = bFALSE;
      dsp_cfg.ADCFilterCfg.Sinc2NotchEnable = bTRUE;
      dsp_cfg.DftCfg.DftNum = AppIMPCfg.DftNum;
      dsp_cfg.DftCfg.DftSrc = AppIMPCfg.DftSrc;
      dsp_cfg.DftCfg.HanWinEn = AppIMPCfg.HanWinEn;
      
      memset(&dsp_cfg.StatCfg, 0, sizeof(dsp_cfg.StatCfg));
      AD5940_DSPCfgS(&dsp_cfg);
        
      /* Enable all of them. They are automatically turned off during hibernate mode to save power */
      if(AppIMPCfg.BiasVolt == 0.0f)
        AD5940_AFECtrlS(AFECTRL_HSTIAPWR|AFECTRL_INAMPPWR|AFECTRL_EXTBUFPWR|\
                    AFECTRL_WG|AFECTRL_DACREFPWR|AFECTRL_HSDACPWR|\
                    AFECTRL_SINC2NOTCH, bTRUE);
      else
        AD5940_AFECtrlS(AFECTRL_HSTIAPWR|AFECTRL_INAMPPWR|AFECTRL_EXTBUFPWR|\
                    AFECTRL_WG|AFECTRL_DACREFPWR|AFECTRL_HSDACPWR|\
                    AFECTRL_SINC2NOTCH|AFECTRL_DCBUFPWR, bTRUE);
        /* Sequence end. */
      AD5940_SEQGenInsert(SEQ_STOP()); /* Add one extra command to disable sequencer for initialization sequence because we only want it to run one time. */
    
      /* Stop here */
      error = AD5940_SEQGenFetchSeq(&pSeqCmd, &SeqLen);
      AD5940_SEQGenCtrl(bFALSE); /* Stop sequencer generator */
      if(error == AD5940ERR_OK)
      {
        AppIMPCfg.InitSeqInfo.SeqId = SEQID_1;
        AppIMPCfg.InitSeqInfo.SeqRamAddr = AppIMPCfg.SeqStartAddr;
        AppIMPCfg.InitSeqInfo.pSeqCmd = pSeqCmd;
        AppIMPCfg.InitSeqInfo.SeqLen = SeqLen;
        /* Write command to SRAM */
        AD5940_SEQCmdWrite(AppIMPCfg.InitSeqInfo.SeqRamAddr, pSeqCmd, SeqLen);
      }
      else
        return error; /* Error */
      return AD5940ERR_OK;
    }
    
    
    static AD5940Err AppIMPSeqMeasureGen(void)
    {
      AD5940Err error = AD5940ERR_OK;
      const uint32_t *pSeqCmd;
      uint32_t SeqLen;
      
      uint32_t WaitClks;
      SWMatrixCfg_Type sw_cfg;
      ClksCalInfo_Type clks_cal;
    
      clks_cal.DataType = DATATYPE_DFT;
      clks_cal.DftSrc = AppIMPCfg.DftSrc;
      clks_cal.DataCount = 1L<<(AppIMPCfg.DftNum+2); /* 2^(DFTNUMBER+2) */
      clks_cal.ADCSinc2Osr = AppIMPCfg.ADCSinc2Osr;
      clks_cal.ADCSinc3Osr = AppIMPCfg.ADCSinc3Osr;
      clks_cal.ADCAvgNum = AppIMPCfg.ADCAvgNum;
      clks_cal.RatioSys2AdcClk = AppIMPCfg.SysClkFreq/AppIMPCfg.AdcClkFreq;
      AD5940_ClksCalculate(&clks_cal, &WaitClks);
    
      AD5940_SEQGenCtrl(bTRUE);
      AD5940_SEQGpioCtrlS(AGPIO_Pin2); /* Set GPIO1, clear others that under control */
      AD5940_SEQGenInsert(SEQ_WAIT(16*250));  /* @todo wait 250us? */
      sw_cfg.Dswitch = SWD_RCAL0;
      sw_cfg.Pswitch = SWP_RCAL0;
      sw_cfg.Nswitch = SWN_RCAL1;
      sw_cfg.Tswitch = SWT_RCAL1|SWT_TRTIA;
      AD5940_SWMatrixCfgS(&sw_cfg);
    	
    	AD5940_AFECtrlS(AFECTRL_HSTIAPWR|AFECTRL_INAMPPWR|AFECTRL_EXTBUFPWR|\
                    AFECTRL_WG|AFECTRL_DACREFPWR|AFECTRL_HSDACPWR|\
                    AFECTRL_SINC2NOTCH, bTRUE);
      AD5940_AFECtrlS(AFECTRL_WG|AFECTRL_ADCPWR, bTRUE);  /* Enable Waveform generator */
      //delay for signal settling DFT_WAIT
      AD5940_SEQGenInsert(SEQ_WAIT(16*10));
      AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT, bTRUE);  /* Start ADC convert and DFT */
    	
    	AD5940_SEQGenFetchSeq(NULL, &AppIMPCfg.SeqWaitAddr[0]); /* Record the start address of the next command. */
    
      AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2));
       AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2));
     
      //wait for first data ready
      AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG, bFALSE);  /* Stop ADC convert and DFT */
    
      /* Configure matrix for external Rz */
      sw_cfg.Dswitch = AppIMPCfg.DswitchSel;
      sw_cfg.Pswitch = AppIMPCfg.PswitchSel;
      sw_cfg.Nswitch = AppIMPCfg.NswitchSel;
      sw_cfg.Tswitch = SWT_TRTIA|AppIMPCfg.TswitchSel;
      AD5940_SWMatrixCfgS(&sw_cfg);
      AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_WG, bTRUE);  /* Enable Waveform generator */
      AD5940_SEQGenInsert(SEQ_WAIT(16*10));  //delay for signal settling DFT_WAIT
      AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT, bTRUE);  /* Start ADC convert and DFT */
    	
    	AD5940_SEQGenFetchSeq(NULL, &AppIMPCfg.SeqWaitAddr[1]); /* Record the start address of next command */
           
      AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2));
       AD5940_SEQGenInsert(SEQ_WAIT(WaitClks/2));
    
      AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG|AFECTRL_ADCPWR, bFALSE);  /* Stop ADC convert and DFT */
        AD5940_AFECtrlS(AFECTRL_HSTIAPWR|AFECTRL_INAMPPWR|AFECTRL_EXTBUFPWR|\
                    AFECTRL_WG|AFECTRL_DACREFPWR|AFECTRL_HSDACPWR|\
                    AFECTRL_SINC2NOTCH, bFALSE);
      AD5940_SEQGpioCtrlS(0); /* Clr GPIO1 */
    
      AD5940_EnterSleepS();/* Goto hibernate */
    
      /* Sequence end. */
      error = AD5940_SEQGenFetchSeq(&pSeqCmd, &SeqLen);
      AD5940_SEQGenCtrl(bFALSE); /* Stop sequencer generator */
    
      if(error == AD5940ERR_OK)
      {
        AppIMPCfg.MeasureSeqInfo.SeqId = SEQID_0;
        AppIMPCfg.MeasureSeqInfo.SeqRamAddr = AppIMPCfg.InitSeqInfo.SeqRamAddr + AppIMPCfg.InitSeqInfo.SeqLen ;
        AppIMPCfg.MeasureSeqInfo.pSeqCmd = pSeqCmd;
        AppIMPCfg.MeasureSeqInfo.SeqLen = SeqLen;
        /* Write command to SRAM */
        AD5940_SEQCmdWrite(AppIMPCfg.MeasureSeqInfo.SeqRamAddr, pSeqCmd, SeqLen);
      }
      else
        return error; /* Error */
      return AD5940ERR_OK;
    }
    
    /* Depending on frequency of Sin wave set optimum filter settings */
    AD5940Err AppIMPCheckFreq(float freq)
    {
      ADCFilterCfg_Type filter_cfg;
      DFTCfg_Type dft_cfg;
      HSDACCfg_Type hsdac_cfg;
      uint32_t WaitClks;
      ClksCalInfo_Type clks_cal;
      FreqParams_Type freq_params;
      uint32_t SeqCmdBuff[32];
      uint32_t SRAMAddr = 0;;
      /* Step 1: Check Frequency */
      freq_params = AD5940_GetFreqParameters(freq);
      
           if(freq < 0.51)
    	{
                /* Update HSDAC update rate */
        hsdac_cfg.ExcitBufGain =EXCITBUFGAIN_2;// AppIMPCfg.ExcitBufGain;
        hsdac_cfg.HsDacGain = HSDACGAIN_1;//AppIMPCfg.HsDacGain;
         hsdac_cfg.HsDacUpdateRate = 0x1B;
        AD5940_HSDacCfgS(&hsdac_cfg);
        AD5940_HSRTIACfgS(HSTIARTIA_40K);
        
        /*Update ADC rate */
        filter_cfg.ADCRate = ADCRATE_800KHZ;
        AppIMPCfg.AdcClkFreq = 16e6;
        
        /* Change clock to 16MHz oscillator */
        AD5940_HPModeEn(bFALSE);
    	}
            else if(freq < 5 )
    	{
           /* Update HSDAC update rate */
        hsdac_cfg.ExcitBufGain =EXCITBUFGAIN_2;// AppIMPCfg.ExcitBufGain;
        hsdac_cfg.HsDacGain = HSDACGAIN_1;//AppIMPCfg.HsDacGain;
        hsdac_cfg.HsDacUpdateRate = 0x1B;
        AD5940_HSDacCfgS(&hsdac_cfg);
        AD5940_HSRTIACfgS(HSTIARTIA_40K);
        
        /*Update ADC rate */
        filter_cfg.ADCRate = ADCRATE_800KHZ;
        AppIMPCfg.AdcClkFreq = 16e6;
        
        /* Change clock to 16MHz oscillator */
        AD5940_HPModeEn(bFALSE);
        
    	}else if(freq < 450)
    	{
           /* Update HSDAC update rate */
        hsdac_cfg.ExcitBufGain =AppIMPCfg.ExcitBufGain;
        hsdac_cfg.HsDacGain = AppIMPCfg.HsDacGain;  
        
         hsdac_cfg.HsDacUpdateRate = 0x1B;
        AD5940_HSDacCfgS(&hsdac_cfg);
        AD5940_HSRTIACfgS(HSTIARTIA_5K);
        
        /*Update ADC rate */
        filter_cfg.ADCRate = ADCRATE_800KHZ;
        AppIMPCfg.AdcClkFreq = 16e6;
        
        /* Change clock to 16MHz oscillator */
        AD5940_HPModeEn(bFALSE);
    	}
           else if(freq<80000)
           {
               /* Update HSDAC update rate */
        hsdac_cfg.ExcitBufGain =AppIMPCfg.ExcitBufGain;
        hsdac_cfg.HsDacGain = AppIMPCfg.HsDacGain;
        hsdac_cfg.HsDacUpdateRate = 0x1B;
        AD5940_HSDacCfgS(&hsdac_cfg);
        AD5940_HSRTIACfgS(HSTIARTIA_5K);
        
        /*Update ADC rate */
        filter_cfg.ADCRate = ADCRATE_800KHZ;
        AppIMPCfg.AdcClkFreq = 16e6;
        
        /* Change clock to 16MHz oscillator */
        AD5940_HPModeEn(bFALSE);
           }
            /* High power mode */
    	if(freq >= 80000)
    	{
    		  /* Update HSDAC update rate */
        hsdac_cfg.ExcitBufGain =AppIMPCfg.ExcitBufGain;
        hsdac_cfg.HsDacGain = AppIMPCfg.HsDacGain;
        hsdac_cfg.HsDacUpdateRate = 0x07;
        AD5940_HSDacCfgS(&hsdac_cfg);
        AD5940_HSRTIACfgS(HSTIARTIA_5K);
        
        /*Update ADC rate */
        filter_cfg.ADCRate = ADCRATE_1P6MHZ;
        AppIMPCfg.AdcClkFreq = 32e6;
        
        /* Change clock to 32MHz oscillator */
        AD5940_HPModeEn(bTRUE);
    	}
      
      /* Step 2: Adjust ADCFILTERCON and DFTCON to set optimumn SINC3, SINC2 and DFTNUM settings  */
      filter_cfg.ADCAvgNum = ADCAVGNUM_16;  /* Don't care because it's disabled */ 
      filter_cfg.ADCSinc2Osr = freq_params.ADCSinc2Osr;
      filter_cfg.ADCSinc3Osr = freq_params.ADCSinc3Osr;
      filter_cfg.BpSinc3 = bFALSE;
      filter_cfg.BpNotch = bTRUE;
      filter_cfg.Sinc2NotchEnable = bTRUE;
      dft_cfg.DftNum = freq_params.DftNum;
      dft_cfg.DftSrc = freq_params.DftSrc;
      dft_cfg.HanWinEn = AppIMPCfg.HanWinEn;
      AD5940_ADCFilterCfgS(&filter_cfg);
      AD5940_DFTCfgS(&dft_cfg);
      
      /* Step 3: Calculate clocks needed to get result to FIFO and update sequencer wait command */
      clks_cal.DataType = DATATYPE_DFT;
      clks_cal.DftSrc = freq_params.DftSrc;
      clks_cal.DataCount = 1L<<(freq_params.DftNum+2); /* 2^(DFTNUMBER+2) */
      clks_cal.ADCSinc2Osr = freq_params.ADCSinc2Osr;
      clks_cal.ADCSinc3Osr = freq_params.ADCSinc3Osr;
      clks_cal.ADCAvgNum = 0;
      clks_cal.RatioSys2AdcClk = AppIMPCfg.SysClkFreq/AppIMPCfg.AdcClkFreq;
      AD5940_ClksCalculate(&clks_cal, &WaitClks);		
    	
    	
    	  SRAMAddr = AppIMPCfg.MeasureSeqInfo.SeqRamAddr + AppIMPCfg.SeqWaitAddr[0];
    	   
               SeqCmdBuff[0] =SEQ_WAIT(WaitClks/2);
               SeqCmdBuff[1] =SEQ_WAIT(WaitClks/2);
          
    		AD5940_SEQCmdWrite(SRAMAddr, SeqCmdBuff, 2);
    		
    		SRAMAddr = AppIMPCfg.MeasureSeqInfo.SeqRamAddr + AppIMPCfg.SeqWaitAddr[1];
    		  
               SeqCmdBuff[0] =SEQ_WAIT(WaitClks/2);
               SeqCmdBuff[1] =SEQ_WAIT(WaitClks/2);
    
    		AD5940_SEQCmdWrite(SRAMAddr, SeqCmdBuff, 2);
    
    		
    //	/* Maximum number of clocks is 0x3FFFFFFF. More are needed if the frequency is low */
    //	if(WaitClks > 0x3FFFFFFF)
    //	{
    //		WaitClks /=2;
    //		SRAMAddr = AppIMPCfg.MeasureSeqInfo.SeqRamAddr;
    //		SeqCmdBuff[0] = SEQ_WAIT(WaitClks);
    //		AD5940_SEQCmdWrite(SRAMAddr+11, SeqCmdBuff, 1);
    //		AD5940_SEQCmdWrite(SRAMAddr+12, SeqCmdBuff, 1);
    //		AD5940_SEQCmdWrite(SRAMAddr+18, SeqCmdBuff, 1);
    //		AD5940_SEQCmdWrite(SRAMAddr+19, SeqCmdBuff, 1);
    //	}
    //	else
    //	{
    //		SRAMAddr = AppIMPCfg.MeasureSeqInfo.SeqRamAddr;
    //		SeqCmdBuff[0] = SEQ_WAIT(WaitClks);
    //		AD5940_SEQCmdWrite(SRAMAddr+11, SeqCmdBuff, 1);
    //		AD5940_SEQCmdWrite(SRAMAddr+18, SeqCmdBuff, 1);
    //	}
     
      return AD5940ERR_OK;
    }
    
    
    /* This function provide application initialize. It can also enable Wupt that will automatically trigger sequence. Or it can configure  */
    int32_t AppIMPInit(uint32_t *pBuffer, uint32_t BufferSize)
    {
      AD5940Err error = AD5940ERR_OK;  
      SEQCfg_Type seq_cfg;
      FIFOCfg_Type fifo_cfg;
    
      if(AD5940_WakeUp(10) > 10)  /* Wakeup AFE by read register, read 10 times at most */
        return AD5940ERR_WAKEUP;  /* Wakeup Failed */
    
      /* Configure sequencer and stop it */
      seq_cfg.SeqMemSize = SEQMEMSIZE_2KB;  /* 2kB SRAM is used for sequencer, others for data FIFO */
      seq_cfg.SeqBreakEn = bFALSE;
      seq_cfg.SeqIgnoreEn = bTRUE;
      seq_cfg.SeqCntCRCClr = bTRUE;
      seq_cfg.SeqEnable = bFALSE;
      seq_cfg.SeqWrTimer = 0;
      AD5940_SEQCfg(&seq_cfg);
      
      
      /* Reconfigure FIFO */
      AD5940_FIFOCtrlS(FIFOSRC_DFT, bFALSE);									/* Disable FIFO firstly */
      fifo_cfg.FIFOEn = bTRUE;
      fifo_cfg.FIFOMode = FIFOMODE_FIFO;
      fifo_cfg.FIFOSize = FIFOSIZE_4KB;                       /* 4kB for FIFO, The reset 2kB for sequencer */
      fifo_cfg.FIFOSrc = FIFOSRC_DFT;
      fifo_cfg.FIFOThresh = AppIMPCfg.FifoThresh;              /* DFT result. One pair for RCAL, another for Rz. One DFT result have real part and imaginary part */
      AD5940_FIFOCfg(&fifo_cfg);
      AD5940_INTCClrFlag(AFEINTSRC_ALLINT);
    
      /* Start sequence generator */
      /* Initialize sequencer generator */
      if((AppIMPCfg.IMPInited == bFALSE)||\
           (AppIMPCfg.bParaChanged == bTRUE))
      {
        if(pBuffer == 0)  return AD5940ERR_PARA;
        if(BufferSize == 0) return AD5940ERR_PARA;   
        AD5940_SEQGenInit(pBuffer, BufferSize);
    
        /* Generate initialize sequence */
        error = AppIMPSeqCfgGen(); /* Application initialization sequence using either MCU or sequencer */
        if(error != AD5940ERR_OK) return error;
    
        /* Generate measurement sequence */
        error = AppIMPSeqMeasureGen();
        if(error != AD5940ERR_OK) return error;
    
        AppIMPCfg.bParaChanged = bFALSE; /* Clear this flag as we already implemented the new configuration */
      }
    
      /* Initialization sequencer  */
      AppIMPCfg.InitSeqInfo.WriteSRAM = bFALSE;
      AD5940_SEQInfoCfg(&AppIMPCfg.InitSeqInfo);
      seq_cfg.SeqEnable = bTRUE;
      AD5940_SEQCfg(&seq_cfg);  /* Enable sequencer */
      AD5940_SEQMmrTrig(AppIMPCfg.InitSeqInfo.SeqId);
      while(AD5940_INTCTestFlag(AFEINTC_1, AFEINTSRC_ENDSEQ) == bFALSE);
      AD5940_INTCClrFlag(AFEINTSRC_ALLINT);
      /* Measurement sequence  */
      AppIMPCfg.MeasureSeqInfo.WriteSRAM = bFALSE;
      AD5940_SEQInfoCfg(&AppIMPCfg.MeasureSeqInfo);
      
      AppIMPCheckFreq(AppIMPCfg.FreqofData);
    
      seq_cfg.SeqEnable = bTRUE;
      AD5940_SEQCfg(&seq_cfg);  /* Enable sequencer, and wait for trigger */
      AD5940_ClrMCUIntFlag();   /* Clear interrupt flag generated before */
    
      //AD5940_AFEPwrBW(AppIMPCfg.PwrMod, AFEBW_250KHZ);
    
      AppIMPCfg.IMPInited = bTRUE;  /* IMP application has been initialized. */
      return AD5940ERR_OK;
    }
    
    /* Modify registers when AFE wakeup */
    int32_t AppIMPRegModify(int32_t * const pData, uint32_t *pDataCount)
    {
      if(AppIMPCfg.NumOfData > 0)
      {
        AppIMPCfg.FifoDataCount += *pDataCount/4;
        if(AppIMPCfg.FifoDataCount >= AppIMPCfg.NumOfData)
        {
          AD5940_WUPTCtrl(bFALSE);
          return AD5940ERR_OK;
        }
      }
      if(AppIMPCfg.StopRequired == bTRUE)
      {
        AD5940_WUPTCtrl(bFALSE);
        return AD5940ERR_OK;
      }
      if(AppIMPCfg.SweepCfg.SweepEn) /* Need to set new frequency and set power mode */
      {
        AD5940_WGFreqCtrlS(AppIMPCfg.SweepNextFreq, AppIMPCfg.SysClkFreq);
    		AppIMPCheckFreq(AppIMPCfg.SweepNextFreq);
      }
      return AD5940ERR_OK;
    }
    
    /* Depending on the data type, do appropriate data pre-process before return back to controller */
    int32_t AppIMPDataProcess(int32_t * const pData, uint32_t *pDataCount)
    {
      uint32_t DataCount = *pDataCount;
      uint32_t ImpResCount = DataCount/4;
    
      fImpPol_Type * const pOut = (fImpPol_Type*)pData;
      iImpCar_Type * pSrcData = (iImpCar_Type*)pData;
    
      *pDataCount = 0;
    
      DataCount = (DataCount/4)*4;/* We expect RCAL data together with Rz data. One DFT result has two data in FIFO, real part and imaginary part.  */
    
      /* Convert DFT result to int32_t type */
      for(uint32_t i=0; i<DataCount; i++)
      {
        pData[i] &= 0x3ffff; /* @todo option to check ECC */
        if(pData[i]&(1L<<17)) /* Bit17 is sign bit */
        {
          pData[i] |= 0xfffc0000; /* Data is 18bit in two's complement, bit17 is the sign bit */
        }
      }
      for(uint32_t i=0; i<ImpResCount; i++)
      {
        iImpCar_Type *pDftRcal, *pDftRz;
    
        pDftRcal = pSrcData++;
        pDftRz = pSrcData++;
        float RzMag,RzPhase;
        float RcalMag, RcalPhase;
        
        RcalMag = sqrt((float)pDftRcal->Real*pDftRcal->Real+(float)pDftRcal->Image*pDftRcal->Image);
        RcalPhase = atan2(-pDftRcal->Image,pDftRcal->Real);
        RzMag = sqrt((float)pDftRz->Real*pDftRz->Real+(float)pDftRz->Image*pDftRz->Image);
        RzPhase = atan2(-pDftRz->Image,pDftRz->Real);
    
        RzMag = RcalMag/RzMag*AppIMPCfg.RcalVal;
        RzPhase = RcalPhase - RzPhase;
        //printf("V:%d,%d,I:%d,%d ",pDftRcal->Real,pDftRcal->Image, pDftRz->Real, pDftRz->Image);
        
        pOut[i].Magnitude = RzMag;
        pOut[i].Phase = RzPhase;
      }
      *pDataCount = ImpResCount; 
      AppIMPCfg.FreqofData = AppIMPCfg.SweepCurrFreq;
      /* Calculate next frequency point */
      if(AppIMPCfg.SweepCfg.SweepEn == bTRUE)
      {
        AppIMPCfg.FreqofData = AppIMPCfg.SweepCurrFreq;
        AppIMPCfg.SweepCurrFreq = AppIMPCfg.SweepNextFreq;
        AD5940_SweepNext(&AppIMPCfg.SweepCfg, &AppIMPCfg.SweepNextFreq);
      }
    
      return 0;
    }
    
    /**
    
    */
    int32_t AppIMPISR(void *pBuff, uint32_t *pCount)
    {
      uint32_t BuffCount;
      uint32_t FifoCnt;
      BuffCount = *pCount;
      
      *pCount = 0;
      
      if(AD5940_WakeUp(10) > 10)  /* Wakeup AFE by read register, read 10 times at most */
        return AD5940ERR_WAKEUP;  /* Wakeup Failed */
      AD5940_SleepKeyCtrlS(SLPKEY_LOCK);  /* Prohibit AFE to enter sleep mode. */
    
      if(AD5940_INTCTestFlag(AFEINTC_0, AFEINTSRC_DATAFIFOTHRESH) == bTRUE)
      {
        /* Now there should be 4 data in FIFO */
        FifoCnt = (AD5940_FIFOGetCnt()/4)*4;
        
        if(FifoCnt > BuffCount)
        {
          ///@todo buffer is limited.
        }
        AD5940_FIFORd((uint32_t *)pBuff, FifoCnt);
        AD5940_INTCClrFlag(AFEINTSRC_DATAFIFOTHRESH);
        AppIMPRegModify(pBuff, &FifoCnt);   /* If there is need to do AFE re-configure, do it here when AFE is in active state */
        //AD5940_EnterSleepS(); /* Manually put AFE back to hibernate mode. This operation only takes effect when register value is ACTIVE previously */
        AD5940_SleepKeyCtrlS(SLPKEY_UNLOCK);  /* Allow AFE to enter sleep mode. */
        /* Process data */ 
        AppIMPDataProcess((int32_t*)pBuff,&FifoCnt); 
        *pCount = FifoCnt;
        return 0;
      }
      
      return 0;
    } 
    
    
    

    Also Impedance.h file shall be as below:

    /*!
     *****************************************************************************
     @file:    Impedance.h
     @author:  Neo XU
     @brief:   4-wire/2-wire impedance measurement header file.
     -----------------------------------------------------------------------------
    
    Copyright (c) 2017-2019 Analog Devices, Inc. All Rights Reserved.
    
    This software is proprietary to Analog Devices, Inc. and its licensors.
    By using this software you agree to the terms of the associated
    Analog Devices Software License Agreement.
     
    *****************************************************************************/
    #ifndef _IMPEDANCESEQUENCES_H_
    #define _IMPEDANCESEQUENCES_H_
    #include "ad5940.h"
    #include <stdio.h>
    #include "string.h"
    #include "math.h"
    
    typedef struct
    {
    /* Common configurations for all kinds of Application. */
      BoolFlag bParaChanged;        /* Indicate to generate sequence again. It's auto cleared by AppBIAInit */
      uint32_t SeqStartAddr;        /* Initialaztion sequence start address in SRAM of AD5940  */
      uint32_t MaxSeqLen;           /* Limit the maximum sequence.   */
      uint32_t SeqStartAddrCal;     /* Measurement sequence start address in SRAM of AD5940 */
      uint32_t SeqWaitAddr[2];     
      uint32_t MaxSeqLenCal;
    /* Application related parameters */ 
      float ImpODR;                 /*  */
      int32_t NumOfData;            /* By default it's '-1'. If you want the engine stops after get NumofData, then set the value here. Otherwise, set it to '-1' which means never stop. */
      float WuptClkFreq;            /* The clock frequency of Wakeup Timer in Hz. Typically it's 32kHz. Leave it here in case we calibrate clock in software method */
      float SysClkFreq;             /* The real frequency of system clock */
      float AdcClkFreq;             /* The real frequency of ADC clock */
      float RcalVal;                /* Rcal value in Ohm */
      /* Switch Configuration */
      uint32_t DswitchSel;
      uint32_t PswitchSel;
      uint32_t NswitchSel;
      uint32_t TswitchSel;
      uint32_t PwrMod;              /* Control Chip power mode(LP/HP) */
      uint32_t HstiaRtiaSel;        /* Use internal RTIA, select from RTIA_INT_200, RTIA_INT_1K, RTIA_INT_5K, RTIA_INT_10K, RTIA_INT_20K, RTIA_INT_40K, RTIA_INT_80K, RTIA_INT_160K */
      uint32_t ExcitBufGain;        /* Select from  EXCTBUFGAIN_2, EXCTBUFGAIN_0P25 */     
      uint32_t HsDacGain;           /* Select from  HSDACGAIN_1, HSDACGAIN_0P2 */
      uint32_t HsDacUpdateRate;
      float DacVoltPP;              /* DAC output voltage in mV peak to peak. Maximum value is 800mVpp. Peak to peak voltage  */
      float BiasVolt;               /* The excitation signal is DC+AC. This parameter decides the DC value in mV unit. 0.0mV means no DC bias.*/
      float SinFreq;                /* Frequency of excitation signal */
      uint32_t DftNum;              /* DFT number */
      uint32_t DftSrc;              /* DFT Source */
      BoolFlag HanWinEn;            /* Enable Hanning window */
      uint32_t AdcPgaGain;          /* PGA Gain select from GNPGA_1, GNPGA_1_5, GNPGA_2, GNPGA_4, GNPGA_9 !!! We must ensure signal is in range of +-1.5V which is limited by ADC input stage */   
      uint8_t ADCSinc3Osr;
      uint8_t ADCSinc2Osr;  
      uint8_t ADCAvgNum;
      /* Sweep Function Control */
      SoftSweepCfg_Type SweepCfg;
      uint32_t FifoThresh;           /* FIFO threshold. Should be N*4 */
    /* Private variables for internal usage */
    /* Private variables for internal usage */
      float SweepCurrFreq;
      float SweepNextFreq;
      float FreqofData;                         /* The frequency of latest data sampled */
      BoolFlag IMPInited;                       /* If the program run firstly, generated sequence commands */
      SEQInfo_Type InitSeqInfo;
      SEQInfo_Type MeasureSeqInfo;
      BoolFlag StopRequired;          /* After FIFO is ready, stop the measurement sequence */
      uint32_t FifoDataCount;         /* Count how many times impedance have been measured */
    }AppIMPCfg_Type;
    
    #define IMPCTRL_START          0
    #define IMPCTRL_STOPNOW        1
    #define IMPCTRL_STOPSYNC       2
    #define IMPCTRL_GETFREQ        3   /* Get Current frequency of returned data from ISR */
    #define IMPCTRL_SHUTDOWN       4   /* Note: shutdown here means turn off everything and put AFE to hibernate mode. The word 'SHUT DOWN' is only used here. */
    
    
    int32_t AppIMPInit(uint32_t *pBuffer, uint32_t BufferSize);
    int32_t AppIMPGetCfg(void *pCfg);
    int32_t AppIMPISR(void *pBuff, uint32_t *pCount);
    int32_t AppIMPCtrl(uint32_t Command, void *pPara);
    
    #endif