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 and Timer

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



Joined: 06 Nov 2011
Posts: 13

View user's profile Send private message

Comparator and Timer
PostPosted: Sun Nov 06, 2011 9:09 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 06, 2011 1:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2011 6:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2011 1:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 08, 2011 4:47 am     Reply with quote

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
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