PDA

View Full Version : Comparator Help reqd



Squibcakes
- 21st September 2005, 07:34
Does anyone have experience with PIC built in camparators?

I have a few questions?

1. What max voltage can a comparator input take? I would like to input 12volts? Or will this smoke the PIC? (Alternatives if this is the case??)

2. How good is the built-in voltage reference Vref?

3. Is it better to sacrifice an input and set your own external Vref?

Cheers

G8RPI
- 21st September 2005, 08:43
Hi,

To get exact answers you (or I) have to read the data sheet for the PIC in question. However you have not stated which pic you want to use.
I can make a few comments though.
1, 12V will damage a PIC if applied to a pin without current limiting. If you limit the current to a milliamp or so the pin will be clamped by the protection diode to just above the supply (Vdd) voltage.
The datasheet will tell you the useable voltage range, to sense 12V you would have to use a resistive divider to drop the voltage to within this range.
2, Check the datasheet some use the supply (Vdd) so it's as good as you make it, other have a "real" reference and they are pretty good, but it depends on your needs.

3, see 2 above.

HTH Robert G8RPI

Squibcakes
- 22nd September 2005, 00:19
Hi Rob,

Thanks for yor reply, I haven't decided on which chipset to use yet. It all comes down to cost. (500 chips in total for this project)

I would prefer to use the 14 Pin 16F630 which gives me more I/Os but cost wise a may end up using the 8 Pin 12F629.

The Electrical specs for both chips are much the same.

I will probably use the resistive divider and use the 16F630.

Cheers

G8RPI
- 22nd September 2005, 11:51
Hi,
The 16F630 divides down the Vdd for it's reference and the usable input range is about 0.3 to 3.5V with a 5V Vdd. the resoultion is about 0.15V (Vdd/32).
Depending on your application, it may be worth considering the 16F676 with it's 10 bit ADC. The ADC allows you more freedom to add filtering etc in software.

Robert G8RPI.

Squibcakes
- 23rd September 2005, 05:19
Hi Rob,

At this stage, I'm just learing the basics (with a 16F628A), so I'm not ready to decide on a chip for that reason. (But thanks for the info)

I have been able to get the comparator working using an external Vref by resistive divider network, and it works quite well. This I am ok with. (thanks to mister_e's simple code example).

However, no luck when trying to use the internal voltage reference.
I think this is my problem...

The datasheet is not very clear when setting the VCON VR<3:0>: bits.

For example, the datasheet states that the voltage reference specs should be
3.0V < VDD < 5.5V

But by following the formula for configuring the voltage reference I get values between:
0 to 3.13V for VRR=1 and
1.25 to 3.59V for VRR=0,
assuming VDD=5V.

Also, on another matter, if we want to output the internal Vref to RA2, (to monitor this voltage), should we set TRISA.2 to an output pin?

Any Ideas?

Squibcakes
- 27th September 2005, 23:56
Ok,

I have searched this forum and found a good link to Melanie's Comparator Tutorial. Fantastic, even for a dummy like me.

http://list.picbasic.com/forum/messages/3064/3607.html?1020960642

Hope this helps anyone else out there.

J

Melanie
- 28th September 2005, 03:39
Goodness... I didn't think that old thread was still in existance - let alone folks reading it!