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

Variable Time to Read Timer1 Counts

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



Joined: 04 Aug 2005
Posts: 21

View user's profile Send private message

Variable Time to Read Timer1 Counts
PostPosted: Mon Mar 03, 2008 1:35 am     Reply with quote

Hi All..

I have a problem in setting time to count pulses in Timer 1..
This is how I usually do it:

Code:
   setup_timer_1 ( T1_EXTERNAL | T1_DIV_BY_1 );
   count=0;
   set_timer1(0);

   output_low(S2);
   output_low(S3);

   delay_ms(200);
   count=get_timer1();


This means I'll count incoming pulses to my pin15 of pic16f877a for~200ms.. But right now I need to vary the time because it depends on other factors.. I guess I cant use delay_ms() anymore right? How to do it then? Confused

Please help... TQ soo much Very Happy
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Mar 03, 2008 5:51 am     Reply with quote

Quote:
But right now I need to vary the time because it depends on other factors.. I guess I cant use delay_ms() anymore right?
Do you know ahead how long the delay needs to be? If yes, you can vary the time by passing delay_ms() a variable instead of a fixed constant.

For a more detailed help you will have to explain to us what the 'other factors' consist of.
ChickymEAL
Guest







PostPosted: Mon Mar 03, 2008 6:41 pm     Reply with quote

The 'other' factor is actually an input from sensor.
I need to count incoming pulse from sensor for certain period of time, then based on the number of pulse I'll need to adjust the time period to count the next incoming pulse..

The time period is adjusted by using bisection method (but thats a different story).. The important part is i need to vary the time to count the incoming pulse...

Any idea? I'm quite at dead end here.. Please advice..
Guest








PostPosted: Mon Mar 03, 2008 8:34 pm     Reply with quote

ckielstra wrote:
Do you know ahead how long the delay needs to be? If yes, you can vary the time by passing delay_ms() a variable instead of a fixed constant.


Ermm.. how do I do that? Is it like this:

Code:
x=1000;
delay_ms(x);


I've tried this before n it does not work..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 03, 2008 8:49 pm     Reply with quote

Do you have version 3.xxx of the compiler ? (Instead of 4.xxx)
If so, see this thread for links to delay routines that accept 16-bit variables.
http://www.ccsinfo.com/forum/viewtopic.php?t=32288
Chicky



Joined: 04 Aug 2005
Posts: 21

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 12:38 am     Reply with quote

ooook..
I've updated my compiler n it works! Yay!

Thanks a lot guys~ Very Happy
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