Page 1 of 2
PIC16F1825 Bug in OSCCON
Posted: Sat Oct 21, 2023 2:52 pm
by DirkB
Hello,
it is not possible for me to run the PIC 16F1825 with INTOSC 32Mhz. I tried everything, OSCCON=0x70; PLL turned on in the chip options, OSCCON = 0xF0; PLL turned off in the chip options. Here is a small test program. Clock Out is on and gives a speed of 8 Mhz, but the chip always works with 500 Khz. So I suspect an error in the configuration of the multiplexer of the oscillator. I tried it with V8, V9 and V10. I can't get it to work. What am I doing wrong?
Thanks
Dirk
Re: PIC16F1825 Bug in OSCCON
Posted: Sat Oct 21, 2023 6:08 pm
by mnfisher
What do you mean by only works at 500kHz? - A PIC running at 32MHz has an instruction rate of 8MHz - so 16 instructions per loop / output to pins and change the value of clk.
It's probably about right?
The 'fastest' I can get on a 32MHz PIC by toggling a pin (A0) is 1.14MHz (with 540ns / 340ns high / low pulses) - you can get faster using PWM if you need?
AVR chips are quicker at 1clk per instruction - so 16MHz chip gives 16MHz instructions.
Note - I cheat and use an output to A0 to set it as an output (rather than fiddling with TRISA etc).
(Sorry - had to change the chip)
Martin
Re: PIC16F1825 Bug in OSCCON
Posted: Sat Oct 21, 2023 9:44 pm
by DirkB
I mean that the PIC has a default setting of 500 Khz. The switching of pin A0 is only an example. The program runs only with 500 Khz. An older slower chip with 20 Mhz crystal runs more than 20 times faster. I have a program with an 8 bit sinus lut, which can create about 15 Khz at 32 Mhz. With this chip you can't even do 10 Hz.
Dirk
Re: PIC16F1825 Bug in OSCCON
Posted: Sat Oct 21, 2023 9:48 pm
by DirkB
I forgot, I get a maximum of 249 Khz when switching pins. So half of 500 Khz.
Dirk
Re: PIC16F1825 Bug in OSCCON
Posted: Sat Oct 21, 2023 9:56 pm
by DirkB
If it is theoretically only 1/4 of the time, it is still about 8 Khz Sine.
Dirk
Re: PIC16F1825 Bug in OSCCON
Posted: Mon Oct 23, 2023 8:27 am
by medelec35
Hello.
You have got the watchdog timer enabled within your configuration settings
However, you are not cleating the watchdog timer.
The reason for lack of speed when toggling a pin is because your target device constantly resetting.
Try disabling the watchdog timer then see what speed you get.
Re: PIC16F1825 Bug in OSCCON
Posted: Mon Oct 23, 2023 10:03 am
by DirkB
Hello Martin,
I have now disabled everything except Clock Output, same result, see attachment.
It concerns all chips which I use. The PIC16F1825 with 32 Mhz Clock Out 32Mhz (Clock) / 4 (Instructions)
results in 8 Mhz. Main Loop (program) 500Khz. The PIC16F1455 can be operated with 48 Mhz. Clock Out
48Mhz (Clock) / 4 (Instructions) results in 12 Mhz. Main Loop (Program) 500Khz.
I already thought about if there is always a reset. Then the chip is set to 500Khz by default. But everything
is switched off in the configuration. I have no idea. There must be a bug in the configuration.
Dirk
Re: PIC16F1825 Bug in OSCCON
Posted: Mon Oct 23, 2023 11:08 am
by DirkB
Hello,
it probably affects the whole 12(L)F18XX, 16(L)F18XX, 16(L)F14XX family and probably many more.
Dirk
Re: PIC16F1825 Bug in OSCCON
Posted: Mon Oct 23, 2023 11:17 am
by medelec35
Have you tried the
one sec flash test to check if your hardware is running at the correct speed?
I have just tried your configuration settings with Martins method of toggling the A0 pin on a 16F1825 and:

- Toggling A0 16F1825.png (14.64 KiB) Viewed 6370 times
Using your flowchart with the same configuration, the toggle speed is:

- Toggling A0 16F1825 org.png (19.52 KiB) Viewed 6370 times
All the overheads slow things down and that is what you are seeing.
The 1sec flash test working as expected, so no configuration issues.
As it is not a bug, I have moved the topic to a more appropriate section.
Re: PIC16F1825 Bug in OSCCON
Posted: Mon Oct 23, 2023 2:17 pm
by DirkB
Hello Martin,
It must be a bug. It cannot be that with a clock frequency of 8 Mhz with the program with PWM an output frequency of 10 Khz results. With the second flash the process can always rest 1 second. This is not meaningful. I need continuous calculations which are not possible. Please check the signals with proper hardware frequency counters or oscilloscope. Also when I implement midi and there comes a midi sequence with 3 or more commands, there are errors because the program is too slow. A 16F688 with 20 Mhz crystal program written in assembler is able to reach a 4 Mhz signal. Also if I implement midi and there comes a midi sequence with 3 or more commands, there are errors because the program is too slow.Please check the signals with proper hardware frequency counters or oscilloscope. A 16F688 with 20 Mhz crystal program written in assembler is able to reach a 4 Mhz signal.
The slow speed is now clear to me. See this post.
https://flowcode.co.uk/forums/viewtopic.php?f=5&t=2010
Please check the matter.
Thanks
Dirk