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

Clock problems with 18F44J11

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



Joined: 14 Mar 2009
Posts: 5
Location: motor city, usa

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

Clock problems with 18F44J11
PostPosted: Mon Nov 15, 2010 3:38 pm     Reply with quote

I have a simple setup with a PIC18F44J11. I am using a 16 mhz crystal and trying to use the processor in HS mode.

The system starts up properly, but all timing functions seem be off by an order of magnitude.

Processor setup is:
Code:

#use delay(clock=16000000)                           // Frequency set at 16Mhz
#fuses HS,NOWDT,NOPROTECT,XINST,STVREN,IESO,NOIOL1WAY
#fuses PRIMARY,NOCPUDIV

#use standard_io(b)
 

my interrupt routine is:
Code:

#int_TIMER3
void  TIMER3_isr(void)       // 10 msec timebase   
{
   set_timer3(15536);
   gClkUpdate = 1;
   g10msTimer1++;
   g10msTimer2++;
}



in main I have:
Code:

setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);              // Set up timer 1 (counter);
set_timer1(0);                          // Reset timer1 counter
setup_timer_3(T3_INTERNAL | T3_DIV_BY_8);
set_timer3(15536);
enable_interrupts(INT_TIMER3);
enable_interrupts(GLOBAL);

As I understand it, the timer input is OSC/4, so the input to Timer3 is 4,000,000 hz, which divided by 8 would be a count rate of 500Khz. Timer3 then counts 50,000, (from 15536 to rollover, 0000).

Instead, it is almost 20 seconds between interrupts and I haven't a clue as to why this is.

Any help would be greatly appreciated.

thanx in advance..... mark
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 15, 2010 3:43 pm     Reply with quote

Quote:
#use delay(clock=16000000) // Frequency set at 16Mhz
#fuses HS,NOWDT,NOPROTECT,XINST,STVREN,IESO,NOIOL1WAY
#fuses PRIMARY,NOCPUDIV

#use standard_io(b)

The extended instruction set is not supported by CCS. Using it will result
in erratic program operation. Change the fuse to NOXINST.
fredmatic



Joined: 14 Mar 2009
Posts: 5
Location: motor city, usa

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

PostPosted: Mon Nov 15, 2010 4:18 pm     Reply with quote

I changed the fuse and no change. I am kinda going crazy on this one.

With the fuse selections, I should have the HS/16mhz selected, right?

I have been programming the PIC3, dsPIC33' and PIC24F's for seven years and this is the first venture into the PIC18's.

Oh well, gotta keep trying. Thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 15, 2010 5:28 pm     Reply with quote

This works. This provides a 5 Hz signal on Pin C4, which is correct.
I don't have an 18F44J11 but I have a PIC in the same family. I tested
this program with compiler vs. 4.114. If it doesn't work, make sure you
really have a 16 MHz crystal installed, and also make sure it's really
running at 16 MHz. When I was testing this, I accidently had a 4 MHz
crystal installed and it made me wonder what was happening for a while.
Then I fixed it and it started running correctly.
Code:

#include <18F24J11.h>
#fuses HS,NOWDT
#use delay(clock=16000000)

#int_TIMER3
void  TIMER3_isr(void)       
{
set_timer3(15536);

output_toggle(PIN_C4);
}

//====================================
void main()
{
setup_timer_3(T3_INTERNAL | T3_DIV_BY_8);

set_timer3(15536);
enable_interrupts(INT_TIMER3);
enable_interrupts(GLOBAL);

while(1);
}
fredmatic



Joined: 14 Mar 2009
Posts: 5
Location: motor city, usa

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

PostPosted: Mon Nov 15, 2010 5:53 pm     Reply with quote

I'll give it a try. The 24J11 is the same processor, just a wee bit less memory.....ok, no PMP or deep sleep, but I don't use those anyhow.

I'll give it a try....

thanx
fredmatic



Joined: 14 Mar 2009
Posts: 5
Location: motor city, usa

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

PostPosted: Mon Nov 15, 2010 5:57 pm     Reply with quote

Actually, that should give you a 10Hz output....just remember, the your LED is 0.1 on, 0.1 off.

mark Shocked
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 15, 2010 6:16 pm     Reply with quote

With a 16 MHz oscillator, the instruction clock is 4 MHz. The Timer3
prescaler reduces that to 500 KHz. Then Timer3 is preset to 15536,
so it counts 50K clocks before it rolls over and generates an interrupt.
So 500 KHz / 50K = 10 Hz interrupt rate. I'm toggling pin C4 in the isr,
so the frequency of output waveform will be 10 Hz / 2 = 5 Hz. It only
generates 1/2 cycle of the output waveform per interrupt.
fredmatic



Joined: 14 Mar 2009
Posts: 5
Location: motor city, usa

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

PostPosted: Mon Nov 15, 2010 8:04 pm     Reply with quote

you're right...thanx
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