View previous topic :: View next topic |
Author |
Message |
octopuss83
Joined: 06 Nov 2011 Posts: 13
|
Comparator and Timer |
Posted: Sun Nov 06, 2011 9:09 am |
|
|
Hello
I have a problem: I want use Timer1 as a counter with increment when the output of comparator change.
On the datasheet the register is: CMCON1: COMPARATOR CONFIGURATION REGISTER
and bit to set is: T1GSS: Timer1 Gate Source Select bit
But in the Wizard this option is in gray color (Other -> Comparator -> timer 1 source) I can't set this...
I work on a pic12F683.
Anybody have idea ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 06, 2011 1:41 pm |
|
|
The compiler (vs. 4.125) doesn't support the Timer1 gate bit
for some reason. But in the program below, I've added a small
macro to add support for it. Add those 3 lines above main(), and
then call the enable_t1_gate() function in main().
Code: |
#include <12F683.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOMCLR
#use delay(clock=4M)
#byte CMCON1 = 0x1A
#bit T1GSS = CMCON1.1
#define enable_t1_gate(x) x ? (T1GSS = 1) : (T1GSS = 0)
//===================================
void main()
{
setup_comparator(A1_VR);
enable_T1_gate(TRUE);
while(1);
}
|
|
|
|
octopuss83
Joined: 06 Nov 2011 Posts: 13
|
|
Posted: Mon Nov 07, 2011 6:30 am |
|
|
Thank you very much, I can continue my project now.
Just 2 question:
In my case the comparator output is connected to timer gate 1
so in my project I do use : enable_T1_gate(FALSE); that ok ?
I must count only COUT pulse (comparator output ). Timer 1 must be disabled ?
Thank you |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 07, 2011 1:09 pm |
|
|
First you said you want Timer1 gate enabled:
Quote: |
I want use Timer1 as a counter with increment when the output of comparator change.
|
So I posted a small function to enable the Timer1 gate for Comparator
input.
Then below, you say that you want to Disable Timer1 gate:
Quote: | so in my project I do use : enable_T1_gate(FALSE); that ok ? |
I don't know what you really want. You need to decide if you want
Timer1 gate enabled or disabled. My sample code will allow you to
enable or disable it. |
|
|
octopuss83
Joined: 06 Nov 2011 Posts: 13
|
|
Posted: Tue Nov 08, 2011 4:47 am |
|
|
in fact i want to put bit T1GSS to 0 and your function works fine for this
T1GSS to 0 Allow output comparator (COUT) connected on the timer 1 Gate
on datasheet :
bit 1 T1GSS: Timer1 Gate Source Select bit(1)
1 = Timer 1 Gate Source is T1G pin (pin should be configured as digital input)
0 = Timer 1 Gate Source is comparator output
.
Thanks for your function |
|
|
|