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

delay_us( B * {period})

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







delay_us( B * {period})
PostPosted: Mon Nov 26, 2001 1:14 pm     Reply with quote

For a situation like below,

for (...)
{
some lines of code...
specific event_D
delay_us( A - B*C);

some more lines of code..
}

A = known amount of time, say 60 us.
B = total_clks(for some lines of code) ie a number that I manually put in.
C = Period (which is my osc/8)

Is there a way to 'call-in' the period. So that later on, should I decide to use a different value in the #use delay() that the delay will be calculated right? I want to do this because I want to keep the time between 'specific event_d' constant.

Joe
___________________________
This message was ported from CCS's old forum
Original Post ID: 1324
Tomi
Guest







Re: delay_us( B * {period})
PostPosted: Tue Nov 27, 2001 11:10 am     Reply with quote

Maybe you are about "calculated delay". You can enter a 8-bit variable for the delay_us() and delay_ms() functions (16-bit integers are supported only as const). So you can use something like this:

char i,myvar;
i = 10;
myvar = 60 - 2*i;
delay_us(myvar);


:=For a situation like below,
:=
:=for (...)
:={
:=some lines of code...
:=specific event_D
:=delay_us( A - B*C);
:=
:=some more lines of code..
:=}
:=
:=A = known amount of time, say 60 us.
:=B = total_clks(for some lines of code) ie a number that I manually put in.
:=C = Period (which is my osc/8)
:=
:=Is there a way to 'call-in' the period. So that later on, should I decide to use a different value in the #use delay() that the delay will be calculated right? I want to do this because I want to keep the time between 'specific event_d' constant.
:=
:=Joe
___________________________
This message was ported from CCS's old forum
Original Post ID: 1341
Joe Heinrich
Guest







Re: delay_us( B * {period})
PostPosted: Tue Nov 27, 2001 11:45 am     Reply with quote

that is closer to what I want. Can I do something like this?

...
#define freq = 2457600;
#use_delay(freq);
...
float i; // WILL this work?
i = 1/(freq/8);
myvar = 60 - 2 *i;
...

Joe


:=Maybe you are about "calculated delay". You can enter a 8-bit variable for the delay_us() and delay_ms() functions (16-bit integers are supported only as const). So you can use something like this:
:=
:=char i,myvar;
:=i = 10;
:=myvar = 60 - 2*i;
:=delay_us(myvar);
:=
:=
:=:=For a situation like below,
:=:=
:=:=for (...)
:=:={
:=:=some lines of code...
:=:=specific event_D
:=:=delay_us( A - B*C);
:=:=
:=:=some more lines of code..
:=:=}
:=:=
:=:=A = known amount of time, say 60 us.
:=:=B = total_clks(for some lines of code) ie a number that I manually put in.
:=:=C = Period (which is my osc/8)
:=:=
:=:=Is there a way to 'call-in' the period. So that later on, should I decide to use a different value in the #use delay() that the delay will be calculated right? I want to do this because I want to keep the time between 'specific event_d' constant.
:=:=
:=:=Joe
___________________________
This message was ported from CCS's old forum
Original Post ID: 1342
Tomi
Guest







Re: delay_us( B * {period})
PostPosted: Tue Nov 27, 2001 12:07 pm     Reply with quote

No. Keep in mind that the arithmetic calculation needs time.
The floating point calculation needs lot of time. You can make 255usec max. with delay_us(var) and your floating point calc. needs approx. 1-2 msec.
Plus you have some syntax errors. Correct:
#define freq 2457600 // no semicolon. It is a #define statment
#use delay(freq) // no semicolon. It is a compiler statement

If I strongly understand your expression "1/(freq/8)" is constant.
However, if you want to use calculated delay then it would be better to use a simple integer arithmetics, e.g.:
The "8/freq" is 3.2552 usec. For more prec. use a 16-bit variable what is 256*(8/freq) what is 833. Use a simple calculation, then use the HIGH byte of the result as input parameter for the delay_us() call (this is the "value/256"), e.g.:
int16 myvar,inttime;
#byte myvarH = myvar+1
inttime = 833;
myvar = 15360 - 2 *inttime; // 15360 = 60*256
delay_us(myvarH);


