• AVR Freaks

AnsweredHot![ADC] What is the point of TAD configuration?

Author
Maldus
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2016/08/17 09:55:57
  • Location: 0
  • Status: offline
2019/09/25 08:29:58 (permalink)
0

[ADC] What is the point of TAD configuration?

Hello everyone,
I'm bashing my head against ADC configuration on PIC24.
My requirements are the simplest one can possibly imagine: I need to sample one ADC channel at least once every 100 milliseconds (laughably slow). No need for DMA, interrupts or even auto sampling since I'm already struggling with full manual operation.

After several attempts I actually have a working configuration to poll the ADC channel. Still, I would like to fully understand the options I'm using.
Specifically I can't seem to wrap my head around the `ADxCON3.ADCS` register.
The datasheets defines it as:
A/D Conversion Clock Select bits
Which is pretty ambiguous. After digging for a while I understood that it decides the value of TAD, as in TAD = (`ADxCON3.ADCS`+1) * TCY. TCY is 1/FOSC. FOSC = the oscillator frequency / 2.
What exactly is TAD? I only know that a conversion sequence (from when SAMP is cleared to when the conversion is complete) takes 14*TAD time, and that the sampling period (from when SAMP is set to when it is cleared) must be at least 3*TAD - written only in fine print at the end of the FRM.
That being said, what is the use in having a longer conversion sequence? Does the precision improve?
#1
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11407
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: [ADC] What is the point of TAD configuration? 2019/09/25 09:55:01 (permalink) ☼ Best Answerby Maldus 2019/09/25 12:01:24
5 (4)
The ADC needs a clock input to operate, and it can't exceed a specified frequency.  You can't just feed Fosc into it, so ADCS is the divider that brings the clock speed down to a legal value.  The higher your Fosc, the larger divider you need.
#2
Maldus
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2016/08/17 09:55:57
  • Location: 0
  • Status: offline
Re: [ADC] What is the point of TAD configuration? 2019/09/25 10:21:29 (permalink)
0
jtemples
The ADC needs a clock input to operate, and it can't exceed a specified frequency.  You can't just feed Fosc into it, so ADCS is the divider that brings the clock speed down to a legal value.  The higher your Fosc, the larger divider you need.

When approaching the subject this was my first guess. But at this point two questions emerge:
1. What is this legal value? Edit: I possibly found it; is it the TAD time specified in table 32-25 of this datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/PIC24FJ256GA705-Family-Data-Sheet-DS30010118D.pdf)?
2. Why can't this setting be automatic? I have no reason to set the divider slower than necessary, have I not?
#3
Jim Nickerson
User 452
  • Total Posts : 6333
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: [ADC] What is the point of TAD configuration? 2019/09/25 10:28:36 (permalink)
0
If you want everything to be automatic and the choices made for you maybe you could use MCC.
#4
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11407
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: [ADC] What is the point of TAD configuration? 2019/09/25 10:36:28 (permalink) ☄ Helpfulby Maldus 2019/09/25 12:01:31
5 (1)
Yes, the range of Tad values in your data sheet tells you the range of valid clock frequencies that can be fed into the ADC.
 
Why can't this setting be automatic?

 
How could it be automatic?  How could the ADC know the speed of your external crystal?
#5
Maldus
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2016/08/17 09:55:57
  • Location: 0
  • Status: offline
Re: [ADC] What is the point of TAD configuration? 2019/09/25 12:01:05 (permalink)
5 (1)

If you want everything to be automatic and the choices made for you maybe you could use MCC.

I would be really happy to, if it worked.
 

How could it be automatic?  How could the ADC know the speed of your external crystal?

Well, in my line of work using an external oscillator is very rare; almost all of my projects are simple enough to use the internal one. I guess ideally I would expect the ADC to configure itself when using it - or at very least the documentation to be clearer; I literally spent days trying to understand such a simple concept because the information is randomly scattered all over the 400+ pages of datasheet and reference manuals.
 
Thank you for clarifying it for me.
#6
oliverb
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Joined: 2009/02/16 13:12:38
  • Location: 0
  • Status: online
Re: [ADC] What is the point of TAD configuration? 2019/10/21 06:53:33 (permalink)
0
jtemples
Yes, the range of Tad values in your data sheet tells you the range of valid clock frequencies that can be fed into the ADC.
 
Why can't this setting be automatic?

 
How could it be automatic?  How could the ADC know the speed of your external crystal?


I'd quite like some sort of configuration macro that could be fed a frequency value (_XTAL_FREQ or a number) and would spit out a config register value. In my case it isn't for the ADC, instead I want to configure a hardware timer to interrupt after a specific time delay (3.5ms).  Probably not practical without either a compiler extension or a nightmare of #if directives.
 
Incidentally regarding the ADC I understand that there's a minimum and maximum time each bit can take. Presumably too fast and the voltages don't settle in the available time. Too slow and charge leaks away mid conversion.
#7
nigelwright7557
Super Member
  • Total Posts : 308
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: [ADC] What is the point of TAD configuration? 2019/10/22 09:01:10 (permalink)
0
Given you dont read the A2D very often just set TAD as high as possible.
I have designed usb oscilloscopes which need to run the A2D as fast as possible and found some experimentation is needed to TAD etc to get good results.
 
 
#8
Jump to:
© 2019 APG vNext Commercial Version 4.5