Michael Thomas Flanagan's Java Scientific Library

AtoD Class:      Modelling an Analogue to Digital Converter (ADC) for Control Theory Simulations

     

Last update: 8 November 2009                                                                                                                              Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains the constructor to create an instance of an Analogue to Digital Converter and the methods to use this in control simulations.
An instance may be created that:
i.   simulates an analogue to digital converter (ADC) of a given bit length and reference voltage. Three outputs may be accessed: as well as the quantisation error and signal to quantisation noise ratio (sqnr).

or

ii.   simply acts as a marker of an analogue to digital conversion in which the output equals the input voltage with no quantization error and no binary output. This can be useful in some control loop simulations.

This class is a subclass of the superclass BlackBox thus allowing easy use with classes such as OpenPath and ClosedLoop. Though many of the Blackbox methods are of limited relevance they will function. The s-domain transfer function will appear as the voltage equivalent of the binary output divided by the input voltage modified by any dead-time that may have been set.

import directive: import flanagan.control.AtoD;

SUMMARY OF CONSTRUCTORS AND METHODS

Constructors   public AtoD(int nBits, double vRef)
  public AtoD()
Input
  public void setInput(double input)
Output
Binary output public String binaryOutput()
public int[ ] binaryArray()
Decimal output public long decimalOutput()
Voltage output public double voltageOutput()
Quantization error
Actual error public double quantizationError()
Maximum error public double maximumQuantizationError()
SQNR (dB) public double getSQNR()
Clipping error
  public double clippingError()
Return reference voltage
as voltage public double getVref()
as decimal (binary) public long getMaximumDecimal()
Settings
Range public void setRangeOption(int option)
public String getRange()
True ADC option public boolean getTrueAtoDoption()
Dead Time
(transportation time)
[inherited from BlackBox]
Set the dead time public void setDeadtime(double deadTime)
public void setDeadtime(double deadTime, double padeOrder)
Get the dead time public double getDeadtime()
Set the Pade order public void setPadeOrder(double padeorder)
Get the Pade order public void setPadeOrder(double padeorder)
Deep Copy   public BlackBox copy()
public Object clone()
See BlackBox for the remaining inherited methods



CONSTRUCTORS

public AtoD(int nBits, double vRef)
public AtoD()
Usage:                      AtoD adc = new AtoD(nBits, vRef);
This constructor creates a new instance of AtoD that simulates an n bit analogue to digital converter (ADC) of reference voltage, vRef, and a range of either 0 to vRef or -vRef/2 to +vRef/2. The range option is set using setRangeOption described below. The 0 to vRef range is the default option on creating an instance of AtoD. The number of bits, n, is passed to the constructor as the int variable, nBits.

public AtoD()
Usage:                      AtoD adc = new AtoD();
This constructor simply acts as a marker to be used in OpenPath and ClosedLoop to indicate the presence of an ADC. In this case there is no simulation of an ADC and the output is equal to the input plus any delay set.



INPUT

public void setInput(double input)
Usage:                      adc.setInput(input);
The method by which the input, in volts, is entered.
If the instance of AtoD is a true simulation of an ADC (see Constructors above), the input voltage (argument input) is subject to the following checks and, if appropriate, the listed actions: If the input has been altered the change may be obtained by calling clippingError().



OUTPUT

BINARY OUTPUT
public String binaryOutput()
public int[ ] binaryArray()
Usage:                      binaryOut = adc.binaryOutput();
Returns a String containing a binary representation of the output of the simulated ADC in a two's complement with a one bit sign extension format.

Usage:                      binaryArray = adc.binaryArray();
Returns an int array containing a binary representation of the output of the simulated ADC in a two's complement with a one bit sign extension format. The least significant bit (LSB) is the zeroth array element.

DECIMAL OUTPUT
public long decimalOutput()
Usage:                      decimalOut = adc.decimalOutput();
Returns a decimal representation of the binary output of the simulated ADC.

VOLTAGE OUTPUT
public double voltageOutput()
Usage:                      voltageOut = adc.voltageOutput();
Returns an output voltage rescaled to the input voltage but with quantization error.



QUANTIZATION ERROR

This class calculates quantisation errors as truncation quantisation errors.

ACTUAL QUANTIZATION ERROR
public double quantizationError()
Usage:                      qError = adc.quantizationError();
Returns the actual truncation quantisation error, in volts, for the set input after any clipping.

MAXIMUM QUANTIZATION ERROR
public double maximumQuantizationError()
Usage:                      maxError = adc.quantizationError();
Returns the maximum truncation quantisation error, in volts, for the set reference voltage and number of bits.

SIGNAL TO QUANTIZATION NOISE RATIO
public double getSQNR()
Usage:                      sqnr = adc.getSQNR();
Returns the signal to quantization noise ratio.



CLIPPING ERROR

public double clippingError()
Usage:                      cError = adc.clippingError();
Returns the clipping error, i.e the difference between the input voltage and the actual voltage operted upon by the ADC if the input voltage is outside the range of the ADC.



REFERENCE VOLTAGE

RETURN VALUE AS A VOLTAGE
public double getVref()
Usage:                      vRef = adc.getVref();
Returns the reference voltage as a voltage.

RETURN VALUE AS A BINARY (DECIMAL REPRESENTATION)
public double getMaximumDecimal()
Usage:                      vDec = adc.getMaximumDecimal();
Returns the reference voltage as the decimal representation of the maximum binary number that the ADC can output.



SETTINGS

RANGE
Setting the range
public void setRangeOption(int option)
Usage:                      adc.setRangeOption(option);
This method allows the range of the ADC to be set. Two options are available. The argument, (option in the abovre usage) may be set to 0 or 1: Getting the range
public String getRange()
Usage:                      range = adc.getRange();
This method returns the range of the ADC.

TRUE ADC OPTION
public boolean getTrueAtoDoption()
Usage:                      option = adc.getTrueAtoDoption();


DEEP COPY

public AtoD copy()
public Object clone()

Copy an AtoD
Usage:                      aa = bb.copy();
A deep copy of AtoD, bb, is returned as aa.

Clone an AtoD
Usage:                      aa = bb.clone();
A deep copy of AtoD, bb, is returned as aa cast as Object. This method overrides java.lang.Object.clone().



OTHER CLASSES USED BY THIS CLASS

This class is a subclass of BlackBox which uses the following classes in this library:


This page was prepared by Dr Michael Thomas Flanagan