View previous topic :: View next topic |
Author |
Message |
SKROTNISSE Guest
|
setup Timer1 as a counter |
Posted: Sun Jun 01, 2003 10:51 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
Re: setup Timer1 as a counter |
Posted: Mon Jun 02, 2003 12:32 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
SKROTNISSE Guest
|
I've tried this. But only get 0 time |
Posted: Mon Jun 02, 2003 12:48 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
Re: I've tried this. But only get 0 time |
Posted: Mon Jun 02, 2003 3:24 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
SKROTNISSE Guest
|
The code |
Posted: Mon Jun 02, 2003 7:10 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
Re: The code |
Posted: Mon Jun 02, 2003 7:47 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
SKROTNISSE Guest
|
Answers |
Posted: Mon Jun 02, 2003 9:34 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
Re: Answers |
Posted: Mon Jun 02, 2003 10:14 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|