Exact match. Not showing close matches.
PICList
Thread
'[PIC]: Real newbie question on ADC'
2002\08\17@104814
by
Sean Alcorn (SYD)

Hi guys,
As I've stated in what became the much talked about PBK thread, I'm a
relative newbie, however have designed a couple of commercial products and
the list was a big help when I got stuck here and there.
I've been mainly working on the PIC12C508 with a bit of development on
PIC16F84As, then porting over to the 508s.
I am having reasonable success, designing products quite quickly, and
working in Assembler  rather that the BASIC which I originally bought.
However I am totally stuck when it comes to applying the ADC. The PIC12C671
is a very practical device and I am looking forward to the "Future Product"
 PIC12F675 for the 10bit ADC  however there are conflicting reports on
the Microchip website as to whether this device will have 8bit or 10bit
ADC.
If you look in all the PIC books on applying the ADC, they basically say;
Configure ADC
Delay
Turn on ADC
Keep checking
Get result from ADRES
This is fine if working in perfect conditions on a bench, but in the real
world, my circuits will be subjected to noisy industrial environments. I
have read elsewhere that multiple readings are required  sort of like
debouncing a pushbutton, I guess  but I have also read about 50Hz and 60Hz
hum.
I did post a question regarding the filtering of hum, and I was simply
pointed to some example code for filters  which was all a little daunting.
What is the trick? Is it just a matter of taking multiple readings at a
given frequency? I have read something about 40KHz  as it is a multiple of
both 50Hz and 60Hz
Would love to hear from anybody who can help a newbie get to this next
milestone.
Regards,
Sean

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2002\08\17@120237
by
Geo

On 18 Aug 2002, at 0:26, Sean Alcorn (SYD) wrote:
> This is fine if working in perfect conditions on a bench, but in the real
> world, my circuits will be subjected to noisy industrial environments. I
> have read elsewhere that multiple readings are required  sort of like
> debouncing a pushbutton, I guess  but I have also read about 50Hz and 60Hz hum.
>
> I did post a question regarding the filtering of hum, and I was simply
> pointed to some example code for filters  which was all a little daunting.
>
> What is the trick? Is it just a matter of taking multiple readings at a
> given frequency? I have read something about 40KHz  as it is a multiple of both
> 50Hz and 60Hz
PIC has nothing to do with it  it is an EE question :)
Used to work (servicing) expensive bench Digital Voltmeters (1uV resolution
on 10 volt range  work out the 'bits' equivalent for yourself).
They had a filter switch which basically just added an RC filter at the input to
get reduce some HF noise. BUT the integration time of the ADC was phase
locked to the mains frequency so that a reading was taken over one (or
multiple) cycles of the mains. This 'averaged' any mains ripple on the input to
near zero  assuming sinusoidal interference.
Basically if you have unknown frequency/waveform on your DC input then the
answer will be wrong regardless of filters.
If it is mains then you must look at the signal for e.g. 20mS (50Hz) or 40mS  I
am not sure if the PIC (or any) microprocessors have a facilty for setting
integration time...
regards,
George Smith

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2002\08\17@144538
by
Michael Simpson
Looks like the problem is in the Warp 13 software. Works good when warp 13
is used within MPLAB but the warp 13 driver software is not setting the
code protect bits correctly.
Well at least I can still develop my code with the driver software and
create the finals within mplab. (that stinks)
{Original Message removed}
2002\08\17@164808
by
Spehro Pefhany

