Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

ADC problem!

ADC problem!

2004-05-30 by ereihani

HI!
I use 8-bit adc and i use the result conversion in ADCH which is 
produced in the wizard.I have given a DC voltage of 2.5V and I have 
got 128,but when I give a 40HZ sine and send the result to PC and 
plot with MATLAB the figure is very bad.I have also increased the 
sampling frequency but it was in vain.
Please guide me!
Thank you!

RE: [AVR-Chat] ADC problem!

2004-05-30 by Steven Chang-Lin Yu

Firstly, which AVR are u using for your application, what is your Vref, did you make sure your ADC results is the combination of the results in HIGH and LOW register of the ADC, what is your clock speed, what is your ADC prescaler!!!

Secondly, what wizard???

Steven

__________________________________________________________________
Steven Chang-Lin Yu
MEngSc of Telecommunications
ICQ#:
66369374

Current ICQ status:

( Home Tel#: +61 0401043641
( Work Tel#: +61 0401043641
+ More ways to contact me

From: ereihani [mailto:ereihani@yahoo.com]
Sent: Sunday, 30 May 2004 3:44 PM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] ADC problem!

HI!
I use 8-bit adc and i use the result conversion in ADCH which is
produced in the wizard.I have given a DC voltage of 2.5V and I have
got 128,but when I give a 40HZ sine and send the result to PC and
plot with MATLAB the figure is very bad.I have also increased the
sampling frequency but it was in vain.
Please guide me!
Thank you!




---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.692 / Virus Database: 453 - Release Date: 28/05/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.692 / Virus Database: 453 - Release Date: 28/05/2004

Re: [AVR-Chat] ADC problem!

2004-05-30 by John Johnson

The sampling frequency must be several times the frequency you
want to sample, otherwise, you will see a seemingly random
sample, or a harmonic of the original frequency. You can
decide how many points will adequately describe the
40Hz sine wave for your project, multiply by 40 and
use that for the sample frequency. If I were doing it,
I would use a prime number as the number of samples,
that way you're guaranteed not to lock onto a
multiple/harmonic of the frequency you're sampling.
(The things we learn from Nature :-) Locusts, in
this case.)

Regards,
   JJ
Show quoted textHide quoted text
On Sunday, May 30, 2004, at 01:43 AM, ereihani wrote:

> HI!
> I use 8-bit adc and i use the result conversion in ADCH which is
> produced in the wizard.I have given a DC voltage of 2.5V and I have
> got 128,but when I give a 40HZ sine and send the result to PC and
> plot with MATLAB the figure is very bad.I have also increased the
> sampling frequency but it was in vain.
> Please guide me!
> Thank you!
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>

Re: [AVR-Chat] ADC problem!

2004-05-30 by David VanHorn

At 05:43 AM 5/30/2004 +0000, ereihani wrote:

>HI!
>I use 8-bit adc and i use the result conversion in ADCH which is 
>produced in the wizard.I have given a DC voltage of 2.5V and I have 
>got 128,but when I give a 40HZ sine and send the result to PC and 
>plot with MATLAB the figure is very bad.I have also increased the 
>sampling frequency but it was in vain.
>Please guide me!
>Thank you!

Make sure you read the high and low bytes in the right order, if not, you're getting the high byte of one sample, and the low byte of another sample.. That would be MOST confusing.

Re: [AVR-Chat] ADC problem!

2004-05-30 by erikc

----- Original Message -----
Show quoted textHide quoted text
From: "John Johnson" <johnatl@mac.com>
To: <AVR-Chat@yahoogroups.com>
Sent: Sunday, May 30, 2004 14:53
Subject: Re: [AVR-Chat] ADC problem!


> The sampling frequency must be several times the frequency
you
> want to sample, otherwise, you will see a seemingly random
> sample, or a harmonic of the original frequency. You can
> decide how many points will adequately describe the
> 40Hz sine wave for your project, multiply by 40 and
> use that for the sample frequency. If I were doing it,
> I would use a prime number as the number of samples,
> that way you're guaranteed not to lock onto a
> multiple/harmonic of the frequency you're sampling.
> (The things we learn from Nature :-) Locusts, in
> this case.)
>
> Regards,
>    JJ

What would be the lowest reasonable prime for this?  And why
are prime number sampling rates so great, anyway?

Erikc  - firewevr@airmail.net
///
"An Fhirinne in aghaidh an tSaoil."
"The Truth against the World."
        -- Bardic Motto
/// In theory, there is no difference between theory and
practice, in practice there is.

RE: [AVR-Chat] ADC problem!

2004-05-31 by Steven Chang-Lin Yu

Is called Nyquist sampling theory:

From Wikipedia:

The Nyquist-Shannon sampling theorem is a fundamental tenet in the field of information theory, in particular telecommunications.

The theorem states that, when converting from an analog signal to digital (or otherwise sampling a signal at discrete intervals), the sampling frequency must be greater than twice the highest frequency of the input signal in order to be able to reconstruct the original perfectly from the sampled version.

If the sampling frequency is less than this limit, then frequencies in the original signal that are above half the sampling rate will be "aliased" and will appear in the resulting signal as lower frequencies. Therefore, an analog low-pass filter is typically applied before sampling to ensure that no components with frequencies greater than half the sample frequency remain. This is called an "anti-aliasing filter".

The theorem also applies when reducing the sampling frequency of an existing digital signal.

