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

Right connection for using the internal AD converter?

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








Right connection for using the internal AD converter?
PostPosted: Mon Sep 29, 2008 8:00 am     Reply with quote

Hi

I use internal AD converter.

Is it ok to make this connection:
---<VCC (3.3V)>---<10Kohm>---<LDR (AN0)>---<GND>---

The LDR is from 0-100Kohm. That mean in some case the AN0 is directly connected to GND!

I ask because when I make current measurement on the PIC the current is 15mA more when the AN0 is shorted to GND. If connected to VCC no influence.

The setup is:

Code:
setup_adc_ports(AN0 | VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);


All other pin on PortA is used as digital I/O!!!

What do I mess up here?
Ttelmah
Guest







PostPosted: Mon Sep 29, 2008 8:29 am     Reply with quote

Sort of....
You don't say which PIC?. Now for any reasonable accuracy, the PIC has a _minimum_ impedance specified to drive the ADC inputs. If this is not met, and you do successive quick samples, or the source voltage can change quickly, you will get poor accuracy. The required impedance varies with PIC models. The maximum impedance you are presenting is 9090 ohms. Check what the specified minimum is for your PIC. You can add a capacitor between the input pin and ground, to improve the AC impedance (at a cost in response time).
Then also check in the data sheet whether the internal oscillator is legal. For most chips, this is _not_ recommended, if you are running above 1MHz, unless 'sleep' mode is used for the sampling.
Then look at how you are using the other pins as outputs. If you are using them with the standard output bit instructions, this is fine. However for you are using the byte wide 'output_a' instruction, this is not OK. To do the latter, you will have to switch to using 'fast_io' mode. This may well be your problem.

Best Wishes
Guest








PostPosted: Mon Sep 29, 2008 8:53 am     Reply with quote

Hi

The PIC is a 2455 clocked from internal 4mhz clock.

Port A is only used as normally CCS manner "output_low/output_high".

If for to keep it simple, connect (only in theory) a switch where VCC and GND is connected and the output i directly connected to AN0! Then I can switch between +5v and 0v to input to my AN0.

If +5v no extra current is used.
if 0v then extra 15mA is pulled to the PIC. And this is what I dont understand.

Is there some special command I miss when using only one analog channel and all other as digital I/O?
Guest








PostPosted: Mon Sep 29, 2008 9:08 am     Reply with quote

Hi

Found the problem, and I think it a compiler bug.

If I put:
Code:
output_float(pin_a0);

Just before:
Code:
setup_adc_ports(AN0 | VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);


Then the huge mA problem is gone.

But I don't understand why?
Ttelmah
Guest







PostPosted: Mon Sep 29, 2008 11:40 am     Reply with quote

For your chip, ADC_CLOCK_INTERNAL, is _not_ legal with a 4MHz clock selected, unless you use sleep. Data sheet, page 259, note 3. You need to select OSC/4, or OSC/8, if this is a LF device.
Your impedance is above the specified maximum (2.5KR). Section 21.1 in the data sheet. You need to think a bit more, if you are going to get reasonable accuracy with this.
You don't say which compiler version. Have stuck a simple test program together with just the ADC configured on 4.070, with the rest of the pins driven as outputs, and it is not showing your problem. The pin is set as an input (which is what output_float does). Check again everything you are calling, before this point, for a bytewide operation, which would cause this.

Best Wishes
Guest








PostPosted: Tue Sep 30, 2008 8:28 am     Reply with quote

Hi

Many thanks for your reply. I will be happy if you make one more reply:-)

What does CCS mean with "B3D03"
.................... output_high(pin_a1);
006A: BCF TRISA.B3D03 //expect somthing like BCF TRISA.1
006C: BSF LATA.LATA1


I made as you a small program, striped down to only handle the AN0 channel.
I cant find anyplace where CCS set port_a as input. But if I put the output_float(pin_a0) I find that the pin is not draining current.

p.s. the compiler is 4.068.
Guest








PostPosted: Tue Sep 30, 2008 8:38 am     Reply with quote

Hi

This is solved; I found it in the Device Table Editor.

But I think it's mess with these label names:-(

What does CCS mean with "B3D03"
.................... output_high(pin_a1);
006A: BCF TRISA.B3D03 //expect somthing like BCF TRISA.1
006C: BSF LATA.LATA1
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 11:55 am     Reply with quote

Quote:
Hi

Found the problem, and I think it a compiler bug.

If I put:
Code:
output_float(pin_a0);

Just before:
Code:
setup_adc_ports(AN0 | VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);


Then the huge mA problem is gone.

But I don't understand why?



You also need to make the ADC pin an input. This is what
output_float(pin_a0) does.
_________________
David
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