At 04:26 PM 8/17/02 +0100, you wrote:
>If it is mains then you must look at the signal for e.g. 20mS (50Hz) or
>40mS  I
>am not sure if the PIC (or any) microprocessors have a facilty for setting
>integration time...
No current PICs (other than possibly the 14000) uses an integrating A/D
converter they are successiveapproximation converters. Some of the good
sigmadelta converters have notch filters that can be set to mains
frequency, but nothing on the PIC series like that at the moment.
Of course you are free to implement your own converter with the onboard
capture compare facilities, in which case you can make the period reject
50 and/or 60Hz ripple (an period of 100msec will reject both).
Best regards,
Spehro Pefhany "it's the network..." "The Journey is the reward"
spam_OUTspeffTakeThisOuTinterlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
9/11 United we Stand

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2002\08\17@181840
by
Sean Alcorn (SYD)
Spehro,
> Of course you are free to implement your own converter with the onboard
> capture compare facilities, in which case you can make the period reject
> 50 and/or 60Hz ripple (an period of 100msec will reject both).
What do you mean? Check every 100ms & average?
Regards,
Sean

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2002\08\17@181943
by
Olin Lathrop
part 1 3359 bytes contenttype:text/plain; (decoded 7bit)
> This is fine if working in perfect conditions on a bench, but in the real
> world, my circuits will be subjected to noisy industrial environments. I
> have read elsewhere that multiple readings are required  sort of like
> debouncing a pushbutton, I guess  but I have also read about 50Hz and
60Hz
> hum.
First, you have to characterize the signal you want and the noise you don't
want. What kind of bandwidth does your signal have? How fast does anything
need to respond to this signal? Are you only worried about 50 or 60Hz power
line noise or other random noise?
Let's take the easy case where the desired signal has a much lower frequency
than the dominant noise sources. In that case, you take lots of readings
and low pass filter the crap out of them.
I often take one reading every 1mS, then do the rest in software. The
equation for the equivalent of an analog R/C low pass filter is:
FILT < FILT + (NEW  FILT) * FF
where FILT is the current filtered value that is updated by this equation
for each new reading, NEW is the new reading, and FF is the filter fraction.
This is a number from 0 to 1 that controls what fraction of the input signal
is "let thru" each iteration. The filter time constant is a function of FF
and how often this filter operation is performed. An FF value of 0 results
in an infinite time constant (the filter value never changes), and FF of 1
results in a 0 time constant (output immediately follows the input).
Obviously useful values are somewhere in between.
The cool part comes from the observation that if you arrange FF to be 2**N,
where N is a positive integer, then the multiply by FF just becomes right
shift by N. You can see an example of this kind of filtering in the
HAL_AD.ASPIC module at http://www.embedinc.com/pic/hal.htm. There the value
of FF is defined by the assembler constant FILTB. FILTB is actually the
number of bits to shift right, which is 4 in this example. Therefore FF =
1/16, although it is never computed nor used directly. This filter yields a
50% step response in 11 samples, and a 90% step response in 36 samples. The
attached SHR4.GIF show a plot of the step response. If you only need about
100mS response to a changing input and you are taking a sample every 1mS,
then you could use a smaller FF, like 1/32 or 1/64, for example.
These filters can also be cascaded, just like you can have multiple R/C
filters in series. The attached file SHR44.GIF shows the step response of a
two pole filter, each with a filter fraction of 1/16. The step response is
a little slower, but random input noise has been attenuated by an additional
12 dB for a total of 24dB.
> I did post a question regarding the filtering of hum, and I was simply
> pointed to some example code for filters  which was all a little
daunting.
Don't feel bad, there are entire graduate level courses that deal with
filtering and signal processing. There is a lot of hidden complexity, which
may be why people prefer to just point at examples.
> What is the trick? Is it just a matter of taking multiple readings at a
> given frequency? I have read something about 40KHz  as it is a multiple
of
> both 50Hz and 60Hz
300Hz is also a multiple of both 50 and 60Hz. Of course all multiples of
300Hz work too.
part 2 7466 bytes contenttype:image/gif; (decode)
part 3 6577 bytes contenttype:image/gif; (decode)
part 4 305 bytes
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 7429014, http://www.embedinc.com

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2002\08\18@141152
by
Peter L. Peres

