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 CCS Technical Support

Not correct delay with delay_ms

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



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

Not correct delay with delay_ms
PostPosted: Wed Jun 07, 2006 3:51 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 07, 2006 4:14 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 07, 2006 4:35 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 07, 2006 7:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 07, 2006 7:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 07, 2006 7:22 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 07, 2006 8:33 pm     Reply with quote

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 Smile
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 07, 2006 8:34 pm     Reply with quote

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!
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