:=that is closer to what I want. Can I do something like this?
:=
:=...
:=#define freq = 2457600;
:=#use_delay(freq);
:=...
:=float i; // WILL this work?
:=i = 1/(freq/8);
:=myvar = 60 - 2 *i;
:=...
:=
:=Joe
:=
:=
:=:=Maybe you are about "calculated delay". You can enter a 8-bit variable for the delay_us() and delay_ms() functions (16-bit integers are supported only as const). So you can use something like this:
:=:=
:=:=char i,myvar;
:=:=i = 10;
:=:=myvar = 60 - 2*i;
:=:=delay_us(myvar);
:=:=
:=:=
:=:=:=For a situation like below,
:=:=:=
:=:=:=for (...)
:=:=:={
:=:=:=some lines of code...
:=:=:=specific event_D
:=:=:=delay_us( A - B*C);
:=:=:=
:=:=:=some more lines of code..
:=:=:=}
:=:=:=
:=:=:=A = known amount of time, say 60 us.
:=:=:=B = total_clks(for some lines of code) ie a number that I manually put in.
:=:=:=C = Period (which is my osc/8)
:=:=:=
:=:=:=Is there a way to 'call-in' the period. So that later on, should I decide to use a different value in the #use delay() that the delay will be calculated right? I want to do this because I want to keep the time between 'specific event_d' constant.
:=:=:=
:=:=:=Joe
___________________________
This message was ported from CCS's old forum
Original Post ID: 1344
Joe Heinrich
Guest







Re: delay_us( B * {period})
PostPosted: Tue Nov 27, 2001 1:26 pm     Reply with quote

What I intended is for 'myvar' to be a constant value for a given oscialator. And I see making 'i' an variable is not what I meant to do. The only time I would ever want 'myvar' to change would be when I enter a different osciallator value. So 'myvar' would be calculated at compile time ONLY. (For this intended use.)

But you have brought to my attention the fact that the delay_us() can have a variable value to it. A feature I was not aware of... Thanks.


:=No. Keep in mind that the arithmetic calculation needs time.
:=The floating point calculation needs lot of time. You can make 255usec max. with delay_us(var) and your floating point calc. needs approx. 1-2 msec.
:=Plus you have some syntax errors. Correct:
:=#define freq 2457600 // no semicolon. It is a #define statment
:=#use delay(freq) // no semicolon. It is a compiler statement
:=
:=If I strongly understand your expression "1/(freq/8)" is constant.
:=However, if you want to use calculated delay then it would be better to use a simple integer arithmetics, e.g.:
:=The "8/freq" is 3.2552 usec. For more prec. use a 16-bit variable what is 256*(8/freq) what is 833. Use a simple calculation, then use the HIGH byte of the result as input parameter for the delay_us() call (this is the "value/256"), e.g.:
:=int16 myvar,inttime;
:=#byte myvarH = myvar+1
:=inttime = 833;
:=myvar = 15360 - 2 *inttime; // 15360 = 60*256
:=delay_us(myvarH);
:=
:=
:=:=that is closer to what I want. Can I do something like this?
:=:=
:=:=...
:=:=#define freq = 2457600;
:=:=#use_delay(freq);
:=:=...
:=:=float i; // WILL this work?
:=:=i = 1/(freq/8);
:=:=myvar = 60 - 2 *i;
:=:=...
:=:=
:=:=Joe
:=:=
:=:=
:=:=:=Maybe you are about "calculated delay". You can enter a 8-bit variable for the delay_us() and delay_ms() functions (16-bit integers are supported only as const). So you can use something like this:
:=:=:=
:=:=:=char i,myvar;
:=:=:=i = 10;
:=:=:=myvar = 60 - 2*i;
:=:=:=delay_us(myvar);
:=:=:=
:=:=:=
:=:=:=:=For a situation like below,
:=:=:=:=
:=:=:=:=for (...)
:=:=:=:={
:=:=:=:=some lines of code...
:=:=:=:=specific event_D
:=:=:=:=delay_us( A - B*C);
:=:=:=:=
:=:=:=:=some more lines of code..
:=:=:=:=}
:=:=:=:=
:=:=:=:=A = known amount of time, say 60 us.
:=:=:=:=B = total_clks(for some lines of code) ie a number that I manually put in.
:=:=:=:=C = Period (which is my osc/8)
:=:=:=:=
:=:=:=:=Is there a way to 'call-in' the period. So that later on, should I decide to use a different value in the #use delay() that the delay will be calculated right? I want to do this because I want to keep the time between 'specific event_d' constant.
:=:=:=:=
:=:=:=:=Joe
___________________________
This message was ported from CCS's old forum
Original Post ID: 1345
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