|
|
View previous topic :: View next topic |
Author |
Message |
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
12F629 comparator operation |
Posted: Tue Apr 27, 2004 6:02 am |
|
|
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 |
Posted: Tue Apr 27, 2004 7:36 am |
|
|
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 |
Posted: Tue Apr 27, 2004 7:53 am |
|
|
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
|
Re: 12F629 comparator operation |
Posted: Tue Apr 27, 2004 8:18 am |
|
|
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 |
Posted: Tue Apr 27, 2004 10:01 am |
|
|
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
|
Re: 12F629 comparator operation |
Posted: Tue Apr 27, 2004 2:23 pm |
|
|
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] |
|
|
|
|
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
|