PIC32MX Clock setting issues

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
User avatar
p.erasmus
Valued Contributor
Posts: 434
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

PIC32MX Clock setting issues

Post by p.erasmus »

Dear Team.

I am having an issue to get the PIC32MX795F512L to run the correct speed and I try to explain the issue below

As a test I used MPLABX and Harmony to generate me the clock settings and it running fine on the mikroE EasyPIC Fusion Development board

XT = 8MHZ
Clock speed 80MHZ
the Harmony configuration
MPLABConfig.jpg
MPLABConfig.jpg (65.94 KiB) Viewed 2913 times
The same settings in the MikroE PIC32 Compiler Runs fine aswell
settings tested in 2 compilers and tool chains with no issue :D

Running the same settings in FC the clock speed is faster as it should be ,
I set a led on 10msec and off 10msec so an period of 20mSec effectivly as you will se below the ON and OFF timnes are 5mSec
totally incorrect
Print_5msec.jpg
Print_5msec.jpg (87.14 KiB) Viewed 2913 times
The configurations below
PLL_2.jpg
PLL_2.jpg (69.79 KiB) Viewed 2913 times
PLL_2_Config.jpg
PLL_2_Config.jpg (49.7 KiB) Viewed 2913 times



Notice the generated code the FPLLIDIV is set at 1 (I canot judge that this is correct or not) just showing what I see and the multipier is 5 which is x20

If I set the FPLLIDIV to x4 it causes the the timing to be 100% correct and the code generated show a value of 3 for FPLLIDIV
see below

Print10_ms.jpg
Print10_ms.jpg (74.17 KiB) Viewed 2913 times
PLL_4.jpg
PLL_4.jpg (67.35 KiB) Viewed 2912 times
in all cases the Peripheral clock is set at Pclk/1(div by 1 )

I attatch the project as well however in my humble opion there is an isse with the pic32 config settings in FC

The FC chart
FC_10ms.jpg
FC_10ms.jpg (31.17 KiB) Viewed 2908 times
I am in a serious problem as I need to do a CAN project for a customer and the timings are wrong so I will battle to get the CAN to work properly Thanks again for all the help and I would appreciate if we can point to the problem regardles me or FC :D
P32_Test.rar
(42.08 KiB) Downloaded 106 times
[attachment=0]
Attachments
PLL_4_Config.jpg
PLL_4_Config.jpg (55.12 KiB) Viewed 2913 times
Regards Peter - QME Electronics

User avatar
p.erasmus
Valued Contributor
Posts: 434
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

Re: PIC32MX Clock setting issues

Post by p.erasmus »

Hi Team.

After a few more experiments
I set the FPLLIDIV to x2 as should be and configure Timer 2 Interrupt for 10mSec and then toggle led on RB1 and leaving the Toggle of LED on RB0 in the main loop controlled by the Delay component.

The interrupt fire exactly on the 10mSec and the delay timing is way off ,
This seems that the PIC32 is running at the correct clock speed as it si configured for however the delay calculations are wrong below a print of the timings and the code file.

CH1 delay timing control and CH2 is timer 2 interrupt controlled

Would you agree with me that it seems there is a problem with the delay component , :D please shed some light on this :D


Print_Int.jpg
Print_Int.jpg (98.9 KiB) Viewed 2901 times
INT.jpg
INT.jpg (36.48 KiB) Viewed 2901 times
Config_Int.jpg
Config_Int.jpg (51.6 KiB) Viewed 2901 times
Regards Peter - QME Electronics

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: PIC32MX Clock setting issues

Post by BenR »

Hello,

The FPLLIDIV set to /2 should be a value of 1 so that is correct.

The PIC32 devices have internal clock dividers and that is probably what's causing the timing issues.

What is your FPBDIV config setting set to?

User avatar
p.erasmus
Valued Contributor
Posts: 434
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

Re: PIC32MX Clock setting issues

Post by p.erasmus »

Hi Ben

In the config print above the internal devide is set to 0 (No divide ) FPBDIV = 0

How does that effect only the delay component (this is my issue ) the HW timing is correct as I have indicated by the TMR2 10mSec interrupt

I am confused

Thanks for your help
Regards Peter - QME Electronics

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: PIC32MX Clock setting issues

Post by BenR »

Hello,

Please can you try adding this to your supplementary code and see if that makes any difference.

Code: Select all

#define MX_CLKS_PER_INST 4

User avatar
p.erasmus
Valued Contributor
Posts: 434
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

Re: PIC32MX Clock setting issues

Post by p.erasmus »

Hi Ben

CLKS_PER_INST 4 has the same efect Delay component is to fast however

Code: Select all

#define MX_CLKS_PER_INST 2 
This solve the issue HW and Delay Component now has the same time value :D
What this define actually modify is not clear to me however for now it is OK but in future or if soemone change the Clock settings I suppose this will need a recalibrate also :D
Regards Peter - QME Electronics

SpeedPIC32
Posts: 252
Joined: Thu Dec 10, 2020 2:35 pm
Has thanked: 36 times
Been thanked: 17 times

Re: PIC32MX Clock setting issues

Post by SpeedPIC32 »

Hello

small error also with the PIC32MZ2048EFH100 200Mhz Flip Clickboard PIC32MZ
Loop with second cycle runs at second cycle
LED one sec on one sec off.
The second LED should do the same with a 10msec cycle in conjunction with a counter up to 100. But flashes faster
I have output the count value via a RS232 and it was the same, much too fast.
The build rate was correct.

With kind regards
SpeedPic32
Fehler.fcfx
(31.22 KiB) Downloaded 91 times

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: PIC32MX Clock setting issues

Post by BenR »

PIC32 discussion continued here: viewtopic.php?p=5563#p5563

Post Reply