Page 1 of 1

PIC16F1788 - Internal Oscillator Speed

Posted: Thu Jun 28, 2018 2:38 pm
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 301 times

Re: PIC16F1788 - Internal Oscillator Speed

Posted: Thu Jun 28, 2018 3:05 pm
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 5225 times

Re: PIC16F1788 - Internal Oscillator Speed

Posted: Thu Jun 28, 2018 4:24 pm
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

Re: PIC16F1788 - Internal Oscillator Speed

Posted: Thu Jun 28, 2018 5:02 pm
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

Re: PIC16F1788 - Internal Oscillator Speed

Posted: Thu Jun 28, 2018 6:06 pm
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

Re: PIC16F1788 - Internal Oscillator Speed

Posted: Thu Jun 28, 2018 7:07 pm
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

Re: PIC16F1788 - Internal Oscillator Speed

Posted: Fri Jun 29, 2018 6:13 am
by Frank607
Hi Martin,

Thanks for this explanation.