The TransistoriZed logo should be here! But... curses! Your browser does not support SVG!

homelist of postsdocsγ ~> e-about & FAQ


A continuation of the content management script.

I have been fiddling a bit with my page content management script. So now except the pages I am also auto-generating the page bars too. As another field test I will just as well share the skeleton of my generator.

We first have the basic stuff:

 ############## EDIT THIS ###########################
OUTPUT="/media/05022eeb-bcac-4484-8eb0-1b41d4eae750/site-tex-res/site-sync/dilemaltd.com/public_html/deyan-levski/test/"
FILE="index.htm"

DIRECTORIES="\
/media/05022eeb-bcac-4484-8eb0-1b41d4eae750/site-tex-res/site-sync/dilemaltd.com/public_html/deyan-levski/test/post/ \
"
FILENAMES='post*.htm'

#################################################### 
I.e. I look through the "post" folder and the html files in it and then build-up the pages by concatinating a base skeleton and the posts e.g.:

DATE=`date`
echo $BASE >> $OUTPUT$FILE
#declare -i cnt
#declare -i p

cnt=0
dobase=0
p=0

for f in $FILENAMES; do
for i in `find $DIRECTORIES -type f \( -iname "*$f*" ! -iname "*~" ! -iname ".*" \) | sort -V -r `; do

#flinedate=$(head -n 1 $i) #Auto file date fetch stuff, that is currently not implemented.
#echo $date

cnt=`expr $cnt + 1`

if  [ "$cnt" -lt 5 ] && [ "$p" -eq 0 ]
	then
	CATSTR=$OUTPUT$FILE
	cat $i >> $CATSTR


elif [ "$cnt" -lt 5 ] && [ "$p" -ne 0 ]
	then
	CATSTR=$OUTPUT$p$FILE
	cat $i >> $CATSTR


else
	cnt=0
	p=`expr $p + 1`
	CATSTR=$OUTPUT$p$FILE
	dobase=0
	if [ "$dobase" -eq 0 ]
	then
	echo $BASE >> $CATSTR
	dobase=1
	fi


	cat $i >> $CATSTR

fi

done
done

Then generate the pagebar:

z=0

for k in { 0..$p }; do # Generate bottom Page bar

CATSTR=$OUTPUT$z$FILE
MAININDEX=$OUTPUT$FILE

	if [ $z -ne 0 ]
	then
	olz=0
		echo "
Page: " >> $CATSTR for r in `seq 0 $p`;do olz=`expr $olz + 1` if [ "$olz" -eq 1 ] then echo "0  " >> $CATSTR else olzt=`expr $olz - 1` echo "$olzt  " >> $CATSTR fi done echo "
" >> $CATSTR echo "

Last edited: $DATE by $USER

" >> $CATSTR echo "\n" >> $CATSTR else olz=0 echo "
Page: " >> $MAININDEX for r in `seq 0 $p`;do olz=`expr $olz + 1` if [ "$olz" -eq 1 ] then echo "0  " >> $MAININDEX else olzt=`expr $olz - 1` echo "$olzt  " >> $MAININDEX fi done echo "
" >> $MAININDEX echo "

Last edited: $DATE by $USER

" >> $MAININDEX echo "\n" >> $MAININDEX fi z=`expr $z + 1` done

The latter also completes the end of the HTML and adds Last edit tag. We can then look at all our files and upload them to the server.

 # Connect to FTP and upload htmls.