On Sat, 17 Aug 2002, Spehro Pefhany wrote:
>At 04:26 PM 8/17/02 +0100, you wrote:
>
>>If it is mains then you must look at the signal for e.g. 20mS (50Hz) or
>>40mS  I
>>am not sure if the PIC (or any) microprocessors have a facilty for setting
>>integration time...
>
>No current PICs (other than possibly the 14000) uses an integrating A/D
>converter they are successiveapproximation converters. Some of the good
>sigmadelta converters have notch filters that can be set to mains
>frequency, but nothing on the PIC series like that at the moment.
>
>Of course you are free to implement your own converter with the onboard
>capture compare facilities, in which case you can make the period reject
>50 and/or 60Hz ripple (an period of 100msec will reject both).
I was under the impression that all PICs use a C/2C converter which is a
SAR but with integration built in, so only the input hold time must be
respected, after conversion starts the input no longer counts. Am I right
?
Peter

http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body
2002\08\18@142457
by
Olin Lathrop
> I was under the impression that all PICs use a C/2C converter which is a
> SAR but with integration built in, so only the input hold time must be
> respected, after conversion starts the input no longer counts. Am I right
> ?
I don't think I ever saw documentation on whether it was C/2C or R/2R, but
otherwise I believe you are right. Except for the wierd PIC14000, but
Microchip doesn't want to talk about that so I won't either.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 7429014, http://www.embedinc.com

http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservKILLspammitvma.mit.edu with SET PICList DIGEST in the body
2002\08\19@070508
by
Michael RigbyJones
> Original Message
> From: Olin Lathrop [SMTP:.....olin_piclistKILLspam.....EMBEDINC.COM]
> Sent: Sunday, August 18, 2002 7:23 PM
> To: EraseMEPICLISTspam_OUTTakeThisOuTMITVMA.MIT.EDU
> Subject: Re: [PIC]: Real newbie question on ADC
>
> > I was under the impression that all PICs use a C/2C converter which is a
> > SAR but with integration built in, so only the input hold time must be
> > respected, after conversion starts the input no longer counts. Am I
> right
> > ?
>
> I don't think I ever saw documentation on whether it was C/2C or R/2R, but
> otherwise I believe you are right. Except for the wierd PIC14000, but
> Microchip doesn't want to talk about that so I won't either.
>
An FAE confirmed to me that the ADC is based on a C/2C method, but like you
I have never seen this in writing.
Regards
Mike

http://www.piclist.com hint: To leave the PICList
piclistunsubscriberequestspam_OUTmitvma.mit.edu
2002\08\19@155314
by
Peter L. Peres
On Sun, 18 Aug 2002, Olin Lathrop wrote:
>> I was under the impression that all PICs use a C/2C converter which is a
>> SAR but with integration built in, so only the input hold time must be
>> respected, after conversion starts the input no longer counts. Am I right
>> ?
>
>I don't think I ever saw documentation on whether it was C/2C or R/2R, but
>otherwise I believe you are right. Except for the wierd PIC14000, but
>Microchip doesn't want to talk about that so I won't either.
I relied on this in two projects and they work. I also read the A/D input
setup and hold time timings several times over and I came to the
conclusion that I can rely on the A/D holding the sampled value a certain
time after conversion is initiated. This is true for at least 16C71 and
711 which is what I used.
Peter

http://www.piclist.com hint: To leave the PICList
@spam@piclistunsubscriberequestKILLspammitvma.mit.edu
2002\08\25@084701
by
ian.forse
Olin
Using your formula and simulating in Excel I always get an offset dependant
on FF i.e. if using 1/16 then error is 15 counts and if 1/32 then error
is 31 counts. Should this be added on at the end if using integer maths?
For example my line 11 is as follows:
=A10+INT(($D$1A10)/$C$1)
Ian Forse

http://mdm1.bravepages.com
Technical support for the Multifunction Display Module