The theorem was first formulated by Harry Nyquist in 1928 ("Certain topics in telegraph transmission theory"), but was only formally proved by Claude E. Shannon in 1949 ("Communication in the presence of noise"). Mathematically, the theorem is formulated as a statement about the Fourier transformation.

If a function s(x) has a Fourier transform F[s(x)] = S(f) = 0 for |f| > W, then it is completely determined by giving the value of the function at a series of points spaced 1/(2W) apart. The values sn = s(n/(2W)) are called the samples of s(x).


The minimum sample frequency that allows reconstruction of the original signal, that is 2W samples per unit distance, is known as the Nyquist frequency, (or Nyquist rate). The time inbetween samples is called the Nyquist interval.

If S(f) = 0 for |f| > W, then s(x) can be recovered from its samples by the Nyquist-Shannon Interpolation Formula.

A well-known consequence of the sampling theorem is that a signal cannot be both bandlimited and time-limited. To see why, assume that such a signal exists, and sample it faster than the Nyquist frequency. These finitely many time-domain coefficients should define the entire signal. Equivalently, the entire spectrum of the bandlimited signal should be expressible in terms of the finitely many time-domain coefficients obtained from sampling the signal. Mathematically this is equivalent to requiring that a (trigonometric) polynomial can have infinitely many zeros since the bandlimited signal must be zero on an interval beyond a critical frequency which has infinitely many points. However, it is well-known that polynomials do not have more zeros than their orders due to the fundamental theorem of algebra. This contradiction shows that our original assumption that a time-limited and bandlimited signal exists is incorrect.

[edit]

Undersampling

It has to be noted that even if the concept of "twice the highest frequency"; is the more commonly used idea, it is not absolute. In fact the theorem stands for "twice the bandwidth", which is totally different. Bandwidth is related with the range between the first frequency and the last frequency that represent the signal. Bandwidth and highest frequency are identical only in baseband signals, that is, those that go very nearly down to DC. This concept led to what is called undersampling, that is very used in software-defined radio.

Imagine that you want to sample all the FM commercial radio stations that broadcast in a given area. They broadcast in channels that span from 88 MHz to 108 MHz, giving a signal with bandwidth of 20 MHz. In the baseband interpretation of the theorem, this would require a sampling frequency more than 216 MHz. In fact, doing undersampling one only require to sample at more than 40 MHz, as long as you pass the antenna signal by a bandpass filter that only keep the 88-108 MHz range. Sampling at 44 MHz the frequency 100 MHz will be reflected as a 12 MHz digital frequency.

In certain problems, the frequencies of interest are not an interval of frequencies, but perhaps some more interesting set F of frequencies. Again, the sampling frequency must be proportional to the size of F. For instance, certain domain decomposition methods fail to converge for the 0th frequency (the constant mode) and some medium frequencies. Then the set of interesting frequencies would be something like 10Hz to 100Hz, and 110Hz to 200Hz. In this case, one would need to sample at 360Hz, not 400Hz, to correctly capture these signals.

[edit]

References
  • H. Nyquist, "Certain topics in telegraph transmission theory," Trans. AIEE, vol. 47, pp. 617-644, Apr. 1928.
  • C. E. Shannon, "Communication in the presence of noise," Proc. Institute of Radio Engineers, vol. 37, no.1, pp. 10-21, Jan. 1949.

__________________________________________________________________
Steven Chang-Lin Yu
MEngSc of Telecommunications
ICQ#:
66369374

Current ICQ status:

( Home Tel#: +61 0401043641
( Work Tel#: +61 0401043641
+ More ways to contact me

From: erikc [mailto:firewevr@airmail.net]
Sent: Monday, 31 May 2004 9:18 AM
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] ADC problem!


----- Original Message -----
From: "John Johnson"
To: <AVR-Chat@yahoogroups.com>
Sent: Sunday, May 30, 2004 14:53
Subject: Re: [AVR-Chat] ADC problem!


> The sampling frequency must be several times the frequency
you
> want to sample, otherwise, you will see a seemingly random
> sample, or a harmonic of the original frequency. You can
> decide how many points will adequately describe the
> 40Hz sine wave for your project, multiply by 40 and
> use that for the sample frequency. If I were doing it,
> I would use a prime number as the number of samples,
> that way you're guaranteed not to lock onto a
> multiple/harmonic of the frequency you're sampling.
> (The things we learn from Nature :-) Locusts, in
> this case.)
>
> Regards,
> JJ

What would be the lowest reasonable prime for this? And why
are prime number sampling rates so great, anyway?

Erikc - firewevr@airmail.net
///
"An Fhirinne in aghaidh an tSaoil.";
"The Truth against the World."
-- Bardic Motto
/// In theory, there is no difference between theory and
practice, in practice there is.






---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.692 / Virus Database: 453 - Release Date: 28/05/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.692 / Virus Database: 453 - Release Date: 28/05/2004

RE: [AVR-Chat] ADC problem!

2004-05-31 by mpdickens

--- Steven Chang-Lin Yu <stevenyu@powerup.com.au>
wrote:
> Is called Nyquist sampling theory:

>>>>>SNIP<<<<<

In essence, Nyquist's sampling theorem states that the
sampling rate must be at a minimum of twice the
highest frequency present in the signal you are
sampling in order to accurately reconstruct the
original signal. 

Otherwise, the reconstructed signal is not an accurate
reproduction of the original signal...

Regards

Marvin Dickens



=====
Registered Linux User No. 80253
If you use linux, get counted at: 
http://www.linuxcounter.org


	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.