Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Oscillator use (internal or external) in MikroC

Status
Not open for further replies.

shahbaz.ele

Advanced Member level 1
Advanced Member level 1
Joined
Aug 12, 2008
Messages
454
Helped
72
Reputation
146
Reaction score
73
Trophy points
1,308
Location
Islamabad, Pakistan
Activity points
3,669
dear all
I am using MikoC to program PIC18F4520.
The proble is that my program is working in Proteus.
but not working in hardware.
Hardware is tested for other programs means ok.

My question is that how to define that I am using Internal oscillator or External oscillator.
 

I am using MikroC 8.2V
I want to use 16MHz crystal Oscillator externally.
If there is option for internal crystal as 16MHz
 

Internal oscillator is RC rather than crystal oscillator, you should check if the accuracy is sufficient for your purposes. 16 MHz operation with internal oscillator is possible.

Read the datasheet, particularly section PLL IN INTOSC MODES.
 

how to set the parameters in MikroC is the problem.
My code is working in proteus simulation but not working in Hardware(actual).
 

hi
yes you can use internal oscillator for that need to declare fuse bits for example
#FUSES INTRC // setup internal oscillator or INTRC_OSC_NOCLKOUT -> no clock out
 

Try these.

Code:
OSCCON = 0b11100111;
OSCTUNE = 0b01000000;

In Project Properties for Oscillator type select INTOSC or INTIO. It gives 4 MHz x 4 (4x PLL) = 16 Mhz (Internal Oscillator).
 
Thank you @ Okada
I will try this then discuss here in 10 minutes.

- - - Updated - - -

My circuit is working fine now.
what will be the method of testing the clock frequency.
I observed 1MHz at OSC (RA7) pin of uc.

- - - Updated - - -

should it be 4MHz as I think this frequency is Fosc/4 ?
 

In the configuration that Okada recommended (FOSC bits as either INTIO or INTOSC) RA7 is set to be a normal IP pin - see the data sheet, Register 23-1 CONFIG1H.
Given that you should be able to work out how to get the CLKO signal onto a pin.
Susan
 

you can check the Frequency @ pin RA7 or RA6. it should be Frequency/16 for your settings i.e., it should be 1MHz.
Otherwise use clk=clock_MHz(); built in command and display this command on LCD or somewhere through RS232.
 
Thank you all
specially Okada, great_electron.
My frequency is set to 16MHz using internal oscillator and I have displayed it on LCD using built-in command clock_MHz();
The problem is solved.
 

By the way, I found this in reference to the 'clock_MHz function at https://forum.mikroe.com/viewtopic.php?f=88&t=54510&view=previous#p213789.
Mark- wrote:
No. If PLL is enabled the clock is 4X the setting.

The thing you seem not to realise is that compiler knows only the setting one puts in the MCU Clock field. As long as the frequency given is the effective one, it does not matter to the compiler whether PLL is on or a four times faster crystal is used.

Quote:
So really, Clock_Mhz only returns the setting not the actual FOSC.

Right. Clock_Mhz returns what one puts in MCU Clock field, which in turn should be the effective clock frequency or compiler will wrongly calculate time constants or UART baud rate.
So you may only be seeing what you told the IDE/Compiler, not what the actual clock rate is.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top