# Sampling interval

Thread Starter

#### MTech1

Joined Feb 15, 2023
161
I've been going through the general description of ADCs, and I believe I understand the step size and resolution. For instance, with a 5V reference, 1 step equals 4.88 mV in a 10-bit ADC with a maximum value of 1024. Please confirm if this interpretation of step size and resolution is accurate?

Additionally, I use PIC18F45K22. I'm still a bit unclear about the sampling interval. I know that ADCs convert analog voltages into digital samples, but I'm not sure about the time it takes for this conversion. Is that time what's referred to as the sampling interval?

#### BobTPH

Joined Jun 5, 2013
8,665
Sampling interval is the time to charge the capacitor to the point where the conversion can be done. The conversion is separate, and is usually expressed in clock cycles of the ADC clock.

#### ericgibbs

Joined Jan 29, 2010
18,656
I'm not sure about the time it takes for this conversion. Is that time what's referred to as the sampling interval?
Hi M,
Read this clip from the d/s, note the Acquisition time

E

#### Attachments

• 59 KB Views: 7

#### Ian0

Joined Aug 7, 2020
9,507
Sampling interval is the time to charge the capacitor to the point where the conversion can be done. The conversion is separate, and is usually expressed in clock cycles of the ADC clock.
It could also mean the time interval between successive samples.

#### MrChips

Joined Oct 2, 2009
30,494
There are two times you need to consider:

(1) Sample interval
(2) Sample interval jitter

(1) The sample interval is the time between samples. The reciprocal of the sample interval is the sampling frequency, i.e.

sample frequency = 1 / (sample interval)

(2) Sample jitter is the error or uncertainty in the sample interval. This is more important than the sample interval. Why?
Imagine that the input signal is changing. Any uncertainty in the sample time will result in error in the sampled voltage. In other words, ADC resolution has been degraded. This is equivalent to measuring noise in your signal.

#### Irving

Joined Jan 30, 2016
3,798
I've been going through the general description of ADCs, and I believe I understand the step size and resolution. For instance, with a 5V reference, 1 step equals 4.88 mV in a 10-bit ADC with a maximum value of 1024. Please confirm if this interpretation of step size and resolution is accurate?
That is correct.

Additionally, I use PIC18F45K22. I'm still a bit unclear about the sampling interval. I know that ADCs convert analog voltages into digital samples, but I'm not sure about the time it takes for this conversion. Is that time what's referred to as the sampling interval?
As @ericgibbs showed the acquisition time is the shortest time you can allow for the analog sampled data to be stable before a conversion can start. The sampling interval must be > (the acquisition time + conversion time) and may incur other delays. The sampling rate is 1/(sampling interval).

The data sheet, section 17.1.4 says:
"Acquisition time is set with the ACQT<2:0> bits of the
ADCON2 register. Acquisition delays cover a range of
2 to 20 TAD. When the GO/DONE bit is set, the A/D
module continues to sample the input for the selected
acquisition time, then automatically begins a
conversion. Since the acquisition time is programmed,
there is no need to wait for an acquisition time between
selecting a channel and setting the GO/DONE bit"

This is illustrated graphically in Fig 17.4, reproduced below. The value you program into the ACQT<2:0> value (bits 5:3 of the ADCON2 register) sets the acquisition time in terms of TAD clock cycles x 2 (ie a value of 001 = 2 TAD clock cycles, a value of 000 = 0.5 TAD clock cycles). TAD timing is dependant on the ADCS<2:0> value (bits 2:0 of the ADCON2 register) and the main CPU clock as per table 17.1. The complete conversion therefore requires a time of (ACQT * 2 + 12) TAD cycles and that is your minimum sampling interval plus whatever time it takes to set the GO bit again when responding to the ADIF interrupt. Moving the data from the result register to your required destination can occur while the following conversion is taking place.

Hope that helps.

Last edited:
Thread Starter

#### MTech1

Joined Feb 15, 2023
161
I'm still uncertain about sampling interval. For example If we want to measure voltage between 0 to 5 volts using a PIC 10-bit ADC,

What should be the sampling interval for this situation?

#### Papabravo

Joined Feb 24, 2006
21,010
A theoretical guideline is that the sampling interval should be AT LEAST one-half the period of the highest frequency component in the input signal. This is equivalent to sampling at a frequency that is at least twice the frequency of the highest frequency component. As a simple example if you were looking for 60 Hz. noise in a power supply output, a sampling frequency of 120 Hz. (sampling interval 8.33 ms.) would be the minimum sampling frequency. In order for this to work you would need to ensure an analog front end that would limit the bandwidth of the input signal to eliminate higher frequency harmonics aliasing for the fundamental of interest.

