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

Timer1 will miss counting the first clock pulse

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



Joined: 04 Feb 2011
Posts: 5
Location: Japan

View user's profile Send private message Visit poster's website MSN Messenger

Timer1 will miss counting the first clock pulse
PostPosted: Fri May 04, 2012 1:53 am     Reply with quote

Hi, I got to know that "Timer1" made a mistake.

Information sauce is "Microchip".
http://ww1.microchip.com/downloads/en/DeviceDoc/80329a.pdf

Is there any solution in CCS?

Code:
#include <18F97J60.h>

setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);
set_timer1(0);

   int32 count = 0;
   
   while (true)
   {
      count = get_timer1();
      if (0 < count)
      {
         set_timer1(0);
         fprintf("Input : %Ld \r\n", count);
         count = 0;
      }
   }

Please comment, and inform us of it kindly.
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Fri May 04, 2012 7:26 am     Reply with quote

Depends how fast your CPU is running.
No 'fix' is needed provided your main CPU is clocking faster than about 20MHz.

It wouldn't normally apply in the code you show, anyway, since there is no relationship between when you are doing things, and the external clock. The 'point' is that when you get an interrupt, and want to update the timer inside the handler for this, you need to ensure that both parts of the write are performed before the clock next drops, _or_ wait for the following edge, and then perform both updates, and increment the value, if you are not going to miss an edge.

You are potentially making things 'worse', by using int32 comparison on an int16 value, so the loop will be slower than it can be.

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