Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Ads

Discussion Groups

Discussion Groups | Comp.Arch.Embedded | PIC 18Fxxxx A/D TAD and Fosc

There are 9 messages in this thread.

You are currently looking at messages 0 to 9.

PIC 18Fxxxx A/D TAD and Fosc - beananimal - 19:21 19-09-06

I am very new to PIC microcontrollers and will be using one to develop
an A/D project.

I will be using PicBasic Pro and likely the 18F2420 or 18F4420
(language choice is due to the fact that I am a fluent VB programmer).
I don't know much C anymore and would like to avoid asembly until I get
a basic Idea of what I am doing with these uCs.

I have worked my way through the datasheets for this PIC and older
generations.  I have learned a lot by comparing old samples of code for
the older generations of PICs to the new datasheet etc...  Though I
have made progress, I am still very in the dark about many things.

My biggest issue at this point is understanding all of the timing
issues.

I had planned on using a 10MHz XTAL and running at either 10MHz or
using the PLL option to get 40MHz.
After pulling my hair out, I fail to understand the ADCON2 bits 0-5.  I
have looked that the tables, Parameter 130, code samples etc.  From
what I gather the older PICS did not have the TAD setting and this had
to be done by pauses in the code... that still does not help me figure
out what TAD setting to use or what Fosc setting to use.

The best I can figure is that for
10MHz I need a Fosc/16 (16/10 = 1.6)
40MHz I need a Fosc/64 (64/40 = 1.6)

I figured this out with some help from code on other websites and the
datasheet, but really don't understand what it all means.  As well that
leaves me with the TAD settings of either  0,2,4,6,8,12,16 or 20 Which
I have no idea how to calculate.

Could somebody pleae be kind enough to explain how this all works?  I
would like to be able to calculate these settings for this OR ANY PIC.
A laymens explanation would be great, as again, I am not at all
familiar with PIC clock and timing issues or lingo.

Once I get that figured out, we can move on to UART timing.

Thanks in advance,
Bill




Re: PIC 18Fxxxx A/D TAD and Fosc - Robert Scott - 17:58 20-09-06

On 19 Sep 2006 16:21:17 -0700, "beananimal" <b...@gmail.com> wrote:

>I am very new to PIC microcontrollers and will be using one to develop
>an A/D project....I had planned on using a 10MHz XTAL and running at either 10MHz or
>using the PLL option to get 40MHz.
>After pulling my hair out, I fail to understand the ADCON2 bits 0-5.

In setting the A/D clock period you want to make it as fast as possible so that
you get your A/D reading a short time after you trigger a reading.  But you
should not set the time any shorter than 1.6 usec. or else the reading may not
be accurate.  So just look over all your choices and pick one that results in a
period slightly greater than 1.6 usec.  Your choices are to derive the A/D clock
from the processor clock (10MHz or 40 MHz), or to use an independent RC clock.

>...From what I gather the older PICS did not have the TAD setting..

I have never seen a PIC that didn't have some register that set the A/D clock
period.

>The best I can figure is that for
>10MHz I need a Fosc/16 (16/10 = 1.6)
>40MHz I need a Fosc/64 (64/40 = 1.6)

...sure.  Why not?

>I figured this out with some help from code on other websites and the
>datasheet, but really don't understand what it all means.

What specifically don't you understand?  The A/D process takes 9.5 TAD times to
complete.  If TAD is too short, then the switched capacitors in the A/D
converter do not have enough time to fully charge up, so the apparent measured
voltage may be inaccurate.  The A/D clock is derived from the CPU clock by a
selectable prescaler, or by an RC oscillator.


>Once I get that figured out, we can move on to UART timing.

Same thing.  The UART clock is derived from the CPU clock , except that the
prescaler has much more programmability (not just powers of 2).

For more info check out:

http://forum.microchip.com/tt.aspx?forumid=-2

Robert Scott
Real-Time Specialties

Robert Scott
Ypsilanti, Michigan

Re: PIC 18Fxxxx A/D TAD and Fosc - beananimal - 21:56 20-09-06

> >The best I can figure is that for
> >10MHz I need a Fosc/16 (16/10 = 1.6)
> >40MHz I need a Fosc/64 (64/40 = 1.6)
>
> ...sure.  Why not?
>
> >I figured this out with some help from code on other websites and the
> >datasheet, but really don't understand what it all means.
>
> What specifically don't you understand?

