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

Using a comparator as an ADC

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



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

Using a comparator as an ADC
PostPosted: Fri Feb 25, 2005 4:00 am     Reply with quote

Hi,

MCU : 16F628
Compiler : PCM Compiler ver3.1619
Xtal : 4 Mhz

Is it possible to use the comparator input as an ADC ?? I would like to read voltages upto 2.5 V ( 5 V would be preferable).

thanks
arun
Ttelmah
Guest







PostPosted: Fri Feb 25, 2005 4:53 am     Reply with quote

Yes(ish)...
Basically, you need to generate some way of ramping a voltage. If (for instance), you build an external constant current source, charging up a capacitor, then attach the junction pin of this, to an pin on the PIC, and to one of the comparator inputs, with the voltage you want to measure to the other, you can turn the pin to an output, and pull the capacitor 'low'. Wait a while for it to fully discharge, then let the output 'float', and time how long it takes for the compator to switch. The time is proportional to the voltage being measured.
You could also use a PWM output to form a DAC, and compare the voltage from this with the required input.
You can even simplify the ramping system, just using a resistor to charge the capacitor, but then you have to allow for the ramp being non-linear in the code.
Just about every ADC, contains a comparator, and this component forms the 'core' part needed to make an ADC, but there needs to be some other parts to support it.

Best Wishes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Feb 25, 2005 8:40 am     Reply with quote

Look at Microchip's application notes AN512 and AN513 on how to measure analog signals with digital inputs. They are old but still just as sound as when they were written.
_________________
The search for better is endless. Instead simply find very good and get the job done.
wireless



Joined: 02 Nov 2003
Posts: 16
Location: London England

View user's profile Send private message

PostPosted: Sun Feb 27, 2005 7:54 am     Reply with quote

Hi Arun

It depends how much resolution you need from the ADC. If 4bits (16) steps is OK you can use the internal Vref generator on the 16f628.

For measuring 5 V ( with a 5V supply) you will need to pot. down the test voltage with say two equal resistors eg 10k. Then start the Vref generator at 0 (see set_vref()) and increase its value one step at a time whilst monitoring the comparator output bit. When it changes state it means that the Vref has just exceeded half the input voltage.

This works well for simple battery voltage testing and I have used it to control the brightness of a LED diplay as a function of ambient light level by connecting a LDR and resistor to the comparator input.

Regards


Terry
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