Another example of this principle is the use of the sampling frequency of 44.1 kHz in order to reproduce the audio spectrum from 20 Hz. to 20 KHz. To most people this sounds acceptable. The Golden Ears are never satisfied with anything except a live performance.

#### crutschow

Joined Mar 14, 2008
34,050
As a simple example if you were looking for 60 Hz. noise in a power supply output, a sampling frequency of 120 Hz. (sampling interval 8.33 ms.) would be the minimum sampling frequency. I
That's the theoretical minimum.
If it were exactly 120Hz for the 60Hz signal, then you could be continually sampling at the same point on the waveform, thus the voltage you measure would depend upon the phase of the sample relative to the 60Hz sinewave.
So you would need to synchronize the samples with the peaks of the sinewave.

Alternately you can take many samples per 60Hz period to find the peak value.
For example to find the peak value to 0.1% resolution (10bits) requires a sample about every 2.56 degrees (118.5µs) or 140 samples/cycle.

Interestingly, if the sinewave voltage was steady with no significant random noise, you could also sub-sample to get this.
For example, sampling at 60.4Hz, would give a sample shift of 110µs per cycle, thus giving a complete period sample in about 150 cycles,

#### ericgibbs

Joined Jan 29, 2010
18,656
I'm still uncertain about sampling interval. For example If we want to measure voltage between 0 to 5 volts using a PIC 10-bit ADC,
What should be the sampling interval for this situation?
Hi M,
The sampling interval is usually based on the application.

eg:
Say you were measuring the voltage of a battery during charge or discharge, a long sample interval could be used, say 1minute or 5 minutes.

Sampling a load cell OPA output voltage may require an interval of seconds.

Sampling a dynamic stress/strain gauge OPA output voltage may require an interval of milliseconds.
E

#### MrChips

Joined Oct 2, 2009
30,494
I'm still uncertain about sampling interval. For example If we want to measure voltage between 0 to 5 volts using a PIC 10-bit ADC,

What should be the sampling interval for this situation?
If you have a constant voltage signal then you need to sample only once. Sampling interval is irrelevant.

#### Ian0

Joined Aug 7, 2020
9,507
I'm still uncertain about sampling interval. For example If we want to measure voltage between 0 to 5 volts using a PIC 10-bit ADC,

What should be the sampling interval for this situation?
It should be less than HALF the PERIOD of the highest frequency you want to measure.
e.g. if you wish to measure up to 20kHz, then the sample interval must be less than 1/(2x20000)=25us
22.6us or 20.8us would be a good choice of sample interval.
One sample every 22.6us is a sample rate or sampling frequency of 44.1kHz.

#### MrChips

Joined Oct 2, 2009
30,494
The sampling interval is not less than half the period of the highest frequency you want to measure.

The sampling interval is less than half the period of the highest frequency appearing in the signal. In other words, you must remove all frequencies above half the sampling frequency otherwise you encounter an issue know as aliasing.

For example, if you want to sample 60Hz AC and it has 50kHz noise, you need to sample at 100kHz, i.e. sample period is 10μs.

In other words, you need to have an anti-aliasing filter before the ADC.

#### Ya’akov

Joined Jan 27, 2019
8,974
The sampling rate or interval is determined by the requirements of the particular application. This is why you can’t understand a very simple idea. Once again you are creating scenarios with missing dimensions because you are sanitizing them based on your naïveté.

Rates and intervals are related to frequency.

I'm still uncertain about sampling interval. For example If we want to measure voltage between 0 to 5 volts using a PIC 10-bit ADC, what should be the sampling interval for this situation?
Yet in your question were is no mention of a frequency. This is similar to asking “I have a car that seats 6, and has tinted windows, what kind of fuel should I use?”

If you were actually trying to solve a problem instead of just living in your head this gap would become clear. But here is where to look for some answers.

If you knew you needed to get samples of a voltage every 100ms, then your sampling interval would be 100ms. It’s that simple. This would be based on the requirements of a real world application, such as monitoring a sensor whose output has a low rate of change.

On the other hand, if you were concerned with waveforms, as in an AC signal, it is somewhat more complicated. First you need to know what you are trying to measure. Do you want to know the instantaneous voltage at various intervals? Then the case above applies—but it is an unlikely scenario and the data wouldn’t be very useful in most real world requirements.