For starters what exactly "Fosc" is (I stumbled on how to derive the
proper setting for the ADCON register.  I however have no idea what it
means. so it takes 1.6uS to do the conversion and the math works out,
but I am still in the dark.  What is exactly is Fosc/64?

> The A/D process takes 9.5 TAD times to
> complete.  If TAD is too short, then the switched capacitors in the A/D
> converter do not have enough time to fully charge up, so the apparent measured
> voltage may be inaccurate.

The uC in question has a setting for Fosc and a setting for TAD.  Not
to be dense here, but the datahseet lists TAD settings from 2 to 20.
The datasheet lists 11 TAD per 10 bit conversion. What exactly does
changing the TAD setting mean?  What is the correct setting?  It would
appear that if 11 is the minimum, then setting TAD to 12 (the nearest
value) would be the correct choice.  But that would beg the question as
to why there are available settings of 2, 4, 6, 8, 12, 16, 20.

Not to be rude or redundant, but I needed a laymens explanation, not
datasheet speak.  I have read a dozen datahseets and 2 dozens websites
and forums including the forum you listed.  Surely I can post the same
question there and only hope I don't get the standard RTFM! reply.  I
grasp things easily, but am TOTALY new to uC architecture and concepts.
Programming is one thing, uC timing and the specifics are not something
I am comfortable with.

Thanks for the reply...  sorry I am not able to put it all together.


Re: PIC 18Fxxxx A/D TAD and Fosc - Robert Scott - 22:29 20-09-06

On 20 Sep 2006 18:56:57 -0700, "beananimal" <b...@gmail.com> wrote:

>
>> What specifically don't you understand?
>
>For starters what exactly "Fosc" is..

It is the CPU oscillator frequency (10 MHz or 40 MHz).  I'm not sure, but I
think if you use the PLL, Fosc refers to the multiplied-up frequency (40MHz).

> (I stumbled on how to derive the
>proper setting for the ADCON register.  I however have no idea what it
>means. so it takes 1.6uS to do the conversion..

No, it takes 11.5 TAD  periods to do a conversion (not 9.5 as I said earlier
because I was thinking of a 8-bit conversion and I see you are talking about a
10-bit conversion).  The TAD period must be 1.6 usec or more, but otherwise it
is whatever you decide to make it by your choice of ADCON bits.

> What is exactly is Fosc/64?

Is the the Focs frequency divided by 64.

>The uC in question has a setting for Fosc and a setting for TAD.  Not
>to be dense here, but the datahseet lists TAD settings from 2 to 20.
>The datasheet lists 11 TAD per 10 bit conversion. What exactly does
>changing the TAD setting mean?

It means changing the tap on the prescaler that derives the A/D clock from the
CPU clock.

>  What is the correct setting?

Any setting that yields a TAD period of at least 1.6 usec.

>  It would
>appear that if 11 is the minimum, then setting TAD to 12 (the nearest
>value) would be the correct choice.  But that would beg the question as
>to why there are available settings of 2, 4, 6, 8, 12, 16, 20.

The minimum setting is specified in terms of TIME not in terms of the divide
ratio.  But you must specify it in terms of the divide ratio.  The chip does not
know what frequency XTAL you are using, so they offer different divide ratioes
and leave it up to you to pick an appropriate divide ratio to make the A/D clock
period come out correctly ( > 1.6 usec.) in terms of time.


>Not to be rude or redundant, but I needed a laymens explanation, not
>datasheet speak.

I have found the Microchip datasheets to be among the clearest in the industry
for giving things in as close to laymans terms as is possible without
sacrificing accuracy.  Just keep reading them.  Nothing else is needed other
than a general understanding of principles of digital electronics.

Robert Scott
Real-Time Specialties

Robert Scott
Ypsilanti, Michigan

Re: PIC 18Fxxxx A/D TAD and Fosc - Robert Scott - 07:55 21-09-06

On Thu, 21 Sep 2006 02:29:12 GMT, ---@--- (Robert Scott) wrote:

>>For starters what exactly "Fosc" is..
>
>It is the CPU oscillator frequency (10 MHz or 40 MHz).  I'm not sure, but I
>think if you use the PLL, Fosc refers to the multiplied-up frequency (40MHz).

I goofed.  Fosc is the oscillator frequency divided by 4.


Robert Scott
Ypsilanti, Michigan

Re: PIC 18Fxxxx A/D TAD and Fosc - beananimal - 10:18 21-09-06

Robert Scott wrote:
> On 20 Sep 2006 18:56:57 -0700, "beananimal" <b...@gmail.com> wrote:
>
> >
> >> What specifically don't you understand?
> >
> >For starters what exactly "Fosc" is..
>
> It is the CPU oscillator frequency (10 MHz or 40 MHz).  I'm not sure, but I
> think if you use the PLL, Fosc refers to the multiplied-up frequency (40MHz).
>
> > (I stumbled on how to derive the
> >proper setting for the ADCON register.  I however have no idea what it
> >means. so it takes 1.6uS to do the conversion..
>
> No, it takes 11.5 TAD  periods to do a conversion (not 9.5 as I said earlier
> because I was thinking of a 8-bit conversion and I see you are talking about a
> 10-bit conversion).  The TAD period must be 1.6 usec or more, but otherwise it
> is whatever you decide to make it by your choice of ADCON bits.

You seem to not understand what I am asking.  I have no idea what TAD
is.  I have no idea what Fosc is.  Therefore I have no way to wrap my
head around what they do and how they are calculated.

> It means changing the tap on the prescaler that derives the A/D clock from the
> CPU clock.

Again this means nothing to me.  So we change the "tap" and come up
with a different time.  That tells me nothing about how to calcualate
either number.


> The minimum setting is specified in terms of TIME not in terms of the divide
> ratio.  But you must specify it in terms of the divide ratio.

Scott, divide ratio of what?  What is being divided? Examples and
numbers would help.

> The chip does not know what frequency XTAL you are using, so they offer different >divide ratioes and leave it
up to you to pick an appropriate divide ratio to make the A/D clock:

I FULLY understand the concept.  I think your missing that point.  I
DONT understand what numbers to use, what they mean and where they come
from.  Again examples would help.

> I have found the Microchip datasheets to be among the clearest in the industry
> for giving things in as close to laymans terms as is possible without
> sacrificing accuracy.  Just keep reading them.  Nothing else is needed other
> than a general understanding of principles of digital electronics.

I think that is the problem here.  I READ THEM and have questions and
you are answering the questions with almost direct quotes from the
Datasheet.  No matter how well YOU think the datasheet is written, I am
struggling to put a few of the concepts into perpective.  YOU
understand your anwers but I do not.  If I did understand, then the
datasheet would have been all I needed in the first place.

I understand your trying to help and I appriciate that.  However, your
answers are as cryptic to me as the information on the datasheet.  I am
no closer to being able to calculate the Fosc and TAD bits for a given
uC than I was when I posted the question.

Anybody else out there in PIC land willing to give a newbie some help?

>
> Robert Scott
> Real-Time Specialties
> 
> Robert Scott
> Ypsilanti, Michigan


Re: PIC 18Fxxxx A/D TAD and Fosc - Robert Scott - 12:06 21-09-06

On 21 Sep 2006 07:18:57 -0700, "beananimal" <b...@gmail.com> wrote:

>You seem to not understand what I am asking.  I have no idea what TAD
>is.

TAD is the time it takes for one complete cycle of the clock that runs the A/D
process.  The A/D process takes 11.5 of these TAD clocks to complete.  So if TAD
is 2 usec, then the A/D process will complete in 23 usec. after you trigger a
conversion.

>  I have no idea what Fosc is.

Fosc is the frequency of the instruction cycle clock, which is the CPU clock
divided by 4.  The Fosc clock is used to step through the instructions.  It is
used in many places in the chip besides the A/D section, such as the input to a
timer and the UART.

> Therefore I have no way to wrap my
>head around what they do and how they are calculated.

I just said what they do.  As for calculating them, the  TAD time is calculated
by taking the Fosc period (which is the reciprocal of the Fosc frequency) and
dividing by whatever ratio you select in your choice of ADCON configuration bits
that to set.


>> It means changing the tap on the prescaler that derives the A/D clock from the
>> CPU clock.
>
>Again this means nothing to me.  So we change the "tap" and come up
>with a different time.  That tells me nothing about how to calcualate
>either number.

A "tap" refers to a point in a series of divide-by-2 circuits.  By picking a
different tap you select a frequency that is equal to the input frequency
divided by 2, 4, 8, 16, etc.  By the way, I don't know if you have mentioned it
before, but which particular PIC are you looking at?  It would help me to relate
to what you are seeing.


>> The minimum setting is specified in terms of TIME not in terms of the divide
>> ratio.  But you must specify it in terms of the divide ratio.
>
>Scott, divide ratio of what?

The divide ratio is what you specify when program the ADCON registers.  The
datasheet says which divide ratio goes with which bit settings.

>  What is being divided?

The Fosc clock frequency.

>Examples and
>numbers would help.

OK.  If the external crystal oscillator is 10MHz (no PLL), then the Fosc
frequency is 2.5 MHz.  If you select a divide-by-16 in the ADCON configuration,
then the TAD frequency is 2.5 MHz / 16 = 156250 Hz.  Therefore the TAD period is
6.4 usec., which is a valid TAD period since is is greater than 1.6 usec.

>> The chip does not know what frequency XTAL you are using, so they offer different >divide ratioes and leave
it up to you to pick an appropriate divide ratio to make the A/D clock:
>
>I FULLY understand the concept.  I think your missing that point.  I
>DONT understand what numbers to use, what they mean and where they come
>from.  Again examples would help

The choice of what numbers to use is up to you.  You have to decide what your
design requirements are.  For example, most people want their A/D operations to
complete as fast as possible, so they program the ADCON registers to generate a
TAD time as short as possible, as long as it is not less than 1.6 usec.  However
the choice of crystal also impacts current drain.  If your device is battery
powered, then you want to use as low a crystal frequency as you can, consistent
with getting the job of your application done.  Also, you might want to consider
how the choice of CPU frequency might impact the available UART frequencies.

>> I have found the Microchip datasheets to be among the clearest in the industry
>> for giving things in as close to laymans terms as is possible without
>> sacrificing accuracy.  Just keep reading them.  Nothing else is needed other
>> than a general understanding of principles of digital electronics.
>
>I think that is the problem here.  I READ THEM and have questions and
>you are answering the questions with almost direct quotes from the
>Datasheet.  No matter how well YOU think the datasheet is written, I am
>struggling to put a few of the concepts into perpective.  YOU
>understand your anwers but I do not.  If I did understand, then the
>datasheet would have been all I needed in the first place.

I think I understand where you are coming from.  I just went through a difficult
learning period on trying to crack the "secret" of programming Nokia Symbian
cell phones.  I read all the Nokia documentation and asked lots of questions in
the Nokia forum.  For the longest time it seemed like they were all in a secret
society and I was confused because I had never been taught the secret handshake.
But I finally found some documentation that got me over that initial hurdle.


Robert Scott
Ypsilanti, Michigan

Re: PIC 18Fxxxx A/D TAD and Fosc - John Temples - 14:13 21-09-06

On 2006-09-21, Robert Scott <---@---> wrote:
> On Thu, 21 Sep 2006 02:29:12 GMT, ---@--- (Robert Scott) wrote:
>
>>>For starters what exactly "Fosc" is..
>>
>>It is the CPU oscillator frequency (10 MHz or 40 MHz).  I'm not sure, but I
>>think if you use the PLL, Fosc refers to the multiplied-up frequency (40MHz).
>
> I goofed.  Fosc is the oscillator frequency divided by 4.

No, it is the oscillator frequency.  If you're using the PLL, it's the
oscillator frequency times four.  The instruction clock is Fosc / 4.
Other terms you'll find in the datasheet are Tosc, which is 1 / Fosc,
and Tcy (the instruction cycle time), which is Tosc times four.

-- 
John W. Temples, III

Re: PIC 18Fxxxx A/D TAD and Fosc - Robert Scott - 14:33 21-09-06

On Thu, 21 Sep 2006 13:13:28 -0500, John Temples <u...@xargs-spam.com> wrote:

>On 2006-09-21, Robert Scott <---@---> wrote:
>.. Fosc is the oscillator frequency divided by 4...
>
>No, it is the oscillator frequency.  If you're using the PLL, it's the
>oscillator frequency times four.  The instruction clock is Fosc / 4.
>Other terms you'll find in the datasheet are Tosc, which is 1 / Fosc,
>and Tcy (the instruction cycle time), which is Tosc times four.

Thanks.  I stand corrected.


Robert Scott
Ypsilanti, Michigan