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

delayus()

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



Joined: 18 Apr 2008
Posts: 9

View user's profile Send private message

delayus()
PostPosted: Tue May 18, 2010 4:51 am     Reply with quote

I am using a PIC16F876A with a 20MHz oscillator and trying to get a controllable pulse with using the delayus() function.
Code:

printf("\t %lx\n\n\r", pulse_width);      
output_high(PIN_B7);   
delay_us(pulse_width);
output_low(PIN_B7);   
delay_us(off_time);

The value in pulse_width displays as a long, but delayus() treats it as a int8. However if I manually put a value in of something larger than 255, 0x200 say, it works!

What have I missed?
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue May 18, 2010 6:02 am     Reply with quote

What version are you using?

Note this from the CCS manual:
Quote:

time - a variable 0-65535(int16) or a constant 0-65535
Note: Previous compiler versions ignored the upper byte of an int16, now the
upper byte affects the time.


I don't know which version fixed this but I believe it was around 4.081 or so.
_________________
Google and Forum Search are some of your best tools!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 18, 2010 12:30 pm     Reply with quote

For earlier versions of the compiler that don't support 16-bit variables
as the parameters in delay_us and delay_ms, see this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=32288
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue May 18, 2010 3:16 pm     Reply with quote

There are a couple of draw backs in using delays in your code. First, everything stops while your code waits for the delay to end. Your processor is just setting there with nothing to do until the delay is done. Second, if you happen to have any interrupts firing away like your serial ISR or any other timer/counter/external interrupt these could lengthen the original delay command.

I would suggest using a timer to control your delay. This way your program isn't 'hung' while they delay times out. Timers can be very precise too. Just a thought.

Ronald
Why can't mosquitos suck fat instead of blood?
Graham Webb



Joined: 18 Apr 2008
Posts: 9

View user's profile Send private message

PostPosted: Thu May 20, 2010 3:00 am     Reply with quote

Thanks all. I believe it was an issue with the version number. I resorted to putting a 1us delay in a for loop, but all my printf statements stopped working with the for loop in play, so I will try the timers.
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