Understanding the PIC16F1823 ADC process

upand_at_them

Joined May 15, 2010
940
Also, not addressing your filter question, but since you seem to indicate that you don't need full resolution, you might consider left-justifying the result and using the ADRESH register. It makes the math easier. You'll lose the bottom two bits of the result, but have just one byte to work with. The result will, of course, be 0-255.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,252
Also, not addressing your filter question, but since you seem to indicate that you don't need full resolution, you might consider left-justifying the result and using the ADRESH register. It makes the math easier. You'll lose the bottom two bits of the result, but have just one byte to work with. The result will, of course, be 0-255.
Thanks for that suggestion, I'll look it up. To make things simpler, I plan to do all the necessary math and conversions in a computer that will be connected to the MCU. Having the result being reported as a single byte is very convenient.
 

ericgibbs

Joined Jan 29, 2010
18,848
hi cm,
The Vout range from the sensor is only 4V, so 0.8 *255 = 204 ADC Counts, that gives a resolution of 0.5lbs/Bit.
What resolution based on a max 100psi do you require.?

E
 

BobaMosfet

Joined Jul 1, 2009
2,113
That's correct. Cpin comprises the capacitance of the pin itself, the chip bond wires, the bonding pad on the chip, the capacitance of the protection diodes, and the capacitance of the track leading up to Ric. It is the capacitance any external circuitry "sees" looking at the pin.


No, they are not. That capacitance is so small that you'd need an enormous external series resistance to get any meaningful filtering action from it; and that resistance would totally trash the DC accuracy of the ADC (because of pin leakage current) as well as stretch out the minimum Tacq time to an unreasonable length.
Interesting. I always thought this offered some filtering because the next step is the sample-hold part which to some degree nullifies noise... I stand corrected.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,252
hi cm,
The Vout range from the sensor is only 4V, so 0.8 *255 = 204 ADC Counts, that gives a resolution of 0.5lbs/Bit.
What resolution based on a max 100psi do you require.?

E
Hi Eric, the sensor's working range is actually from 0.5 to 4.5V, and it's powered from a 5V source. As mentioned before, an 8 bit resolution is not only acceptable but desirable because of its simplicity.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,252
From the PIC16LF1823 datasheet:

Code:
;This code block configures the ADC
;for polling, Vdd and Vss references, Frc
;clock and AN0 input.
;
;Conversion start & polling for completion
; are included.
;
BANKSEL ADCON1          ;
MOVLW B’11110000’       ;Right justify, Frc
                        ;clock
MOVWF ADCON1            ;Vdd and Vss Vref
BANKSEL TRISA           ;
BSF TRISA,0             ;Set RA0 to input
BANKSEL ANSEL           ;
BSF ANSEL,0             ;Set RA0 to analog
BANKSEL ADCON0          ;
MOVLW B’00000001’       ;Select channel AN0
MOVWF ADCON0            ;Turn ADC On
CALL SampleTime         ;Acquisiton delay
BSF ADCON0,ADGO         ;Start conversion
BTFSC ADCON0,ADGO       ;Is conversion done?
GOTO $-1                ;No, test again
BANKSEL ADRESH          ;
MOVF ADRESH,W           ;Read upper 2 bits
MOVWF RESULTHI          ;store in GPR space
BANKSEL ADRESL          ;
MOVF ADRESL,W           ;Read lower 8 bits
MOVWF RESULTLO          ;Store in GPR space
Line #19 calls a delay routine clearly meant to allow time for the ADC to properly acquire a sample.

And on the next page, the following example is shown:

1593876850328.png

Based on the previous information, it seems that Tc is the only parameter whose calculation needs to be done carefully.

  • Amplifier settling time is a constant equal to 2µs.
  • Calculating the Temperature Coefficient time is as easy as: [(Temperature - 25°C)(0.05μs/°C)]. Where "Temperature" is the working temperature of the device, "25°C" is a constant representing the standard calibrated temperature of the device, and 0.05μs/°C is its temperature coefficient.

What I want to make sure that I understand is the calculation for Tc. So here's my interpretation of the equation:
TC = –CHOLD(RIC + RSS + RS) ln(1/2047)​

  • CHOLD is a constant and it's the value of the internal capacitor used for sample acquisition.
  • RS is the impedance of the voltage source to be sampled.

I have no idea what RIC and RSS are supposed to be. Are they simply 1K and 7K constants belonging to the MCU's internal workings?

EDIT: I've changed the title of this thread to better reflect the subject being discussed.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,848
hi cm,
This LTS sim supports your calculation for 10k Source resistance, no added capacitor as 2uSec.

This method of input will not suppress any noise on the external signal.
E

AAA 412 17.22.gif
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,252
hi cm,
This LTS sim supports your calculation for 10k Source resistance, no added capacitor as 2uSec.

This method of input will not pressures any noise on the external signal.
E

View attachment 211358
Your diagram clearly shows a 1k and a 7k resistor in series. Which I'm sure are the RIC and RSS values in the previous equations. Question, what are those components supposed to be doing there, and why aren't they represented as a single 8k resistor instead?
 

MaxHeadRoom

Joined Jul 18, 2013
28,684
As mentioned before, an 8 bit resolution is not only acceptable but desirable because of its simplicity.
I have found for the average applications such as this, 8 bits offers sufficient resolution.
Incidentally are you using the MPLAB 8.92 or the MPLB X for assembly? I just tried switching and find the latter seemingly cumbersome for assembly?
Over the old 8.92 anyway.
Max.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,252
I have found for the average applications such as this, 8 bits offers sufficient resolution.
Incidentally are you using the MPLAB 8.92 or the MPLB X for assembly? I just tried switching and find the latter seemingly cumbersome for assembly?
Over the old 8.92 anyway.
Max.
I'm using MPLB X ... and since this is my first experience programming Microchip's products, I am not familiar with any previous versions.

You are right, version X is cumbersome and, IMHO, disorganized as far as its user interface goes. I don't like its editor, for instance. I much prefer using Programmer's Notepad instead. Also they way it organizes a given project's files and how several different projects can be opened at the same time sucks. I find the way things are arranged too chaotic for my taste.
 
Last edited:

upand_at_them

Joined May 15, 2010
940
Be careful with the acquisition time. I noticed that Microchip made mistakes on that calc page in a number of datasheets. The addition was wrong as well as the settling time. Verify the settling time in the "specs" section at the end of the datasheet. I recently used an ADC on a similar 16F1825 and I used 7us for the acquisition time (which was just three goto's and a nop).
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,252
hi,
Those resistors a the internal resistance of the ADC pathway.

I will post a diagram.
E

Added Diagram.
View attachment 211363
That explains everything quite clearly, thank you very much.

Here's another question. I plan to run the MCU at 5V from a properly filtered 7805, and use its internal 4.096V reference. What would happen if I feed a 5V signal into the ADC pin? I'm guessing that the ADC would saturate at 4.096V and then report a full scale reading after that, right? Also, I don't think the chip would be damaged for exceeding the reference voltage. That would only happen if said input were to exceed the 5V that the chip's being powered with, right?
 

ericgibbs

Joined Jan 29, 2010
18,848
hi cm,
I guess you realise that 10k Rsource, may not fix the electrical noise problem, I expect you will need to add a filter cap on the input pin.
Depends how bad the noise is on the PSI Sensor.
E

Update:
Let me know the level of noise and we can come up with a suitable filter network.
 
Top