CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18LF27K42 ADC measurement issues

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ddyess



Joined: 18 Jun 2019
Posts: 5

View user's profile Send private message

PIC18LF27K42 ADC measurement issues
PostPosted: Tue Jun 18, 2019 9:15 am     Reply with quote

I have an issue I've been fighting for a few days. If anyone can help out, would appreciate it.

I have 2 custom boards that have 2 analog inputs (AN1, AN2), using PIC in subject line. Both inputs are buffered by op amps.

On 1 board, if I short both inputs, I read an ADC value of 34. If I apply VDD, I read ADC value of 3874.
On 2nd board, if I short both inputs, I read ADC value of 129. If I apply VDD, I read ADC value of 3969.

No matter how many times I read these inputs, I read same values. If you notice the diff between the boards shorted is 95 and at VDD is 95. They have the same dynamic range of 3840 (0x0F00) ADC counts.

This is how I have the adc setup:
Code:
   setup_adc_ports(sAN0|sAN1|sAN2,VSS_VDD);
   setup_adc(ADC_LEGACY_MODE|ADC_CLOCK_INTERNAL);


This is how I read the adc:
Code:
   set_adc_channel(input);
   delay_us(50);
   ADCount = read_adc();


If I had a noise issue, my readings wouldn't be repeatable. I'm convinced I don't have the adc setup properly. Can anyone assist?
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Tue Jun 18, 2019 9:25 am     Reply with quote

Op amp can typically not go rail to rail.

If you work out the input voltage to ADC you get 0.1 and 0.027.
Typical values on the output.
ddyess



Joined: 18 Jun 2019
Posts: 5

View user's profile Send private message

PIC18LF27K42 ADC measurement issues
PostPosted: Tue Jun 18, 2019 9:54 am     Reply with quote

Thanks Alan.

I'm using a MCP6441 and I've confirmed that when I short my input, the PIC sees 0.001V and it is very near VDD when I apply VDD to the input.
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jun 18, 2019 10:51 am     Reply with quote

while I don't use that PIC...
setup_adc_ports(sAN0|sAN1|sAN2,VSS_VDD);
setup_adc(ADC_LEGACY_MODE|ADC_CLOCK_INTERNAL);

1) is ADC_CLOCK_INTERNAL valid for over 1MHz ? Most( all older..) PICs that's only used during sleep mode.

2)It appears Vref for the ADC is VDD ? If so, you may have a problem between PICs reading the same bit for volts....
ddyess



Joined: 18 Jun 2019
Posts: 5

View user's profile Send private message

PIC18LF27K42 ADC measurement issues
PostPosted: Tue Jun 18, 2019 11:13 am     Reply with quote

Temtronic,

The CPU is using the internal oscillator. I've set to different frequencies and also configured the ADC clock to run of FOSC and set for valid ranges per datasheet. I do have a precision reference tied to Vref pin and tried using VSS_VREF. I get the same readings for both the shorted and VDD case.

I find it odd that I can't measure near 0V when I have 0.001V on the input pin of the PIC. I also find it odd that the dynamic range for both cases is always 3840 (0xF00).
ddyess



Joined: 18 Jun 2019
Posts: 5

View user's profile Send private message

PIC18LF27K42 ADC measurement issues
PostPosted: Tue Jun 18, 2019 11:40 am     Reply with quote

I am reading expected values now. 0 when input is grounded and about 4095 when VDD applied to input.

I changed...
Code:
ADCount = read_adc();

to...
Code:
ADCount=ADC_READ(ADC_RESULT);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group