View previous topic :: View next topic |
Author |
Message |
Guest
|
Right connection for using the internal AD converter? |
Posted: Mon Sep 29, 2008 8:00 am |
|
|
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
|
|
Posted: Mon Sep 29, 2008 8:29 am |
|
|
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
|
|
Posted: Mon Sep 29, 2008 8:53 am |
|
|
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
|
|
Posted: Mon Sep 29, 2008 9:08 am |
|
|
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
|
|
Posted: Mon Sep 29, 2008 11:40 am |
|
|
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
|
|
Posted: Tue Sep 30, 2008 8:28 am |
|
|
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
|
|
Posted: Tue Sep 30, 2008 8:38 am |
|
|
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
|
|
Posted: Tue Sep 30, 2008 11:55 am |
|
|
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 |
|
|
|