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 Comparator with 16f1938

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



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

Using Comparator with 16f1938
PostPosted: Wed Jul 06, 2011 4:22 pm     Reply with quote

Hi,

I have a project to use 16F1938 to monitor an analog signal.
Currently analog signal is connected to RA2 and plan to use DAC as reference voltage of comparator.

I am confused by those options of comparator defined in 16f1938.h:
Code:

#define CP2_A0_A2      0x80000000
#define CP2_A1_A2      0x80010000
#define CP2_B3_A2      0x80020000 
#define CP2_B1_A2      0x80030000 
#define CP2_A0_DAC     0x80100000
#define CP2_A1_DAC     0x80110000
#define CP2_B3_DAC     0x80120000 
#define CP2_B1_DAC     0x80130000 
#define CP2_A0_FVR     0x80200000
#define CP2_A1_FVR     0x80210000
#define CP2_B3_FVR     0x80220000 
#define CP2_B1_FVR     0x80230000 
#define CP2_A0_VSS     0x80300000
#define CP2_A1_VSS     0x80310000
#define CP2_B3_VSS     0x80320000 
#define CP2_B1_VSS     0x80330000 


My question is that which option should be used with setup_comparator knowing RA2 is connected to analog input and DAC used as reference voltage? Any example code?

Thanks,
Howard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 06, 2011 5:20 pm     Reply with quote

Quote:

analog signal is connected to RA2 and plan to use DAC as reference
voltage of comparator.

I don't think this combination is possible.

Look at the pin diagram for the 16F1938 on page 5 of the data sheet:
Quote:

Pin Diagram – 28-Pin SPDIP/SOIC/SSOP (PIC16F1938, PIC16LF1938)

For pin A2, it shows that it's also the C2IN+ comparator input:
Quote:
COM2/DACOUT/VREF-/C2IN+/AN2/RA2


Now look at this diagram in the 16F1938 data sheet (on page 174):
Quote:

FIGURE 18-2: COMPARATOR MODULE SIMPLIFIED BLOCK DIAGRAM

It shows that CxIN+ and the DAC and the FVR buffer 2, and Vss
are all connected to the same 4:1 multiplexer. You select from one
of those 4 inputs to drive the + input of the comparator. This means
your proposed combination of inputs is not possible.


The other input of the comparator (the - input) is driven by another
4:1 multiplexor with these 4 choices as inputs:
Quote:

C12IN0- AN0 RA0
C12IN1- AN1 RA1
C12IN2- AN9 RB3
C12IN3- AN10 RB1


You need to choose inputs from the available options.

16F1938 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/41574A.pdf
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Wed Jul 06, 2011 7:12 pm     Reply with quote

PCM,

Thanks for the quick response and helps.

I have revised the board based on your suggestion to connect analog signal to RA0. With two options available on setup_comparator,
Code:

#define CP1_A0_DAC     0x8010
#define CP2_A0_DAC     0x80100000


If CP1 is used, comparator output will be on RA4 and CP2 goes with RA5. Correct?

If CP1_A0_DAC is selected, and DAC is set as
Code:

setup_dac(DAC_VSS_VDD);

then dac_write(x) where x could be anything between 0-31 could be used to set the Vref for comparator. Correct?

Is there any example code on this?

Thanks,
Howard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 07, 2011 2:08 pm     Reply with quote

To give you a 100% accurate answer, I would have to test it in hardware
with your compiler version. It's better if try to make it work first. Then
if doesn't work, post your test program and test method, and I'll look at it.
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