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 ( internal connection )

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



Joined: 11 Nov 2004
Posts: 7
Location: ITALY

View user's profile Send private message

Comparator ( internal connection )
PostPosted: Mon Nov 15, 2004 8:15 am     Reply with quote

Hi,

I have need to connect C1- with C2- by software .
( see PIC16781 datasheet page 96 figure 12-5 )
The connection is internal , but in the register I haven't found the appropriate bit control.

I ' am trying to use two comparator with common input (C1- an C2-) while C1+, C2+ are connected to external pin

Confused
Any idea?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 15, 2004 1:25 pm     Reply with quote

The 16C781 data sheet has sample code (in ASM) for a window
comparator in Figure 12-3. You can convert that code to CCS C.
Some of the ASM code can be converted to use CCS built-in functions.

But CCS apparently doesn't have any built-in functions for the
comparator in version PCM version 3.212. The easiest way to
fix this problem is by writing directly to the PIC's registers.

For example, here is the code from Figure 12-3 that configures
the comparator registers.
Code:
MOVLW B’10000000’ ; C1: no output
MOVWF CM1CON0 ; VREF1, AN4
MOVLW B’10010000’ ; C2: no output
MOVWF CM2CON0 ; invert,VREF1,AN4


The following code is a translation of the ASM code above, to CCS:
Code:

// Declare the addresses of the Comparator registers.
// The addresses come from Figure 2-3 of the 16C781 data sheet.
#byte CM1CON0 = 0x119
#byte CM2CON0 = 0x11A

main()
{
// Put other init code here.

// Setup comparator registers.
CM1CON0 = 0x80;
CM2CON0 = 0x90;


}


You don't need to select the RAM bank. The CCS compiler automatically
takes care of setting the proper bank.

I have shown only part of the translated code. You need to do the rest.

Also, version 3.212 doesn't appear to support the comparator interrupt.
You will need to add an #int_default function to your program to do this.
See the CCS manual (or the Help file) for information on #int_default.
See this thread for more information:
http://www.ccsinfo.com/forum/viewtopic.php?t=6656&highlight=intdefault
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