View previous topic :: View next topic |
Author |
Message |
GSFC PIC
Joined: 05 Apr 2005 Posts: 8
|
Problem With Delay_ms(xxxx); Function |
Posted: Fri Dec 16, 2005 2:29 pm |
|
|
Good afternoon PIC masters !
I am having a problem with delay_ms function. When I changed the
configuration command line #use delay(clock=xxxxx) it will effect my delay_ms(xxx) function. For example
With the #use delay(clock=4000000) configured, when I want a 1 sec delay I used command delay_ms(1000); but the delay time is only half a second instead of a full second, but when I changed my #use delay(clock=8000000) then I got the full 1 second delay as expected. The crystal oscillator Im using is 4 mhz crystal. So please ! explain to me the function relationship between these commands line (#use delay(clock=xxxx) and delay_ms(xxxx) ) when such a crystal oscillator ( 4 mhz) is used. Thank you so much for your advice
Happy Holidays
regards |
|
|
Storic
Joined: 03 Dec 2005 Posts: 182 Location: Australia SA
|
|
Posted: Fri Dec 16, 2005 2:43 pm |
|
|
I dont know if this will help, is the PIC you as using have an internal OSC (8mg), if so has it been unintentialy enabled. When I first started using CCS software, at first could not get the PIC to work on the internal OSC. I had "setup_oscillator(OSC_8MHZ|OSC_NORMAL);" this line in and it did not work, I ended up taking it out and by default it worked. the PIC I was using was the 18F1320. _________________ What has been learnt if you make the same mistake? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 16, 2005 2:43 pm |
|
|
The value in the #use delay(clock= ) statement must match the
frequency of your crystal or oscillator (unless you're using 4x PLL mode).
Post the #include statement for your PIC, and also post the #fuses
and the #use delay statements.
Also post your compiler version. |
|
|
GSFC PIC
Joined: 05 Apr 2005 Posts: 8
|
|
Posted: Tue Dec 20, 2005 2:51 pm |
|
|
Thanks PCM Programmer,
I removed the crystal oscillator and have it checked. It was malfunctioned, it only outputs about 5 Mhz something, I installed another crystal oscillator ( 8 mhz) and recompiled the program with #use delay(clock=8000000); this time, I got exactly 1 sec delay as expected- delay_ms(1000); I learnt one thing from this problem is even with the correct 8 mhz crystal oscillator installed, if I specify the #use delay(clock=4000000); I will get only half a second instead of a full second delay when the delay_ms(1000); statement is issued. Thanks again for coming to the rescue ...
Regards,
GSFC PIC |
|
|
|