View previous topic :: View next topic |
Author |
Message |
prayami
Joined: 22 Dec 2004 Posts: 78
|
Not correct delay with delay_ms |
Posted: Wed Jun 07, 2006 3:51 pm |
|
|
Hi...
I am using 18F24J10, "CCS PCH C Compiler, Version 3.249" and
MPLAB IDE version 7.4 .
I am running the following simple program using software PLL. But
delay_ms is not correct. As my delay_ms(100) but the pulses are
remain high and low every time for 400ms.
I am using 10Mhz crystal with software PLL enabled.
If I do not use PLL and just work for 10Mhz then it is correct. I tried
changing different #fuses but no progress.
Thanks..in advance....
Code: |
#include <18F24J10.h>
#fuses PRIMARY, H4_SW,NOSTVREN,PROTECT,NOFCMEN,NOFCMEN,NOIESO, NOWDT
#use delay(clock=40000000)
//Below work correct for 10Mhz
//#fuses NOWDT,HS,NOSTVREN,PROTECT,NOFCMEN,NOFCMEN,NOIESO
//#use delay(clock=10000000)
void Init_Setting()
{
//setup_oscillator(OSC_STATE_EXT_RUNNING, OSC_NORMAL);
delay_ms(10);
set_tris_a(0xFF);
set_tris_c(0x00);
set_tris_b(0x00);
delay_ms(10);
}//Init_Setting
void main() {
Init_Setting();
while(TRUE) {
output_high(PIN_B5);
delay_ms(100);
output_low(PIN_B5);
delay_ms(100);
}//while(TRUE)
}//main
|
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Jun 07, 2006 4:14 pm |
|
|
If your time is 4 times too long it could be that your clock is 4 times too slow.
What I mean is your PLL isn't working. Did you know that you have to power cycle the PIC to get the PLL to work? |
|
|
prayami
Joined: 22 Dec 2004 Posts: 78
|
|
Posted: Wed Jun 07, 2006 4:35 pm |
|
|
Thanks...for reply....
I have set the thing in the configuration bits for PLL. Which is there in
#fuses .
I tried to turn the power off and stay for a while more than a minute and then ON again to reset but no difference.
I can't understand, why PLL is not working..... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jun 07, 2006 7:10 pm |
|
|
If it is a software controlled PLL then you have to turn it on. The datasheet says to set the PLLEN bit in the OSCTUNE register.
Code: |
#include <18F24J10.h>
#fuses PRIMARY, H4_SW,NOSTVREN,PROTECT,NOFCMEN,NOFCMEN,NOIESO, NOWDT
#use delay(clock=40000000)
#byte OSCTUNE = 0xF9B
void Init_Setting()
{
OSCTUNE = 0x40;
delay_ms(10);
set_tris_a(0xFF);
set_tris_c(0x00);
set_tris_b(0x00);
delay_ms(10);
}//Init_Setting
void main() {
Init_Setting();
while(TRUE) {
output_high(PIN_B5);
delay_ms(100);
output_low(PIN_B5);
delay_ms(100);
}//while(TRUE)
}//main
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 07, 2006 7:16 pm |
|
|
Quote: | I can't understand, why PLL is not working..... |
The 18F24J10 data sheet says in section 2.4 that:
Quote: | The PLL is enabled by setting the PLLEN in the OSCTUNE register. |
However, the data sheet doesn't give the address of the OSCTUNE
register. So if you look in the P18F24J10.inc file, which is in this folder,
c:\Program Files\Microchip\MPASM Suite, then you find the address
is 0xF9B. Then you can set the PLLEN bit with this code:
Code: |
#byte OSCTUNE = 0xF9B
#bit PLLEN = OSCTUNE.6
void main()
{
PLLEN = 1; // Enable PLL
while(1);
} |
|
|
|
prayami
Joined: 22 Dec 2004 Posts: 78
|
|
Posted: Wed Jun 07, 2006 7:22 pm |
|
|
Thats exellent Mark and PCM programmer. Thank you very much.
That works ...
I didn't know that for software controlled PLL require to enable PLL
like this in the program. I thought that, it is all included in the
configuration bits. As first time I come accross this kind of thing.
I was worried that address of OSCTUNE is not there in datasheet but
PCM programmer clear the doubt.
Thanks again.... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jun 07, 2006 8:33 pm |
|
|
PCM programmer wrote: | Quote: | I can't understand, why PLL is not working..... |
The 18F24J10 data sheet says in section 2.4 that:
Quote: | The PLL is enabled by setting the PLLEN in the OSCTUNE register. |
However, the data sheet doesn't give the address of the OSCTUNE
register. So if you look in the P18F24J10.inc file, which is in this folder,
c:\Program Files\Microchip\MPASM Suite, then you find the address
is 0xF9B. Then you can set the PLLEN bit with this code:
Code: |
#byte OSCTUNE = 0xF9B
#bit PLLEN = OSCTUNE.6
void main()
{
PLLEN = 1; // Enable PLL
while(1);
} |
|
That's where I had to find it |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jun 07, 2006 8:34 pm |
|
|
prayami wrote: | Thats exellent Mark and PCM programmer. Thank you very much.
That works ...
I didn't know that for software controlled PLL require to enable PLL
like this in the program. I thought that, it is all included in the
configuration bits. As first time I come accross this kind of thing.
I was worried that address of OSCTUNE is not there in datasheet but
PCM programmer clear the doubt.
Thanks again.... |
I've never used that PIC either. However you mentioned "software PLL" so I read the datasheet to answer your question. Point, read the datasheet! |
|
|
|