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

Oscillator and timer interference

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



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

Oscillator and timer interference
PostPosted: Wed Nov 03, 2021 4:48 am     Reply with quote

Hello friends, since I just started CCS, I have a series of problems with it.
I just wrote a program in which I used Timer0 and Timer1.
And I called the commands related to the timer and got the numbers according to the formula calculations of the timer.
But because I also need to use an oscillator, when I add this command to the code:
Code:
setup_oscillator (OSC_8MHZ | OSC_PLL_on);
everything becomes faster and the previous calculations of the timer formula are no longer correct.
and when i remove this command from the code every thing is good.
I wanted to see if anyone knows why?

What i used in main
Code:

Setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);                       
enable_interrupts(INT_TIMER0);                                 
 
setup_timer_1(T1_internal | T1_DIV_BY_8);                   
//setup_oscillator(OSC_8MHZ | OSC_PLL_on);       // <===the problem is here     

enable_interrupts(GLOBAL); 

 // for adc use
setup_vref(VREF_ADC_1v024);                       
setup_adc_ports(sAN7|sAN9 , VREF_FVR);
setup_adc(ADC_CLOCK_DIV_64);           
setup_adc_ports(sAN7|sAN9);
 
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 5:36 am     Reply with quote

You need to tell us which PIC you're using and the compiler version !
Also your original program clock configuration.
GiG



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 5:43 am     Reply with quote

#include <16f1939.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,PLL_SW,NOMCLR,NOBROWNOUT,PUT
#device ADC=10
#use delay(internal=8000000)
#INCLUDE <math.h>

this is config
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 6:10 am     Reply with quote

It's clear that you want the PIC to run at 8 MHz. But then you're turning
on the PLL which makes it run 4x faster, at 32 MHz. If you don't want
that, then don't turn on the PLL.
GiG



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 7:10 am     Reply with quote

PCM programmer wrote:
It's clear that you want the PIC to run at 8 MHz. But then you're turning
on the PLL which makes it run 4x faster, at 32 MHz. If you don't want
that, then don't turn on the PLL.



i don't understand why ? when im using this command
setup_oscillator(OSC_8MHZ | OSC_PLL_on);
i put the osc on 8 mhz
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 7:26 am     Reply with quote

The point is what you do in your code, overrides what you do in the setup.
The code line:

setup_oscillator (OSC_8MHZ | OSC_PLL_on);

says to run the oscillator at 8MHz, _and enable the PLL to give 32MHz_.

You are overriding the OSC_8MHz setup by then enabling the PLL.
The 8MHz clock does not use the PLL.....
GiG



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 9:33 am     Reply with quote

Ttelmah wrote:
The point is what you do in your code, overrides what you do in the setup.
The code line:

setup_oscillator (OSC_8MHZ | OSC_PLL_on);

says to run the oscillator at 8MHz, _and enable the PLL to give 32MHz_.

You are overriding the OSC_8MHz setup by then enabling the PLL.
The 8MHz clock does not use the PLL.....



So you mean when i calculate timer0 formula
I should use 32MHZ instead of 8mhz in calculating?!
And if i do it right
Is there anything wrong with the timer calculations?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 10:02 am     Reply with quote

I mean if you want to run at 8MHz, then the line is simply:

setup_oscillator (OSC_8MHZ);

To run at 8MHz, you don't enable the PLL.
GiG



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 2:25 pm     Reply with quote

Ttelmah wrote:
I mean if you want to run at 8MHz, then the line is simply:

setup_oscillator (OSC_8MHZ);

To run at 8MHz, you don't enable the PLL.



Thank you

But ok PLL puts the clock on 32Mhz.
What about that 8mhz before it ?!
For what we have that command before PLL command?
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Wed Nov 03, 2021 2:37 pm     Reply with quote

If you use #use delay(internal=8000000) then there is no reason to use the setup_oscillator command unless you are trying to change it to something different.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Nov 04, 2021 12:48 am     Reply with quote

'setup_oscillator' is the command.

The values passed to it are the 'parameters', saying what you want to set
it 'to'.
Now, the PLL can be fed from either the 8MHz oscillator, or any external
frequency using the LP, XT, HS RX or EC oscillators.
So there are two parts to the setting. The first saying 'what clock source',
and the second saying whether to enable the PLL or not.
If you enable the PLL with a legitimate clock source, then the output
frequency fed to the CPU is 4* the clock frequency.

So your command was saying 'select the 8MHz clock, then multiply this by
four'.
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Thu Nov 04, 2021 6:25 am     Reply with quote

This is also clear if you look at the data sheet. The PLL can only accept a 4MHz - 8MHz input and generate a 16MHz - 32MHz output. When used with the internal oscillator, only the 8MHz can be connected to the PLL, producing a 32MHz clock for the processor.
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