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

counting time...16F876

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



Joined: 16 Feb 2005
Posts: 25

View user's profile Send private message

counting time...16F876
PostPosted: Fri Feb 10, 2006 10:52 am     Reply with quote

I have an issue of counting. I have to run a while loop for some 10 seconds OR until gets signal. I think I cannot use delay here. Is there any better way other than using a counter and count instructions to know the time.

the loop is very simple and looks something like following...

Code:

while((input(SS1)==0)|(j<=30000)){
output_high(DIR3);
set_pwm2_duty(50);
j = j+1000;
}
set_pwm2_duty(0);


(I am using 20 MHZ Clock = 0.05 us
instruction clk = 4*0.05us = 0.2 us
3 instructions per loop = 0.6 us per one run in loop
to run the loop for say 5 sec , counter should be 8333 K)

am I correct or completely dumb! pls help

thx to the forum...
[/code]
Ttelmah
Guest







PostPosted: Fri Feb 10, 2006 11:22 am     Reply with quote

First comment. You don't need to keep setting the PWM duty to 50. It stays where it is set.
Second comment. Three instructions per loop!.... You probably have something like 20 instructions in the loop. You are testing a 16 bit value, which implies fetching two bytes, and comparing these against the constant. Probably about six to eight machine instructions. The input test will take a couple of instructions. The loop itself, involves a couple of machine cycles. Setting the PWM duty, should only involve two instructions (since your value is a 'short', the code just needs to load the constant value, then load this into the PWM register). The ouput instruction then probably adds only one instruction.
The 'best' way, is probably to use one of the hardware timers, (assuming your chip has these). Alternatively, use the RTCC (this is a hardware timer too, but one all the pics have, which in it's default setup, basically counts instructions, from 0 to 255 - you can test for it's interrupt flag becoming set, and clear this,and _know_ that 256 instruction times have passed since the last time this happened - except on the larger PICs which can be set to have this count up to 65536). This then gives you a counter that is independant of the code.

Best Wishes
digitalfreak



Joined: 16 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Wed Feb 15, 2006 12:55 pm     Reply with quote

thx 4 ur time. I will try to work on it and post.
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