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

12F629 comparator operation

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



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

12F629 comparator operation
PostPosted: Tue Apr 27, 2004 6:02 am     Reply with quote

I am working on an application that requires the use of the comparator in the 12F629. I have an external input on GP1 (comparator +ve), and the internal reference connected to comparator -ve. GP0 is unused. I want the comparator output to be on GP2. I have set GP0 and GP1 as inputs, and GP2 as an output. I have selected A1_VR_OUT_ON_A2 (mode 3) for the comparator setup.

The Comparator is working as I can see the interrupts happening - its just that I can't get the comparator output signal on GP2! I have read the data sheet several times, and the only thing I can see is a COUT enable signal shown in Fig 3-2. I had assumed that setting GP2 as an output would enable the output - but then again maybe not. Anybody got any ideas?
Ttelmah
Guest







Re: 12F629 comparator operation
PostPosted: Tue Apr 27, 2004 7:36 am     Reply with quote

adrian wrote:
I am working on an application that requires the use of the comparator in the 12F629. I have an external input on GP1 (comparator +ve), and the internal reference connected to comparator -ve. GP0 is unused. I want the comparator output to be on GP2. I have set GP0 and GP1 as inputs, and GP2 as an output. I have selected A1_VR_OUT_ON_A2 (mode 3) for the comparator setup.

The Comparator is working as I can see the interrupts happening - its just that I can't get the comparator output signal on GP2! I have read the data sheet several times, and the only thing I can see is a COUT enable signal shown in Fig 3-2. I had assumed that setting GP2 as an output would enable the output - but then again maybe not. Anybody got any ideas?

Read paragraph 6.4 of the data sheet.
The tris register controls whether the data is output or not. TRIS defaults to having the pins as inputs...

Best Wishes
Ttelmah
Guest







Re: 12F629 comparator operation
PostPosted: Tue Apr 27, 2004 7:53 am     Reply with quote

Ttelmah wrote:
adrian wrote:
I am working on an application that requires the use of the comparator in the 12F629. I have an external input on GP1 (comparator +ve), and the internal reference connected to comparator -ve. GP0 is unused. I want the comparator output to be on GP2. I have set GP0 and GP1 as inputs, and GP2 as an output. I have selected A1_VR_OUT_ON_A2 (mode 3) for the comparator setup.

The Comparator is working as I can see the interrupts happening - its just that I can't get the comparator output signal on GP2! I have read the data sheet several times, and the only thing I can see is a COUT enable signal shown in Fig 3-2. I had assumed that setting GP2 as an output would enable the output - but then again maybe not. Anybody got any ideas?

Read paragraph 6.4 of the data sheet.
The tris register controls whether the data is output or not. TRIS defaults to having the pins as inputs...

Best Wishes

Sorry, I see you say you have set GP2 as output. However beware, that unless you have selected 'fast_io', remember that the compiler will still override your selection, if it does not see an 'output' on the pin.

Best Wishes
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

Re: 12F629 comparator operation
PostPosted: Tue Apr 27, 2004 8:18 am     Reply with quote

Best Wishes[/quote]
Sorry, I see you say you have set GP2 as output. However beware, that unless you have selected 'fast_io', remember that the compiler will still override your selection, if it does not see an 'output' on the pin.
Best Wishes[/quote]

Don't quite follow that? The I/O direction is set first (GP2 output) then the comparator is set up again with GP2 as an output? But yes I am using standard_io.
Ttelmah
Guest







Re: 12F629 comparator operation
PostPosted: Tue Apr 27, 2004 10:01 am     Reply with quote

adrian wrote:
Best Wishes

Sorry, I see you say you have set GP2 as output. However beware, that unless you have selected 'fast_io', remember that the compiler will still override your selection, if it does not see an 'output' on the pin.
Best Wishes[/quote]

Don't quite follow that? The I/O direction is set first (GP2 output) then the comparator is set up again with GP2 as an output? But yes I am using standard_io.[/quote]
Do you actually do an 'output' operation on the pin?. With standard I/O, the compiler will control TRIS for you (which is normally fine), but can get confused where you want to override the decision. I must admit to preferring fast_io, since standard I/O has the 'habit' of sometimes ignoring your settings. Basically, if (for instance), you set the TRIS to 0 on a pin, and an output has not been done, you will sometimes see the compiler 'override' the settings. I'd probably run the code in the MPLAB simulator, and verify that the TRIS register, really does have bit 2 set to 0.

Best Wishes
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

Re: 12F629 comparator operation
PostPosted: Tue Apr 27, 2004 2:23 pm     Reply with quote

Quote:
"Ttelmah wrote"
........standard I/O has the 'habit' of sometimes ignoring your settings. Basically, if (for instance), you set the TRIS to 0 on a pin, and an output has not been done, you will sometimes see the compiler 'override' the settings. I'd probably run the code in the MPLAB simulator, and verify that the TRIS register, really does have bit 2 set to 0.
Best Wishes


That was the clue I was after - your spot on!

I ran the code through the simulator and TRIS set up the output correctly. However, setting up the comparator afterwards corrupted the TRIS, forcing GP2 to become an input! Swapping the order around so that the comparators are setup first followed by the TRIS solved the problem.

Many thanks.[/quote]
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