championx
Joined: 28 Feb 2006 Posts: 151
|
16F648A comparator |
Posted: Thu Oct 17, 2013 7:48 am |
|
|
Hi all! i have a question regarding the comparator in the 16F648A.
Is it possible to use only one pin to compare external battery voltage with an internal vref?
I have a circuit already working with a 16F88, that one of the functions is to monitor the battery voltage across a resistor divider. I use the ADC to do this.
The thing is that now i have to use the same hardware but with the 16F648A. The resistor divider is connected to one of the comparator inputs.
so it is possible to compare this voltage across the divider to the internal vref and let the user know when the battery is empty? i Only can use 1 pin, a comparator input.
thanks! (sorry for my inglish) |
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19594
|
|
Posted: Thu Oct 17, 2013 9:42 am |
|
|
It depends on what you want to do with one other pin....
The only comparator mode capable of what you want, is the one described in Figure 10-1 'comparator I/O modes', as 'four inputs multiplexed to two comparators'. With this the +ve inputs of both comparators are connected to the Vref, and the outputs of the comparators are 'internal' (so don't use any pins). The two comparator -ve inputs are connectable to RA0 or RA3 (comp 1), and RA1 or RA2 (comp 2).
These are selectable by the CCS modes:
A0_VR_A1_VR
A3_VR_A2_VR
So if you use 'A0', then A1 is also connected to a comparator. Use A3, the A2 is also connected to a comparator.
Now when a pin is setup as a comparator input, this defines it as an 'analog' pin, and it won't function as a 'logic' input. However it can still be used as a logic output OK.
So depending on which pin you use, the 'other' pin from the pair, needs to be used as an output.
Now there is a very obvious 'caveat' with using the comparator, that it gives no advance warning of approaching failure, and could be triggered by noise on the rail if there are things being switched.
Best Wishes |
|