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

setup Timer1 as a counter

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







setup Timer1 as a counter
PostPosted: Sun Jun 01, 2003 10:51 pm     Reply with quote

Stupid problem here.

I'm using a 32.768 crystal.
And need to clear and read the time.
How can i Set timer 1 as a counter and reset it to measure time between two variables.
I need to meassure the time in ms.

Thanks for any help!
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514938
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: setup Timer1 as a counter
PostPosted: Mon Jun 02, 2003 12:32 am     Reply with quote

This should do it:
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);

Don't forget you have to connect the crystal pins to the ground with two 33pf capacitors.

Consult the CCS help for more setup_timer_1() options.

Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514940
SKROTNISSE
Guest







I've tried this. But only get 0 time
PostPosted: Mon Jun 02, 2003 12:48 am     Reply with quote

I have used get_timer and set_timer. But only get 0. Do I have to make a counter that ticks everytime the timer overflows? In that case hoe do I do that?
The crystal is connected to RC0 and RC1 and I use two 33pF capacitors.

Cheers
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514941
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: I've tried this. But only get 0 time
PostPosted: Mon Jun 02, 2003 3:24 am     Reply with quote

Ok, it seems your counter is not incrementing. Post your code so I can take a look at it.

__Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514943
SKROTNISSE
Guest







The code
PostPosted: Mon Jun 02, 2003 7:10 pm     Reply with quote

Here is the code I tried.
But I probably need some more, Im a newbee on timers u see. Or of corse you have seen that.
If you got anything I can use I would be very grateful!

setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
while(TRUE){
SET_TIMER1(0);
delay_ms(200);
Time=GET_TIMER1();
Time2=(Time/32.768);

}


Cheers
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514984
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: The code
PostPosted: Mon Jun 02, 2003 7:47 pm     Reply with quote

Ok. Now please answer the following questions:
1-How have you set up PORTC?
2-What is the type of variable Time? It should be a 16bit integer
3-What is Time2? it should be float
4-Which one of those variables iz zero? When you read Time it should return a value around 6553
5-What version of compiler are you using?

You can also take the '|T1_CLK_OUT' part out and try it again.

Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514986
SKROTNISSE
Guest







Answers
PostPosted: Mon Jun 02, 2003 9:34 pm     Reply with quote

1. I havent done anything special about PORTC
2. Time is a Long, old compiler version int16 and so on doesn't work
3. Time 2 is float
4. Time 2 is zero
5. Compiler version: 2.717

But do I need a function that the counter is put in?
Or can I just use these sentenses: Get and Set timer to get time and reset timer?

cheers
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514987
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: Answers
PostPosted: Mon Jun 02, 2003 10:14 pm     Reply with quote

Your code should work. Is Time zero as well? Or only Time2 is zero? What is the value of Time?

I think you should strongly consider upgrading to a newer compiler version.

__Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514988
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