+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Full Member level 3
    Points: 1,561, Level: 9

    Join Date
    Aug 2015
    Posts
    165
    Helped
    7 / 7
    Points
    1,561
    Level
    9

    [PIC] MikroC for PIC32 PIC32MZ MCU Clock Frquency [MHz] bug?

    hey
    I have a simple setup with P32MZ2048EFH144
    It has no external oscillator.
    I have a simple code with Delay_ms(1000) which appears to work fine (the led blinks at about 1 second)
    But....
    I think there is something I dont understand.
    Take a look:
    Click image for larger version. 

Name:	p32bitsconfig.png 
Views:	11 
Size:	102.5 KB 
ID:	156716
    No matter what I set in "MCU Clock Frequency [MHz]", the blinking time is always the same.
    I can set frequency to 200MHz or to 0.1MHz, but it seems that mikroC is ignoring this field.
    It's not blinking slower nor faster when I change it.

    My question is - why?
    I remember that for pic18f I had to enter a correct frequency to this field for delay_ms to work (I had to respect the oscillator settings, the PLL multipler, etc).
    Is this a mikroC PRO for PIC32 bug or why is it?

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 2
    Points: 3,309, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    658
    Helped
    50 / 50
    Points
    3,309
    Level
    13

    Re: [PIC] MikroC for PIC32 PIC32MZ MCU Clock Frquency [MHz] bug?

    Whatever be the Oscillator frequency the Delay_ms(1) function is coded to generate 1ms delay and Delay_us(1) to generate 1us. Doesn't the function name tell that it is for a millisecond delay?



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 3
    Points: 1,561, Level: 9

    Join Date
    Aug 2015
    Posts
    165
    Helped
    7 / 7
    Points
    1,561
    Level
    9

    Re: [PIC] MikroC for PIC32 PIC32MZ MCU Clock Frquency [MHz] bug?

    Quote Originally Posted by baileychic View Post
    Whatever be the Oscillator frequency the Delay_ms(1) function is coded to generate 1ms delay and Delay_us(1) to generate 1us. Doesn't the function name tell that it is for a millisecond delay?
    Did you ever use MikroC?

    Delay_ms(1) doesn't magically know how long the microsecond takes. In all PIC18F, PIC16F, PIC32MX, and dsPIC, this function is taking the "MCU Clock Frequency [MHz]" from Project Settings and it calculates the proper delay based on that.

    I have experienced it many times in PIC16F, that when you enter incorrect 'MCU Clock Frequency [MHz]" it blinks too fast or too slow.

    And my question is - what did they change specifally for PIC32MZ? How do I configure the internal oscillator corrcetly for PIC32MZ?



    •   AltAdvertisement

        
       

  4. #4
    Advanced Member level 4
    Points: 7,616, Level: 20
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    1,021
    Helped
    388 / 388
    Points
    7,616
    Level
    20

    Re: [PIC] MikroC for PIC32 PIC32MZ MCU Clock Frquency [MHz] bug?

    Look in the compiler manual. Some delay functions are based on the "oscillator frequency" and some other delay functions are based on the "MCU clock".
    Delay_ms is based on "oscillator frequency", so it isn't surprising that the delay doesn't change when you modify the "MCU clock" setting.



--[[ ]]--