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

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







delay with variable
PostPosted: Mon Feb 27, 2006 9:10 am     Reply with quote

hello!

i�m shure it is very simple, but:

why it is not the same?

"delay_ms(1000);"

AND

"
int X;
X=1000;
delay_ms(X);
"

with the first statement the delay is exactly 1second,
but with the second one it is much lower... why?

thanks in advance, christoph
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Mon Feb 27, 2006 9:28 am     Reply with quote

The first is using 1000
the second uses a 1000 stored in a 8 bit variable.
8 bit can at max hold 255.
so
1000=0x3E8 only the E8 is stored
thus e8=232
you get 232mS


CCS int is by default and int8
Christoph
Guest







PostPosted: Mon Feb 27, 2006 9:35 am     Reply with quote

okay, i see...

should it work with an int16?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Mon Feb 27, 2006 9:40 am     Reply with quote

To find the biggest number a variable can hold take 2^n
to 2^16 = 65535 BUT
delay_ms will take an int8 variable.
Thought to look it up after I pressed submit.
edited...
Look to the link of PCM below. It shows the delay_ms inside a wrapper
that executes it multi times and DOES take the int16 variable.


Last edited by treitmey on Mon Feb 27, 2006 9:44 am; edited 3 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 27, 2006 9:41 am     Reply with quote

The delay_ms() function only accepts an 8-bit value when the parameter
is a variable. It can accept a 16-bit constant. To use a 16-bit variable
you need to use a loop. See this thread for an example function:
http://www.ccsinfo.com/forum/viewtopic.php?t=375
Christoph
Guest







PostPosted: Mon Feb 27, 2006 9:47 am     Reply with quote

thank you...

i understand.
but when i�m using int16 it�s also not working.

the delay is still not 1 sec...
Christoph
Guest







PostPosted: Mon Feb 27, 2006 9:50 am     Reply with quote

thank you guys...

i will try!
Guest








PostPosted: Mon Feb 27, 2006 4:22 pm     Reply with quote

Christoph wrote:
thank you guys...

i will try!


Better yet to set up a timer interrupt so that you can track time and not have to block waiting for the delay() call at all.

DLC
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