|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Problem getting Timer 1 to work.... |
Posted: Wed Nov 12, 2008 1:47 pm |
|
|
Hi All,
I'm having trouble getting Timer1 to run. I think I'm setting it up correctly according to my Version 4.0 manual (August 2006), but the Get_Timer1 statement always returns a 0 :-(!
Here is a short piece of code that demonstrates the problem:
Code: |
#include <12F629.h>
#fuses INTRC_IO,NOWDT,NOBROWNOUT,NOPROTECT,MCLR
#use delay(clock=4000000)
#define LCD_Output Pin_A0
#use rs232(baud=9600, xmit=LCD_Output)
void main()
{
int16 PulseWidth;
printf("Hello World \n\r");
setup_timer_1 ( T1_INTERNAL|RTCC_DIV_256 );
set_timer1(0);
while(1)
{
PulseWidth = get_timer1();
printf("Counter value: %2X\n\r", PulseWidth);
} //while
} //main
|
I'm continuously polling Timer1, and sending the data to a PC. I'm expecting that the small delay associated with the printf function will show me a different value for Timer1 each time, but it's always zero!
My compiler version is 4.050
Thanks,
Doug |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 12, 2008 3:47 pm |
|
|
Quote: | void main()
{
int16 PulseWidth;
printf("Hello World \n\r");
setup_timer_1 ( T1_INTERNAL | RTCC_DIV_256 );
set_timer1(0);
while(1)
{
PulseWidth = get_timer1();
printf("Counter value: %2X\n\r", PulseWidth);
} //while
} |
Look closely at the line in bold. There is a problem on that line. Look at
the 12F629.H file, in the sections on the timers. Hint: What is the name of
each timer ? |
|
|
Guest
|
|
Posted: Wed Nov 12, 2008 4:04 pm |
|
|
PCM,
Yep, I already found that :-(! The problem is that I was trying to re-use some old Timer0 code, and didn't check it closely enough! I changed the line to:
Code: |
setup_timer_1 ( T1_INTERNAL|T1_DIV_BY_8 );
|
and everything is happy now!
Doug |
|
|
|
|
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
|