View previous topic :: View next topic |
Author |
Message |
Graham Webb
Joined: 18 Apr 2008 Posts: 9
|
delayus() |
Posted: Tue May 18, 2010 4:51 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Tue May 18, 2010 6:02 am |
|
|
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!!!! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue May 18, 2010 3:16 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Graham Webb
Joined: 18 Apr 2008 Posts: 9
|
|
Posted: Thu May 20, 2010 3:00 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|