View previous topic :: View next topic |
Author |
Message |
Fabri
Joined: 22 Aug 2005 Posts: 275
|
delay_us() |
Posted: Wed Nov 23, 2005 9:38 am |
|
|
Hi Everybody,
In my application I use delay_us(9000) to have an delay of 9ms. And Work right.
I change so:
Quote: |
int16 m;
m=9000; // 0x2328
delay_us(m);
|
In this case the delay is not 9ms but only 45us. I verified so with oscilloscope in debug mode.
My compiler Version is. 3.235 with PIC16F876A
what are you think about? |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Wed Nov 23, 2005 9:57 am |
|
|
I think you should read the compilor manual. You can use DELAY_US() with a constant up to 65535 OR a variable up to 255. That's why delay_us(9000) worked and delay_us(m) did not. _________________ David |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Nov 23, 2005 10:00 am |
|
|
Is there any way to use 16 bit variable in delay_us() ?
I need the maximal resolution.
Regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Wed Nov 23, 2005 10:15 am |
|
|
Here's one way.
Code: |
int8 i;
int8 resolution;
resolution = 100; // adjust this number
for (i = 90;i > 0;i--)
delay_us(resolution);
|
Adjust 'resolution' to compensate for the time it takes
to execute the for loop. _________________ David |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Nov 23, 2005 10:29 am |
|
|
Thanks for support,
I decided to use Timer1 whith his 16 bits of resolution. After reset it I stay in loop till became the same or more than my variable.
By the way, in other routine I use timer1 to mesure frequency of some waves.
Regards, |
|
|
|