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

Varying delay longer than 255?

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







Varying delay longer than 255?
PostPosted: Mon Dec 30, 2002 5:46 pm     Reply with quote

I am trying to create a simple LED flasher that starts slow and increments each second, from a rate of 1HZ up to a rate of 5Hz, but I'd like a small step size. Ideally I am trying to increment the rate 50ms each loop, and have it flash at that rate for 10 seconds.

More specifically,

1. Start flashing at 1 Hz (1000ms on/1000ms off) for 10 seconds, or 10000ms.

2. Increase the period by 50ms

3. Flash at the new period, 1050ms on/1050ms off) for 10 seconds.

4. Increase the period by 50ms

5. Continue...

The problem I'm having is that I'm not sure how to work around the 0-255 variable constraint. How can I get a value of 1000, 1050, 1100, etc to delay_ms in order to accomplish this?

I'm currently using 2 for loops, and using the loop counter as my variable, but obviously that doesn't work.

Can anyone suggest some code as a workaround or direct me towards a manual page or other resource that might help me find the answer?

Thanks very much.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10342
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Varying delay longer than 255?
PostPosted: Mon Dec 30, 2002 6:48 pm     Reply with quote

:=The problem I'm having is that I'm not sure how to work around the 0-255 variable constraint. How can I get a value of 1000, 1050, 1100, etc to delay_ms in order to accomplish this?
:=
----------------------------------------------------------
Here is a demo program. The delay function can
accept a variable with a value of 1 to 65536.
This gives a maximum delay of 65.5 seconds.

Code:

#include "c:\program files\picc\devices\16F877.h"
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT, NOLVP
#use Delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)


void long_delay_ms(long count);

//=============================
void main()
{

printf("Start\n\r");

long_delay_ms(30000);

printf("Done\n\r");


while(1);
}
//=============================

void long_delay_ms(long count)
{
long k;

for(k = 0; k < count; k++)
    delay_ms(1);
}



----
Edited to put code in a code block.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10345


Last edited by PCM programmer on Sun Feb 15, 2009 12:30 pm; edited 1 time in total
anestho



Joined: 27 Dec 2006
Posts: 28

View user's profile Send private message

PostPosted: Wed Sep 19, 2007 8:48 pm     Reply with quote

I tried using this routine with delay_us instead, but it doesn't work.

Code:
void long_delay_us(long count)
{
   long k;
   for(k = 0; k < count; k++)
      {
   delay_us(1);
      }   
}


Is there any other way to generate 0 to 8000 in 1us increments? I will be using a int16 as the variable.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 19, 2007 8:54 pm     Reply with quote

If you have version 4 of the compiler, it's already built-in.

If you have version 3 or before, then use the forum's search engine
to find the "long_delay_us()" routine. Here is a link:
http://www.ccsinfo.com/forum/viewtopic.php?t=29746&start=1
anestho



Joined: 27 Dec 2006
Posts: 28

View user's profile Send private message

PostPosted: Wed Sep 19, 2007 9:03 pm     Reply with quote

I have version 3.249. I need 1 us increments or at least 4 us increments from 1000 to 2000 using a variable.

Your code for long_delay_us increments in 253 us and is used to generate delays in ms.

Any other ideas?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 19, 2007 9:13 pm     Reply with quote

No, that's not true. It delays in increments of 1 us.

The "253" value that you see, is actually used in a loop that delays in
increments of 256 us. This takes care of any portion of the delay that
is larger than 255 us. The CCS delay_us() routine is used for the
remainder of the delay (values of 255 us or less). The value of 253 is
used because the loop code itself takes about 3 us, at the oscillator
frequency that was used in that test program.


For people who have vs. 4.xxx of the compiler, you do not need this
routine. The delay_us() routine can handle values of up to 65535 as
either a constant or a variable parameter.
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