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 support@ccsinfo.com

Comparator and unused pin?

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



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

Comparator and unused pin?
PostPosted: Sat Feb 21, 2015 3:56 am     Reply with quote

Hi

When using a chip with 2 internal opamp as comparators and I only use one of them I have understanding problem. I only use 18F4550 for illustrate my confusing.

How to handle unused pin, is they disconnected from the real pin?
If using internal VRef as CVREF, will the VIN+ on both comp be disconnect from the input pin?

I use the config to the right on the picture (CM2:CM0=110), internal VREF as CVREF.

I have confusion to understand how to handle the pin on the PIC. Normally I just use an external opamp. This time I will use one of the new smart chip with included hardware as opamp.

http://s000.tinyupload.com/index.php?file_id=00461571666128813305
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Sat Feb 21, 2015 4:35 am     Reply with quote

You start with some confusion. The 4550, does not have an internal op-amp. It only has comparators. There are similarities between the devices (you can make an op-amp behave as a slightly less than optimal comparator), but the key is that the comparator output, is designed to be digital, not to 'linger' in the transition area, while the op-amp is designed to be linear across this region dependant on it's gain and what the input is doing. The comparator is also designed to recover quickly from being driven to the rails.
Have a look at:
<rohmfs.rohm.com/en/.../amp.../opamp_comparator_tutorial_appli-e.pdf>

So, ignoring this, and talking about the comparators, start by looking at the port I/O summary (Table 10-1). Note the order of priority. Note that a TRIS setting of '0' on any of the pins to the comparator inputs (setting it as a digital output), _overrides_ it's use as an analog input. However also note that if you try to use the pin as a digital input, or if the pin is set as an analog output, the digital TRIS settings are overridden.

Then step to figure 22-1. This shows all the comparator configurations. The only ones that allow CVref to be used as one input, are 000, 010, 011, and 110. The one of interest is 110, with CIS=0. If you use this, and use AN0 as the input to comparator 0. Then you can still use RA1, _as a digital output_ only. The TRIS will then override it's analog function.

If you want an internal op-amp, then there are chips with these (mainly a few of the newer PIC16's). The configurations on these are very different from those on the comparators. If it's an op-amp you want, then you need to be looking at these, rather than the comparators. If you look at a chip like the PIC16F1703, this has two genuine op-amps, and you can separately choose between the external pin, and the voltage reference on the +ve input, and between the external pin, or the output on the -ve input. Very different....
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Sat Feb 21, 2015 6:50 am     Reply with quote

Just a fast reply to correct some confusion. At the moment I only want the Comparator function! I call it an opamp...I mean Comparator.
I will read and try to understand the newer PIC hardware later, thanks. As you suggest, it is the 16Fxxxx I looking at, but have not made a conclusion.
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Wed Feb 25, 2015 6:56 am     Reply with quote

In the data sheet for respective comparator interrupt there is noted that

Direct from the data sheet.
Code:
The user, in the Interrupt Service Routine, can clear the interrupt in the following manner:

a) Any read or write of CMCON will end the mismatch condition.
b) Clear flag bit CMIF.

[b]A mismatch condition will continue to set flag bit CMIF[/b].
Reading CMCON will end the mismatch condition and
allow flag bit CMIF to be cleared.


When CCS leave an "comparator interrupt they clear the "CMIF" _but_ the mismatch condition is still there, missing the read of CMCONx.

Is that by design or an error?
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Wed Feb 25, 2015 8:36 am     Reply with quote

All interrupts involving an event like this, require you to clear the event. After all unless you have, the even is still waiting to be serviced.
So in serial RX interrupts, you must read the byte received.
In 'interrupt on change' interrupts, you need to read port B.
etc. etc..
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Wed Feb 25, 2015 9:01 am     Reply with quote

Of cause, don't know what I was thinking... Embarassed
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