
Instruments 3.3
By the end of this session, you should be able to:
Control Loop Context

Note
The DAS is the bridge between the continuous analog world and the discrete digital world of the PC.

Main Hardware Blocks

Total acquisition time per sample
\[ t_{\text{sample}} \approx t_{\text{acq}} + t_{\text{conv}} \]
Tip
To maximize throughput, you must account for both S/H acquisition time and ADC conversion time.

Important
Software must use the correct base + offset addresses and bit patterns to control the DAS hardware.
Example spec (from Example 25):

BASE + 0 – data register.BASE + 1 – control/status register (EOC bit, SC bit, etc.).BASE + 2 – DAC register.Typical software sequence to get one sample:
Warning
If the DAS fails and never sets EOC, a busy-wait loop can hang the entire system. Always include a time-out or use an interrupt.
Given DAS specifications:
Task:
ERROR if EOC not issued after 100 µs.Address mapping (base is 000H to FFFH via switches; use BASE = 300H):
BASE + 0
BASE + 1
BASE + 2

We now move from “how to get the data” to “what the digital data really means.”
Two key limitations:
Note
Even with a perfect controller algorithm, these two limitations can prevent meeting tight control specifications.
The ADC output is an \(n\)‑bit binary representation of voltage \(V\) between \(V_{\min}\) and \(V_{\max}\).
Quantization relation:
\[ N = \frac{V - V_{\min}}{V_{\max} - V_{\min}} \, 2^n \tag{29} \]
Resolution (LSB size) in volts:
\[ \Delta V = \frac{V_{\max} - V_{\min}}{2^n} \tag{30} \]
Tip
Resolution is the smallest change in input that produces a one-code change in output.
A temperature between \(100^\circ \mathrm{C}\) and \(300^\circ \mathrm{C}\) is converted to a 0–5.0 V signal. That signal feeds an 8‑bit ADC with a 5.0‑V reference.
Questions:
What is the actual measurement range of the system?
What is the resolution in °C?
What hex output results from \(169^\circ \mathrm{C}\)?
What temperature does a hex output of C5H represent?
ADC behavior at extremes:
So:
Therefore, actual measurement range: \[ 100.78^\circ \mathrm{C} \le T \le 299.22^\circ \mathrm{C} \]
Temperature span:
\[ 300^\circ \mathrm{C} - 100^\circ \mathrm{C} = 200^\circ \mathrm{C} \]
ADC levels:
\[ 2^8 = 256 \]
Using Equation (30):
\[ \Delta T = \frac{200^\circ \mathrm{C}}{256} = 0.78^\circ \mathrm{C / bit} \]
Interpretation:
Use Equation (29):
\[ N = \frac{169 - 100}{300 - 100} 2^8 = \frac{69}{200} \times 256 \approx 88.32 \]
Take only integer part:
\[ N = 88_{10} \]
Convert 88\(_{10}\) to hex:
\[ 88_{10} = 58_{\text{H}} \]
So,
\[ 169^\circ \mathrm{C} \rightarrow \text{ADC output } 58\text{H} \]
Alternate method:
Difference between 88.32 and 88.46 is due to rounding in intermediate steps.
Given code C5H:
Use Equation (29) solved for \(T\):
Original: \[ N = \frac{T - 100}{300 - 100} 2^8 \]
Solve for \(T\):
\[ T = \frac{N}{2^8} (300 - 100) + 100 = \frac{197}{256} \times 200 + 100 \]
Compute:
\[ T = \frac{197 \times 200}{256} + 100 \approx 153.9 + 100 = 253.9^\circ \mathrm{C} \]
So,
\[ \text{C5H} \Rightarrow T \approx 253.9^\circ \mathrm{C} \]
Warning
Notice how much information loss there is: many distinct temperatures near 254°C all map to the same digital code C5H.
With 16 bits and 5.0 V reference:
\[ \Delta V = \frac{5.0 \text{ V}}{65536} \approx 76.3 \,\mu\text{V} \]
Important
Using more bits does not help once noise amplitude is larger than the LSB size. At that point, shielding, filtering, and grounding become critical.
In addition to amplitude quantization, PC-based control systems also:
Definitions:
Two opposing constraints:

Actual analog signal
Too slow sampling: severe information loss
Aliasing: sampled data appears to have a false lower frequency
Adequate sampling: main features preserved
Based on maximum signal frequency \(f_{\max}\):
\[ f_s \approx 10 f_{\max} \tag{31} \]
Compare with Nyquist Theorem:
Note
Equation (31) is a practical engineering guideline, not a theorem. It gives a safety margin against aliasing and provides enough samples for control algorithms.

