|
|
View previous topic :: View next topic |
Author |
Message |
jennifer Guest
|
comparators in pic16f88, please! |
Posted: Wed Oct 15, 2008 4:57 am |
|
|
Hi
I am really confused with this comparators thing. Really!
I need to compare 2 voltages and if one is bigger-do some code or output high.
I can see there are 2 comparators and lots of outputs and inputs:
1. What are the 2 analog inputs of comparator?
2. What is the output of the comparator? ( comparator has 1 output! )
3. Do I need software to compare-or it can be done without involve any software? Is this comparator stand-alone? Can be controlled by software?
4. Can I use it to check if there is a change in voltage and output high ?
5. What is the code require to define comparators ?
6. Does comparator function like interrupt that stop all code and do a routine?
I am so confused from data-sheets !! Why is it so hard? How many pins for simple comparators??
I will be happy for any kind of information about this.
Thanks a lot !
jen |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Wed Oct 15, 2008 5:23 am |
|
|
Jennifer,
Please go through Section 13 of the 16F88 datasheet. The first paragraph in this section says Quote: | The comparator module contains two analog comparators. The inputs to the comparators are multiplexed with I/O port pins RA0 through RA3, while the outputs are multiplexed to pins RA3 and RA4. The on-chip Voltage Reference (Section 14.0 “Comparator Voltage Reference Module”) can also be an input to the comparators. |
I think this serves to answer 1 and 2. There are two comparator modules, therefore, two outputs.
The comparators are hardware comparators. Software is only used to configure the working of the comparators, not do the actual comparision. Datasheet Section 13.1 shows the various configurations you can use. Register CMCON has some configuration bits for the comparator. In the CCS help manual, have a look at the instruction setup_comparator()
For question 4 - yes you can. You will need to set a reference voltage on one pin (or you may use the internal reference) and feed the signal to the other pin.
5. Please attempt this yourself first.
6. You can configure the comparator to interrupt the processor. Datasheet Section 13.6 details this. CCS help - INT_COMP
Rohit |
|
|
jennifer Guest
|
|
Posted: Wed Oct 15, 2008 9:58 am |
|
|
I HAVE READ THIS PARTS OF DATA SHEETS SO MANY TIMES.
"The inputs to the comparators are multiplexed with I/O port pins RA0 through RA3, while the outputs are multiplexed to pins RA3 and RA4."
what does it mean?!? why cant they say: inputs:x,y outputs:a,b ??
why microchip's data sheets always so unreadable? (i am finishing engineering..)
input are ra0 and ra3 ? so how can ra3 can be output too ?
i just need to know 2 pins for input .. multiplexed?? what ??
do i get high on output , or do i get the reference between 2 voltages?
does the chip works without any connection to comparators?
thanx a lot- i just cant understand microchip's data sheets ever... |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Wed Oct 15, 2008 11:39 am |
|
|
Jennifer,
I think the word 'multiplexed' is the problem, right? If you aren't comfortable with what a multiplexer is, read this http://en.wikipedia.org/wiki/Multiplexer . In simple terms a multiplexer is capable of choosing one out of many signals. You have four pins that can be used as comparator inputs. But you are allowed to choose only two out of those four to act as inputs to the comparator. The device that allows you to do this is called a multiplexer. Any two of A0, A1, A2, A3 can be used as inputs to the the comparator module. Since there are two separate comparator modules there are two outputs which can be 'gated' to either of A3 or A4, or even read internally (in this case they are not 'sent ' out of the chip; the output is simply reflected by the bit CxOUT. You set/select outputs and inputs using bits in the CMCON register.
Think of the whole multiplexer-demultiplexer system in terms of a telephone exchange. With the thousands of telephone users, it is not feasible to string wires across from your house to everyone you will possibly call. There's just a pair of wires going from your house to the exchange. A set of multiplexers and demultiplexers guides the voice signal from your telephone to any other telephone in the world.
Anyway, the output of the comparators can be 'true' or 'inverted', which means that the comparator can be set to give a high ('true'), or low ('inverted'), when the non-inverting input is greater than the inverting input, depending on whether the CxINV bit in CMCON is set or not.
See this sample code in the CCS help file: Quote: | // Sets up two independent comparators (C1 and C2),
// C1 uses A0 and A3 as inputs (- and +), and C2
// uses A1 and A2 as inputs
setup_comparator(A0_A3_A1_A2); |
Code: | does the chip works without any connection to comparators? | Of course it will work even if you don't use the comparators. Just don't configure them in code. Just use the instruction setup_comparator (NC_NC_NC_NC) during initialization.
Check out ex_comp.c in the 'Examples' directory of CCS. It has a nice sample that you could try out. The code is for a 12F675 but you can change it to a 16F88.
My strongest advice to you is to have a look at the datasheet again particularly Figure 13-1, in Section 13.1 This figure shows you exactly how both the comparators can be setup. Again, have a look at Figure 13-3. This gives you the block diagram for one comparator.
Just a matter of personal opinion, I find that Microchip has some of the best datasheets around. TI and Maxim also have good datasheets. I find Cypress pathetic.
Rohit |
|
|
|
|
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
|