PDA

View Full Version : Using ADCIN or POT/RCTIME?



TonyA
- 14th April 2006, 21:41
Hi,

I just started using the pics and pbp 2.46. I programmed a pic12f683 using adcin to read the value of a couple of pots. I noticed that there is a time lag from the moment when I turn the pot and the response of the pic, which in this case is oscillating the pic with the SOUND command.

I'll turn the pot to adjust the frequency of the note, a new note will sound but only after a time lag. Is this just the nature of using adcin? I thought it was supposed to be very fast and accurate when compared to using the POT or RCTIME commands. Would these other commands be better for reading the value of a pot?

Also, I was wondering if you could use adcin with a different circuit other than a voltage divider circuit.

Thanks in adavance.
Tony

Bruce
- 14th April 2006, 23:34
Hi Tony,

ADCIN & the PIC's internal ADC are actually pretty fast, but the sound
command, depending on the note/duration time, can be relatively slow.

RCTIME just measures the time a pin stays in a particular state. POT would
work, but it's really a pain to calibrate.

The time lag you're seeing is most likely due to the time it takes to generate
sound.

You can adjust the sample time for A/D readings by using the PBP
DEFINE ADC_SAMPLEUS option as long as it stays within the parameters
shown in the PIC data sheet for A/D acquisition time.

The default is 50uS unless otherwise specified with DEFINE ADC_SAMPLEUS.

TonyA
- 15th April 2006, 00:21
I see, so it's the SOUND command that's taking the time.

What about using the ADCIN with a pot using a different circuit than the voltage divider that's shown in the books. Is it possible to use other circuits with a pot and ADCIN?

Thanks again,
Tony

Bruce
- 15th April 2006, 00:31
PIC A/D inputs can be connected directly to the analog source. You don't
need any voltage dividers unless the analog input is greater than Vcc.

TonyA
- 15th April 2006, 00:48
So I can just connect one part of the pot to the pic pin and the other to ground?

Or if using a photocell, one lead to pin the other to ground?

I was laboring under the notion that there had to be that voltage divider that I've seen in some books where one pot pin goes to +5, the other to ground and the middle pin to the pic ADCIN pin.

Tony

Bruce
- 15th April 2006, 02:44
If you have an analog signal from some external device, say, a temperature
sensor or something else, that outputs an analog voltage, then you can
connect this analog source directly to the PIC A/D input.

If you're using a potentiometer to simulate the external analog signal, then of
course you'll want one end to Vcc, the other to ground, and the wiper to the
PIC A/D input.

Without one leg of the potentiometer to Vcc you wouldn't have anything but
ground on the PIC A/D input.

mister_e
- 15th April 2006, 08:55
AND be sure you POT or ELSE analog source meet the maximum A/D input impedance.

If you plan to use a PhotoResistor, you will need to pass the PhotoCell trhough an OPAmp or else method.

look the PIC datasheet (once again) to know the maximum PIC A/D impedance

TonyA
- 15th April 2006, 14:21
Ok, thanks for the info.

So RCTIME is just measuring the time for a cap to discharge, but the voltage source is coming from the pic pin itself, when it goes from low to high. In this case you would just hook the pot up like what's described for using the POT command? (None of the pots pins to Vcc)

Thanks again,
Tony

mister_e
- 16th April 2006, 09:31
RCTIME and POT command are just 'usefull' when your PIC don't have any AD converter. While it's just a pain and real waste of time to do some intelligent calibration, forget them. Choose a PIC with internal AD or use an external one. If you use an external one you'll discover really fast that it just don't worth the investement while a PIC with internal AD are not really much expensive than others without.

Your POT is connect between VCC and GND, the wiper can go directly or through a low value resistor to your PIC AD input.

If your software don't provide any noise cancelation, i suggest to add a ~0.1uF between PIC input and GND to filter the signal a little bit.

If you use the above method, your POT impedance must meet the maximum PIC AD impedance too. Look into your PIC datasheet under the AD section, you'll fiond it there.

BUT if you don't have any POT that meet it, you can even place a buffer between your POT and the PIC. almost any decent op-amp will do the job.

ADCIN is easy to use and work really fine even if you can do it simply by writing/reading directly to the internal registers. That will also provide tighter code.

TonyA
- 16th April 2006, 15:47
I see. So the POT and RCTIME are useful if your pic doesn't have an a/d convertor.

Thanks for the info on the circuit, using a resistor before the pin and the cap for filtering. I appreciate it.

I'm looking in one of the books for A/D conversion. They show a 50K pot, the wiper going directly into the pic pin, but there is a 15K "pull-up" resistor connected from the +5V to the pot. Is this recommended?

mister_e
- 16th April 2006, 17:55
Could be a soultion but i feel the POT will lost his linearity response. well i think

Let's do some math

1/5 pot maximum position:

in theory, we should have 1/5 Vcc on the wiper = 1 Volt
voltage divider resistor are 10 and 40K
Voltage divider ratio is 10/50K

Using the 15K pull up....
(10//15)/40K
voltage divider ration is 6/46
Voltage on the wiper = 6/46 * 5 = 0.65 Volts


1/2 pot maximum position:

in theory, we should have 1/2 Vcc on the wiper = 2.5 Volt
voltage divider resistor are 25 AND 25k
Voltage divider ratio is 25/50K

Using the 15K pull up....
(25//15)/25K
voltage divider ration is 9.3/34.3
Voltage on the wiper = 9.3/34.3 * 5 = 1.36 volt

and so on. Unless your application can deal with that kind of un-linear curve, yes you can use it. I'm not a fan of it

TonyA
- 16th April 2006, 18:37
Hi,

Thanks for that. I see what you're saying. Thanks again

Tony