Problem:
Solution outline:
So, sampling no slower than every 15 ms.
Scenario:
Question:
Measurement request + response: 450 ms.
Add output actuation delay (assumed 225 ms): \[ t_{\text{total}} = 0.45 \text{ s} + 0.225 \text{ s} = 0.675 \text{ s} \]
Effective sampling frequency: \[ f_s = \frac{1}{t_{\text{total}}} \approx \frac{1}{0.675} \approx 1.48 \text{ Hz} \]
From Equation (31): \[ f_{\max} = \frac{f_s}{10} \approx 0.148 \text{ Hz} \]
Corresponding period of maximum controllable variation: \[ T_{\min} = \frac{1}{f_{\max}} \approx 6.8 \text{ s} \]
So, the system can reasonably control temperature variations with periods ≥ 6.8 s. Faster variations will be under-sampled and poorly controlled.
Warning
Network delays effectively lower the sampling rate and limit how fast a process you can control. This is crucial in networked and distributed control systems.
Many sensors have nonlinear input-output relations.
Examples:
After ADC, we get a digital value \(DV\) that reflects these nonlinearities:
Two common software techniques:
Suppose a transducer outputs voltage related to pressure \(p\) by
\[ V = K \sqrt{p} \tag{32} \]
The ADC converts \(V\) to a digital value \(DV\):
\[ DV \propto V \propto \sqrt{p} \tag{33} \]
We want a digital variable linearly related to \(p\).
Idea: square the measured quantity:
\[ DP = DV \times DV \propto p \tag{34} \]
Then, with appropriate scaling and offsets, \(DP\) can be made numerically equal to the actual pressure.
Tip
If the sensor relation is known and invertible, implement the inverse function in software to get a linearized variable.
Pressure \(p\) (50 to 400 psi) → measured by a transducer with output:
\[ V = 0.385 \sqrt{p} - 2.722 \]
This \(V\) feeds an ADC:
In software, DV = UDF(1) reads ADC result as decimal \(DV\) (0–255).
Goal: derive a linearization equation to compute \(p\) from \(DV\), such that \(p\) equals actual pressure (50–400 psi).
ADC relation:
\[ DV = \frac{V}{V_{\text{ref}}} 2^8 = \frac{V}{5} \times 256 \]
So \[ V = \frac{5}{256} DV \]
Sensor relation:
\[ V = 0.385 \sqrt{p} - 2.722 \]
Substitute \(V\) from ADC into sensor equation:
\[ 0.385 \sqrt{p} - 2.722 = \frac{5}{256} DV \]
Solve for \(\sqrt{p}\):
\[ 0.385 \sqrt{p} = \frac{5}{256} DV + 2.722 \]
\[ \sqrt{p} = \frac{\frac{5}{256} DV + 2.722}{0.385} \]
Solve for \(p\):
\[ p = \left( \frac{5}{256 \cdot 0.385} DV + \frac{2.722}{0.385} \right)^2 \]
Numerically simplifying coefficients gives:
\[ p = (0.00507 \, DV + 7.071)^2 \]
So in code, after reading DV, we compute:
and p equals actual pressure in psi (50–400 psi).
Sometimes:
Instead, use a table of calibration points:
Analogy:
Note
Table look-up trades memory space for computational simplicity.

Assumed table structure:
Lookup process:
Problem 1 (Resolution):
A 12-bit ADC measures a 0–10 V signal.
What is the voltage resolution \(\Delta V\)?
If the measured code is 2048\(_{10}\), what is the nominal input voltage?
Solution:
\[ \Delta V = \frac{10 \text{ V}}{2^{12}} = \frac{10}{4096} \approx 2.44 \text{ mV} \]
\[ V \approx N \cdot \Delta V = 2048 \times 2.44 \text{ mV} \approx 5.0 \text{ V} \]
Problem 2 (Sampling):
A process variable exhibits significant oscillations with period as small as 0.25 s.
What is the maximum sampling interval \(t_s\) you should use?
Solution:
So choose \(t_s \le 25\) ms.
ADC mapping (ideal):
\[ N = \frac{V - V_{\min}}{V_{\max} - V_{\min}} \, 2^n \]
Resolution (quantization step):
\[ \Delta V = \frac{V_{\max} - V_{\min}}{2^n} \]
Sampling frequency and period:
\[ f_s = \frac{1}{t_s} \]
Practical sampling rule:
\[ f_s \approx 10 f_{\max} \]
Example linearization chain (from example 29):
ADC relation: \[ DV = \frac{V}{V_{\text{ref}}} 2^n \]
Transducer relation (example): \[ V = 0.385 \sqrt{p} - 2.722 \]
Combined & inverted: \[ p = (0.00507 \, DV + 7.071)^2 \]
Use this live code block to compute ADC resolution and explore how bit depth and voltage range affect it.
Tip
Try different values for bits and V_max. - What happens to ΔV when you double the number of bits? - What if you keep bits fixed but halve the voltage range?
We’ll model the temperature measurement system from Example 26:
Use this interactive cell to convert between temperature, voltage, and ADC code.
Note
T_input = 169.0 and confirm you get about 58H as in the text.code_input = 0xC5 and see that it maps to about 253.9 °C.Use the sliders to choose bit depth and input voltage range. We’ll plot how the analog input is quantized by the ADC.
Tip
Move the bits slider: - Watch the “staircase” get finer or coarser. - Notice how ΔV in the title changes as (1/2^n).
Use this block to compare Nyquist rate and the practical 10× rule for a given maximum signal frequency.
Note
Try f_max = 6.7 Hz (as in Example 27) and compare the 15 ms practical period with the much larger Nyquist period (~75 ms).
Now you can see under-sampling and aliasing. Choose a signal frequency and sampling frequency.
Warning
Let’s visualize the 10× sampling guideline against Nyquist for a chosen ( f_{} ).
Note
This plot emphasizes that practical control often needs substantially more than the theoretical minimum sampling rate.
Play with a square-root sensor like the one used in the linearization examples:
\[ V = K \sqrt{p} \]
Tip
Try values for p_input and see that doubling pressure does not double the voltage. This nonlinearity must be corrected in software if we want a signal proportional to pressure.
We now implement a simplified version of Example 29 in a reactive way.
Note
Drag the DV slider and watch how pressure changes nonlinearly with the raw ADC count.
Although we will not fully implement a table search here, you can experiment with a small lookup table by hand.
Tip
Change DV_meas and see which table entry it snaps to. More advanced implementations would interpolate between table points.
Through these interactive blocks, you: