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

Problem getting Timer 1 to work....

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








Problem getting Timer 1 to work....
PostPosted: Wed Nov 12, 2008 1:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 3:47 pm     Reply with quote

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








PostPosted: Wed Nov 12, 2008 4:04 pm     Reply with quote

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