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 CCS Technical Support

Delay in uS

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



Joined: 18 Feb 2008
Posts: 11

View user's profile Send private message

Delay in uS
PostPosted: Fri Feb 29, 2008 8:57 pm     Reply with quote

Hi
its me
again I know

I got some probly with delay_us

while(TRUE) //Main Loop
{
if(k==200)
{
output_toggle(PIN_A4);
k=0;
}
k++;
delay_us(500);
}

and

while(TRUE) //Main Loop
{
if(k==400)
{
output_toggle(PIN_A4);
k=0;
}
k++;
delay_us(250);
}


should be the same right?
first one the led if flashing at right speed
but second one too much fast what is happening there?

should I use a timer to do this?
bwhiten



Joined: 26 Nov 2003
Posts: 151
Location: Grayson, GA

View user's profile Send private message

PostPosted: Fri Feb 29, 2008 9:32 pm     Reply with quote

What type is "k"?
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Sat Mar 01, 2008 4:40 am     Reply with quote

Hi JulsPower,

I don't now what is the problem, maybe the type of k like suggested by bwhiten, but in every case it will be better for you to use a timer.
Your micro is spending is time in the "delay_us" function. It won't be able to do anything else...

Franck.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Delay in uS
PostPosted: Sat Mar 01, 2008 6:41 am     Reply with quote

JulsPower wrote:

if(k==200)
and
if(k==400)
should be the same right?


In case you haven't figured out why bwhiten and Franck26 are so concerned with the type of 'k', it is that if k is an 8-bit int, it cannot ever be equal to 400. However, the compiler makes a stupid assumption. It assumes that all you want to do is compare k with the low byte of 400 (which is 144). Therefore (k==400) is the same as (k==144). That would explain the second loop being a lot faster.

Robert Scott
Real-Time Specialties
JulsPower



Joined: 18 Feb 2008
Posts: 11

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 8:12 pm     Reply with quote

ooh you are all right
it was a int
but i already made it with a timer
and soon with int
Guest








PostPosted: Wed Mar 05, 2008 4:40 pm     Reply with quote

JulsPower wrote:
ooh you are all right
it was a int
but i already made it with a timer
and soon with int


Is this a haiku?
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