> {Original Message removed}
2002\08\25@105244
by
Olin Lathrop
> Using your formula and simulating in Excel I always get an offset
dependant
> on FF i.e. if using 1/16 then error is 15 counts and if 1/32 then error
> is 31 counts. Should this be added on at the end if using integer maths?
The formula was not intended for just integers. It is usually a good idea
to have enough fraction bits for the bits of shifting implied by FF. So if
FF is 1/16, then there should be 4 fraction bits. Of course the formula
works with more too. Sometimes is is convenient to use 8 fraction bits even
when fewer are needed. The result can be read by picking off the approriate
bytes instead of having to shift to get rid of the fraction bits.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 7429014, http://www.embedinc.com

http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: >uP ONLY! [EE]:,[OT]: >Other [BUY]:,[AD]: >Ads
2002\08\27@122654
by
Mike Mansheim

>>> FILT < FILT + (NEW  FILT) * FF
>> Using your formula and simulating in Excel I always get an offset
>> dependant on FF...<snip>
> The formula was not intended for just integers. It is usually a good
> idea to have enough fraction bits for the bits of shifting implied by
> FF... <snip>
If you're not familiar with fraction bits (newbie reference in subject),
that just means you carry the working data in the upper bits of a longer
variable. For example, if you want to use the full 10 bits of the a/d,
you can use a 16 bit variable and use the bottom 6 bits as fraction bits.
An example, in C, that shows how this works:
(the variables are 16 bit unsigned integers)
// read_a2d() is some function that puts 10 bit a/d reading in NEW
// shift new a/d reading to the top of the word
NEW = read_a2d() << 6;
// this is for FF = 1/8
FILT = FILT + (NEW/8)  (FILT/8); // this particular rendition of
// the formula does the divide
// twice, but lets you completely
// ignore signs
then if you need to use the filtered reading for anything, pick off the
top ten bits of FILT. Say you have a display function that takes a 16
bit variable as a parameter:
display(FILT >> 6); // (but don't use FILT = FILT >> 6; to work with
// it; you'll lose the fraction bits
As Olin pointed out, if you use an 8 bit a/d reading and 8 fraction bits,
the bit shifting in this example simply becomes a matter of selecting
high and low bytes. And if FF = 1/256, then the divide(s) get real
simple too!
Hope this helps.

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2002\08\27@142502
by
Greg Coleman

Unless I'm mistaken, picking off the top bits results in truncation
and not rounding. If it matter in your application, you need to add
one half in whatever your fraction units are, before you pick off the
top bits. Otherwise, your results will all be biased 1/2 unit down
on the average.
Using the 8 and 8 bit scheme as an example,
Just picking off:
03.81 becomes 3
Rounding:
03.7f + .80 = 3.ff then becomes 3
03.81 + .80 = 4.01 then becomes 4
Greg Coleman
{Quote hidden}> then if you need to use the filtered reading for anything, pick off the
> top ten bits of FILT. Say you have a display function that takes a 16
> bit variable as a parameter:
>
> display(FILT >> 6); // (but don't use FILT = FILT >> 6; to work with
> // it; you'll lose the fraction bits
>
> As Olin pointed out, if you use an 8 bit a/d reading and 8 fraction bits,
> the bit shifting in this example simply becomes a matter of selecting
> high and low bytes. And if FF = 1/256, then the divide(s) get real
> simple too!
>
> Hope this helps.
>

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2002\08\27@174527
by
Olin Lathrop
> Unless I'm mistaken, picking off the top bits results in truncation
> and not rounding. If it matter in your application, you need to add
> one half in whatever your fraction units are, before you pick off the
> top bits. Otherwise, your results will all be biased 1/2 unit down
> on the average.
You are correct if you really want to round to the nearest integer.
However, many times the representation is such that you actually want to
truncate. In fact, this often comes naturally and is sometimes a good idea
to make happen deliberately. In this scheme you replicate the high bits
into the fraction bits when expanding a number, but just truncate to convert
back to the best integer value.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 7429014, http://www.embedinc.com

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
More... (looser matching)
 Last day of these posts
 In 2002
, 2003 only
 Today
 New search...