ftp -n -v www.dilemaltd.com << EOT
ascii
user xxxx
prompt off
cd public_html/deyan-levski/test/
mput *.htm
cd post
mput post/*.htm
quit
EOT 

In an ideal world I can possibly extend this in the same fashion and make it a generic piece of code. If I do so, I will for sure write a proper post about it.

Date:Sun Mar 30 15:47:00 CEST 2014

LEAVE A COMMENT | SEE OTHER COMMENTS



Easing up the generation of these pages.

OK, I guess I am a bit old-fashioned, I am still keeping these pages in pure HTML and do not want to port them to blogspot, wordpress, etc... Except my stubbornness it might partly be that I find most of the blog templates quite "not-so-much-content-focused", instead these emphasize on shapes, colors and ads, rather than keeping information content as readable as possible (might not be the case with my HTML template though, but still...). One drawback of writing your pages in HTML is the difficulty to maintain a good content tracking and reduce the effort put into organizing these pages.

I am somewhat excited to be able to create and keep a good content management system which I hope will reduce my writing effort. In some hours of thinking, I have the skeleton of my system and decided to try it out, add a new (this) post, and see how it goes.

Date:Sun Mar 30 14:22:00 CEST 2014

LEAVE A COMMENT | SEE OTHER COMMENTS



Attacking a!b!=a!+b!+c! the brute-force engineering and analytic mathematical ways.

Not very long ago I had an argue about whether there is a solution to the equation a!b!=a!+b!+c!. It was an argue between a mathematician and engineer, so while my math friend was trying to find the solution to the problem the scientific (analytical mathematic) way I decided to give it a try and brute-force it using some nested loops in Matlab. Initially I somehow made a simple uncatchable syntax mistake and my program seemed to be looping forever. The very same evening my math soul continued with the analytical solution and finally came with a statement that the equation does not have a solution. We both agreed and assumed that we are all right.

Well, the day after we found out that there indeed is at least one solution. This is a=3, b=3, c=4. The conclusion I want to bring here is that no matter how good one is in his profession, his self-confidence should stay at maximum 0.999999999999999999.

Interested in the analytical solution? Read here. Interested in the brute-force method? Find the nested loop Matlab script here.

Date:Sun Mar 15 12:46:50 CEST 2014

LEAVE A COMMENT | SEE OTHER COMMENTS



Offset measurement of latched comparators.

During comparator design one is often (but not always) interested in the systematic and mismatch-related offset. When dealing with continuous-time open-loop comparators the offset measurement methodology is similar conventional OTA offset measurement e.g. DC sweep, while latched comparators require a somewhat more discrete-like manner of measuring offset.

One possible approach is to use a very precise (long sloped) linear ramp, and using massive oversampling and comparator decision storage. This approach seems to be a bit tedious as its precision is solely dependent on the ramp's slope.

A basic illustration of the linear ramp method.
A basic illustration of the linear ramp method.

An alternative method for measuring offset of latched comparators would be the binary search method. One can possibly use an ideal DAC to apply "search" voltages and depending on the comparator's decision reach a settling value with a constant binary-weighted precision. E.g. to achieve 16 bits of search accuracy only 16 cycles would be required. Here are some basic illustrative examples of the two methods.

An illustration of the binary search method.
An illustration of the binary search method.

The binary search method for measurement can be applied in various ways. One practical implementation was to implement the algorithm using Verilog-A and directly add a "search" instance where you can test your comparator directly in your existing SPICE simulation. Here is a very simple example of a possible implementation.

Code update guidelines after a reader's feedback. Thanks Stefi!

Hi, I changed some of your code because I found the array method quite confusing. What is the reason for using a large lookup table? This way, you are calculating all the values 2^16 values instead of just the 16 ones needed... I used something like: if (CompDecision > vTransComp) begin // Comparator output is high, inp>inn, ->make inp smaller iTop = iCompinp; iCompinp = iBot + (iTop-iBot)/2; end else begin // Comparator output is low, inp < inn, make inp larger iBot = iCompinp; iCompinp = iBot + (iTop-iBot)/2; end thus directly calculating the values if needed. The iteration stops after 16 cycles, which is the same as having a resolution of 16. So I just tried to keep it easy so I can understand it. Just my 2¢ regards, Stefi

Indeed there is no need to calculate all 2^N code steps and later on comare them in a look-up table fashion. This is some code inefficiency which has not been realized back in the day, my lord... Nevertheless, the code (either way) works and it is the concept that matters. For this reason I have left the old code untouched, as it has been tested. I am however encouraging you to explore and write your own implementaton. Nevertheless, here's the original version and an aka inefficient implementation:

// VerilogA for daisyCycAd, daisyCycAdBinSchSAR, veriloga
//
// A component handy in comparator offset measurement. Uses a binary search algorithm with a "dive" coefficient of 2. See comments for more information.
//
// Initial version P1A - Deyan Dimitrov didolevski@gmail.com
//


`include "constants.vams"
`include "disciplines.vams"

module daisyCycAdBinSchSAR(vCompIn, vCompOut, vClk, vdd, gnd, vCompRef);

input vCompIn, vClk;

output vCompOut, vCompRef;

inout vdd, gnd;

electrical vCompIn, vCompOut, vClk, vdd, gnd, vCompRef;

parameter real vTransClk = 1.65;
parameter real vTransComp = 1.65;
parameter real vSchTop = 3.3;
parameter real vSchBot = 0;
parameter real vCompReference = 1.5;
//parameter integer Resolution = 16;
parameter integer NrOfCodes = 65535;
//parameter real tCompSpeed = 100e-12;
real vRefInReal;
real vBinSch;
real vComp;
real scharray[0:NrOfCodes];
//real next;
integer imid;
integer imin;
integer imax;
integer i;
integer codes;

analog begin

       @(initial_step)
       begin

       vBinSch = vSchBot + (vSchTop-vSchBot)/2;  // Mid point as a start of the search

       imin = 0;
       imax = NrOfCodes-2;
       imid = (NrOfCodes-2)/2;

       	   for (i = 0; i < NrOfCodes-1; i = i + 1) begin
       	     scharray[i] = (((vSchTop-vSchBot)/NrOfCodes)*i)+vSchBot;   // Creating reference array
      	   end

	   $strobe("Array Max %g", scharray[imax]);
	   $strobe("Array Min %g", scharray[imin]);

       end

       @(cross(V(vClk) - vTransClk, 1)) begin

//       next = $abstime + tCompSpeed;    // Possible internal compensation for comparator's delay
//       end
//       @(timer(next)) begin
   
//       $strobe("Imax: %d", imax);
//       $strobe("Imid: %d", imid);
//       $strobe("Imin: %d", imin);

       vComp = V(vCompIn);   // Strobe comparator decision
//       vRefInReal = V(vRefIn, gnd);

       if (imax >= imin) begin	// Continue searching if imax >= imin

       	  if (V(vCompIn) > vTransComp) begin      // Find-out which sub-array to search
       	  $strobe("%g",vComp);
//       	  vBinSch = vBinSch + (vSchTop-vBinSch)/2;
		  imin = imid + 1;	          // Change min index for the upper sub-array
		  imid = imin + ((imax-imin)/2);  // Update imid to be used for strobing-out
		  end
          else 	  
              begin
          $strobe("%g",vComp);
//       	  vBinSch = vBinSch - (vBinSch-vSchBot)/2;
		  imax = imid - 1;		  // Change max index for the upper sub-array
		  imid = imin + ((imax-imin)/2);  // Update imid to be used for strobing-out
              end

          end         

       vBinSch = scharray[imid];		  // Look-up at the reference array and assign to vBinSch (Votage to be strobed-out)
       end

       V(vCompOut) <+ vBinSch;			  // Update search voltage
       V(vCompRef) <+ vCompReference; 		  // Update comparator reference

end

endmodule

The whole principle is simple and self-explanatory. Some delay between the latch clock and S/H clock of the search component is required to compensate for the comparator's speed. Here are some practical usage illustrations.

A primitive testbench proposal.
A primitive testbench proposal.
Component settings.
Component settings.
Offset search progress.
Offset search progress.

If you find this useful the component's symbol for Virtuoso 6 as well as the *.va code can be found here.

Date:Sun Mar 11 12:46:50 CEST 2014

LEAVE A COMMENT | SEE OTHER COMMENTS



A basic "seed" for plotting csv data files with matplotlib.

Well, basically all the usage guide and information about the matplotlib library is available online, however I am writing this as an emphasis on how good matplotlib actually is, moreover I can again use this short snippet as a quick "seed/template" in the future without having to write it from scratch. Here's a short example on plotting line charts from a *.csv file.

## Plotting from a csv and writing down a pdf using matplotlib. Look after the transpose function for the column plotting settings.
## 
## Initial verison A Deyan Levski - didolevski@gmail.com
##
##

from numpy import array 
import csv 
import matplotlib.pyplot as plt 
 
#def plotit(filename,title): 

filename='Slew-Rate-Limit-Errors-Capture.csv';
title='OTA residue voltage';
 
cs=csv.reader(file(filename,"r"),delimiter=",")# seperator of csv data is a tab ("\t") 
# Have to convert comma decimal to dot decimal delimiter 
# newlist=[[float(e.replace(".",".")) for e in x] for x in cs] 
#If no conversion needed paste in: newlist=[[float(e) for e in x] for x in cs] 
newlist=[[float(e) for e in x] for x in cs]
# convert from  pairs for [[x1,y1],[x2,y2]...etc] to [x1,x2,..] [y1,y2,..]

ar=array(newlist).transpose() 

fig=plt.figure() 

ax=fig.add_subplot(1,1,1) 
ax.plot(ar[0],ar[1]) 
ax.plot(ar[0],ar[3])
ax.set_xlabel(r"$T_{p}$") 
ax.set_ylabel(r"Voltage")

ax.grid(True)  # Default grid settings
#ax.grid(color='b', alpha=0.5, linestyle='dashed', linewidth=0.5)

#ax.axis('tight') # Tight auto axis

ax.set_ylim([-0.5, 4]) # Custom Y axis
#axes[2].set_xlim([2, 5]) # Custom X axis

plt.title(title) # Plot
	
plt.savefig(filename+".pdf") # Save figure

One can also use it for plotting histograms, e.g. if you are running some MonteCarlo simulations directly from the SPICE engine and you do not have any GUI available to use.

## Plotting from a csv and writing down a pdf using matplotlib. Look after the transpose function for the column plotting settings.
## 
## Initial verison A Deyan Levski - didolevski@gmail.com
##
##

from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)

from numpy import array 
import csv
import math 
import numpy as np
import matplotlib.pyplot as plt 
import matplotlib.mlab as mlab
 
#def plotit(filename,title): 

filename='OTA-InputOffset-MC-4000.hash';
title='OTA Input Offset Distribution';
 
cs=csv.reader(file(filename,"r"),delimiter=",")# seperator of csv data is a tab ("\t") 
# Have to convert comma decimal to dot decimal delimiter 
# newlist=[[float(e.replace(".",".")) for e in x] for x in cs] 
#If no conversion needed paste in: newlist=[[float(e) for e in x] for x in cs] 
newlist=[[float(e) for e in x] for x in cs]
# convert from  pairs for [[x1,y1],[x2,y2]...etc] to [x1,x2,..] [y1,y2,..]

ar=array(newlist).transpose() 

fig=plt.figure() 

ax = fig.add_subplot(111)

# the histogram of the data
n, bins, patches = ax.hist(ar[1], 30, normed=1, facecolor='green', alpha=0.75)
# hist uses np.histogram under the hood to create 'n' and 'bins'.
# np.histogram returns the bin edges, so there will be 50 probability
# density values in n, 51 bin edges in bins and 50 patches.  To get
# everything lined up, we'll compute the bin centers
bincenters = 0.5*(bins[1:]+bins[:-1])

acc=0
nr=0
for i in ar[1]:
  acc += i
  nr += 1

mu=acc/nr
print mu

acc2=0
nr=0
for i in ar[1]:
  acc += ((i-mu)**2)
  nr += 1

sd=acc/nr
sd=math.sqrt(abs(sd))
print sd

# add a 'best fit' line for the normal PDF
y = mlab.normpdf( bincenters, mu, sd)
l = ax.plot(bincenters, y, 'r--', linewidth=1)

ax.set_xlabel('Input offset voltage')
ax.set_ylabel('Run')

ax.set_xlim(-0.05,0.05)
#ax.set_ylim(0, 0.03)
ax.grid(True)
plt.title(r'Input offset voltage variation $\mu$=%.3f, $\sigma$=%.3f' %(mu, sd))
plt.savefig(filename+".ps") # Save figure 
plt.show()

#ax=fig.add_subplot(1,1,1) 
#ax.plot(ar[0],ar[1]) 
#ax.plot(ar[0],ar[3])
#ax.set_xlabel(r"$T_{p}$") 
#ax.set_ylabel(r"Voltage")

#ax.grid(True)  # Default grid settings
#ax.grid(color='b', alpha=0.5, linestyle='dashed', linewidth=0.5)

#ax.axis('tight') # Tight auto axis

#ax.set_ylim([-0.5, 4]) # Custom Y axis
#axes[2].set_xlim([2, 5]) # Custom X axis

#plt.title(title) # Plot
	
#plt.savefig(filename+".pdf") # Save figure 

Here is a link to the "seed" folder. Where generated pdf graps can also be found.

Date:Sun Mar 09 12:46:50 CEST 2014

LEAVE A COMMENT | SEE OTHER COMMENTS