PIC16F1788 - Internal Oscillator Speed

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

PIC16F1788 - Internal Oscillator Speed

Post by Frank607 »

I don’t understand something with the internal clock speed of this PIC16F1788. (and maybe others)

The datasheet of this PIC says that this PIC has an Internal 32MHz Oscillator.

I have made a simple Flowcode with a blinking LED, 1 second On and 1 second Off. According to this topic I must set the OSCCON value to 0xF0 for a 32MHz Oscillator.
viewtopic.php?f=26&t=20174&p=88850&hili ... con#p88850 (end)

When I set this OSCCON=0xF0 value than the LED blinks too fast. How is this possible?

When I change this OSSCON value to 0x78 (16MHz) than it looks that the LED is blinking 1 second on and 1 second Off.

How can I know what OSCCON value is good for this PIC?

Attached is the simple Flowcode. Maybe there is something else what I must change / configure in the Chip Options. I don’t know if I have the right options selected.

Thanks for helping me out.

Frank
Led Blink - PIC16F1788.fcfx
(7.9 KiB) Downloaded 235 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1788 - Internal Oscillator Speed

Post by QMESAR »

Hi.
Looking at the datasheet the device does not have an 32Mhz Internal Oscillator only a a 31Khz ?
maybe I misunderstood your problem
The device can be clocked with a maximum of 32MHZ with an external clock source (including the 4xPLL) it does not have a 32MHZ OSC internal the options are as shown in the marked block
1.jpg
1.jpg (145.83 KiB) Viewed 4416 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC16F1788 - Internal Oscillator Speed

Post by medelec35 »

Hi Frank,
If

Code: Select all

OSCCON=0x78;
then internal osc will only run at 32MHz if PLL is enabled within configuration settings.
If

Code: Select all

OSCCON=0xF0;
then internal osc will run at 32MHz whether PLL is enabled or disabled within configuration settings.

Your LED was going fast because the internal osc was running at 32MHz since

Code: Select all

OSCCON=0xF0;
PLL is disabled and you had the clock speed in General tab left at the default 19660800Hz
Therefore your delays are too short for the 32MHz internal osc.
The Clock speed in general options must match the osc speed of microcontroller.
QMESAR wrote: The device can be clocked with a maximum of 32MHZ with an external clock source (including the 4xPLL) it does not have a 32MHZ OSC internal the options are as shown in the marked block
Sorry I don't agree with that.

You can set the internal osc at any of the speeds shown on the datasheet for given OSCCON value.
An external clock is not required.

Martin
Martin

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1788 - Internal Oscillator Speed

Post by QMESAR »

medelec35 wrote:You can set the internal osc at any of the speeds shown on the datasheet for given OSCCON value.
An external clock is not required.
Martin you are correct looking more closely at the OSC it true what you said ,I missed the path from the Internal OSC MUX to the PLL

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: PIC16F1788 - Internal Oscillator Speed

Post by Frank607 »

Many thanks to try to help. As always I appreciated this !!

I have tested with a scope the total On / Off cycles. On – Off to On. This must be 2 seconds in total.

If I set the Value to OSCCON=0x70 (8MHz) then the cycles will be 4.900 sec
If I set the Value to OSCCON=0x78 (16MHz) then the cycles will be 2.440 sec

So how can I calculate what is the perfect OSCCON value to let run this chip with exact time ?
medelec35 wrote:... and you had the clock speed in General tab left at the default 19660800Hz
Therefore your delays are too short for the 32MHz internal osc.
The Clock speed in general options must match the osc speed of microcontroller.
Martin
- (in a other topic I have read that this settings are only for simulation speed, so I have leaved it on standard)
hackinblack wrote:PIC Clocks In FlowCode
The clock speed settings selected inside 'Build>Project>Options'
only tell Flowcode what speed the oscillator is set to for simulation...
They do NOT set up the oscillator in the PIC's hardware! so if you are NOT using the default setting...
This was the solution :-) Thanks Martin.
I have now set OSCCON=0x78 (16MHz) and in General Options, Clock speed (Hz) 16000000

Now on the scope the cycles are perfect at 2.000 sec :-) So now I know that this chip and program are running “on time” and now I can go on with programing the EEPROM :-( :-)
( viewtopic.php?f=63&t=20241 )

-------------

@Martin, have you looked to the other settings in the Chip Options? Are they all good?

Frank

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC16F1788 - Internal Oscillator Speed

Post by medelec35 »

Hi Frank,
Frank607 wrote:(in a other topic I have read that this settings are only for simulation speed, so I have leaved it on standard)
That is wrong, the clock speed is NOT for simulation only!
I explained about that here.
The reason for the correct delays is the microcontroller is running at 16MHz (not 32MHz).
As the clock speed is set for 16MHz the microcontroller speed, and the clock speed now match up.
However you wanted the speed to be 32MHz.
If you refer back to my post, you will see you need to set the clock speed to 32000000, that is essential!
Then you either can:
1) Set

Code: Select all

OSCCON to 0xF0
and does not matter if you enable PLL or not as it will be ignored with that OSCCON value.
Or
2) Set

Code: Select all

OSCCON to 0x78
then you must enable PLL within configuration settings as it is now looked at with OSCCON set to 0x78.
Don't leave the clock at 19.66 MHz if the clock of microcontroller is not running at that frequency.
They must match or any components will fail to work as stated in the post link is pointing to.

Martin
Martin

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: PIC16F1788 - Internal Oscillator Speed

Post by Frank607 »

Hi Martin,

Thanks for this explanation.

Post Reply