Do you want to know the average voltage? It might seem that the blind choice of an interval, as above, and the averaging of samples, would suffice. But, in fact it doesn’t—and even the first case, which “works”, lacks the proper rigor. It turns out all cases of sampling—DC and AC—share the same limits.

Much like Newton ignoring the speed of light and Einstein accounting for it, a slow rate of change signal can be sampled ignoring the rate of change, while a quickly changing signal must have the rate accounted for. The characterization is the same for both but the effect of accounting for the frequency of the signal will produce a diminishing difference inversely proportional to the it.

What you need to know about is the Nyquist Frequency, and Nyquist Interval. These are two very closely related but distinct things.

An interval is the time between two events, such as the progress of a fake Rolex watch whose quartz movement advances the second hand 1/60 of the distance around the dial each second in a punctuated way. The interval here is 1/60s (0.0167s). Frequency is the reciprocal of the interval, so 1/T where T is time, in our case, 0.0167s, so 1/0.0167 or ~60Hz (Hertz, or cycles per second).

The Nyquist Interval is the sampling interval required to resolve the events with the highest frequency of interest. If we wanted to sample the progress of the second hand on our fake Rolex accruately, that is, without missing any activities, we would have to account for the frequency of changes to it.

If we chose a sampling interval of, say, 0.033Hz, it should be obvious that there will be times when our sample falls in between movements, and then on a movement. This would make the hand appear to occasionally jump 2s. This is an artifact caused by a sampling interval that is two large.

Nyquist‘s Interval describes the minimum time between samples as 1/2 the smallest interval in the signal of interest or, most commonly, 2 times the highest frequency of that signal. This amounts to the minimum requirement being two samples for every possible occurrence of the thing we want to watch.

This still applies in the case of the very slow rate of change signal, such as something measuring what appears to be DC, something with no frequency to mention. But we are actually trying to monitor a waveform, just a very slow one that won’t go below 0V.

So, in a silly but illustrative case, let’s say in monitoring a battery level, from a battery with an expected lifetime of 8 hours, we chose a sampling interval of 16 hours. Think that through. But what is different in this case as contrasted with a more rapidlyv evolving waveform is that it is certain the choice of sampling interval is based on requirements other that the sure-to-be-satisfied Nyquist criterion.

On the other hand, if we have a wavefrom that changes many times per second we are going to find that Nyquist drives the selection and we need to sample at least two times the frequency of the signal.

Once again, these things are clear in practical projects because practical projects correct errors automatically—you don’t have to know what you don’t know before you start, the project to point out all the gaps. These mind experiments are limited by ignorance and what you are learning from them should be that you don’t know enough to make them useful.

Even if you just pretended you want to build something real and imagined the steps, it would be infinitely superior to attempting to fill gaps in your knowledge with something that depends on not having the gaps.

Go read about Nyquist, and try to either actually build something or at least specify a practical problem to be solved (that is, rather than say I have a signal X with Y characteristics pulled from… somewhere, say something like “I need to monitor the SoC of a battery and warn the user when it is below a safe level” or ”I need to display the waveform of an audio signal between 20Hz and 20kHz”)

#### Ian0

Joined Aug 7, 2020
9,507
The sampling interval is not less than half the period of the highest frequency you want to measure.

The sampling interval is less than half the period of the highest frequency appearing in the signal. In other words, you must remove all frequencies above half the sampling frequency otherwise you encounter an issue know as aliasing.

For example, if you want to sample 60Hz AC and it has 50kHz noise, you need to sample at 100kHz, i.e. sample period is 10μs.

In other words, you need to have an anti-aliasing filter before the ADC.
If I add “your anti aliasing filter should remove all the frequencies you don’t wish to measure” then we’re in agreement!
whilst “all frequencies appearing in the signal” is perfectly true, it might not be entirely helpful. Pickup from nearest TV transmitter? Switched mode supply interference? Decide on the frequency range you need, then filter appropriately, so that the sampling rate is twice the maximum frequency on the output of the filter.

#### MrChips

Joined Oct 2, 2009
30,494
Yes. We are in agreement. Many newcomers to the sampling theorem do not appreciate or understand the phenomenon of aliasing. Furthermore, they may no know about the concept of Nyquist zones and how undersampling can be used effectively to down convert very high frequency signals.

#### ericgibbs

Joined Jan 29, 2010
18,656
I'm still uncertain about sampling interval. For example If we want to measure voltage between 0 to 5 volts using a PIC 10-bit ADC,
Hi,
This is the TS's 'specification', based on his other thread.

A 12Vdc supply, resistive divider and a 10K pot for a 0V through 5Vdc range.

E