November 09, 2024, 04:39:37 AM

PIC32-HMZ144

Started by boattowed, October 03, 2023, 07:53:51 AM

Previous topic - Next topic

boattowed

I bought a PIC32-HMZ144 development board to use with a MikroProg programmer and MikroElektronica MikroBasic Pro compiler.  I have not been able to get the oscillator config bits correct.  I got the demo LED blink hex and programmed it using the MikroProg programmer successfully.  I assume it is correct because the LED blinks about 1 second rate.  I wrote a simple LED blink program which should blink the LED at 1 second but it blinks very fast.  I believe this is because the configuration bits are not right.  I've read, researched, tried many, many settings for the last few days without success.  Has anyone been able to get the PIC32-HMZ144 to work with the MikroBasic compiler or any Mikroelektronica compiler to work?
Thanks,
Charles

boattowed

Hi,
Can someone please tell me how the oscillator configuration bits should be set?  I've tried everything and at this point I'm wondering if the board has an issue.  There is nothing in the manual for the board and the hex files aren't any help in this regard.
Thanks,
Charles

Stanimir5F

Hello boattowed!

You mentioned that you have managed to upload the LED blink hex but did you check the code itself?

If not here are the values of the configurations:
// DEVCFG3
// USERID = No Setting
#pragma config FMIIEN = ON              // Ethernet RMII/MII Enable (MII Enabled)
#pragma config FETHIO = ON              // Ethernet I/O Pin Select (Default Ethernet I/O)
#pragma config PGL1WAY = ON            // Permission Group Lock One Way Configuration (Allow only one reconfiguration)
#pragma config PMDL1WAY = ON            // Peripheral Module Disable Configuration (Allow only one reconfiguration)
#pragma config IOL1WAY = ON            // Peripheral Pin Select Configuration (Allow only one reconfiguration)
#pragma config FUSBIDIO = ON            // USB USBID Selection (Controlled by the USB Module)

// DEVCFG2
#pragma config FPLLIDIV = DIV_8        // System PLL Input Divider (8x Divider)
#pragma config FPLLRNG = RANGE_34_68_MHZ// System PLL Input Range (34-68 MHz Input)
#pragma config FPLLICLK = PLL_FRC      // System PLL Input Clock Selection (FRC is input to the System PLL)
#pragma config FPLLMULT = MUL_128      // System PLL Multiplier (PLL Multiply by 128)
#pragma config FPLLODIV = DIV_32        // System PLL Output Clock Divider (32x Divider)
#pragma config UPLLFSEL = FREQ_24MHZ    // USB PLL Input Frequency Selection (USB PLL input is 24 MHz)

// DEVCFG1
#pragma config FNOSC = FRCDIV          // Oscillator Selection Bits (Fast RC Osc w/Div-by-N (FRCDIV))
#pragma config DMTINTV = WIN_127_128    // DMT Count Window Interval (Window/Interval value is 127/128 counter value)
#pragma config FSOSCEN = ON            // Secondary Oscillator Enable (Enable SOSC)
#pragma config IESO = ON                // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = OFF            // Primary Oscillator Configuration (Primary osc disabled)
#pragma config OSCIOFNC = OFF          // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FCKSM = CSECME          // Clock Switching and Monitor Selection (Clock Switch Enabled, FSCM Enabled)
#pragma config WDTPS = PS1048576        // Watchdog Timer Postscaler (1:1048576)
#pragma config WDTSPGM = STOP          // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming)
#pragma config WINDIS = NORMAL          // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode)
#pragma config FWDTEN = ON              // Watchdog Timer Enable (WDT Enabled)
#pragma config FWDTWINSZ = WINSZ_25    // Watchdog Timer Window Size (Window size is 25%)
#pragma config DMTCNT = DMT31          // Deadman Timer Count Selection (2^31 (2147483648))
#pragma config FDMTEN = ON              // Deadman Timer Enable (Deadman Timer is enabled)

// DEVCFG0
#pragma config DEBUG = OFF              // Background Debugger Enable (Debugger is disabled)
#pragma config JTAGEN = ON              // JTAG Enable (JTAG Port Enabled)
#pragma config ICESEL = ICS_PGx2        // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2)
#pragma config TRCEN = ON              // Trace Enable (Trace features in the CPU are enabled)
#pragma config BOOTISA = MIPS32        // Boot ISA Selection (Boot code and Exception code is MIPS32)
#pragma config FECCCON = OFF_UNLOCKED  // Dynamic Flash ECC Configuration (ECC and Dynamic ECC are disabled (ECCCON bits are writable))
#pragma config FSLEEP = OFF            // Flash Sleep Mode (Flash is powered down when the device is in Sleep mode)
#pragma config DBGPER = PG_ALL          // Debug Mode CPU Access Permission (Allow CPU access to all permission regions)
#pragma config EJTAGBEN = NORMAL        // EJTAG Boot (Normal EJTAG functionality)

// DEVCP0
#pragma config CP = OFF                // Code Protect (Protection Disabled)
May the Source be with You!

boattowed

#3
Thank you for the reply Stanimir5F,

I have tried these settings without success.  I actually pulled the settings from the 2 demos that are provided without either working right.  I have come to the conclusion that this is a hardware problem with this new board.  It states on the board that it is a revision D.  In the manual, for revision D boards, it states:

"Because of the above we added 2 oscillators and have changed the 2
crystals and their corresponding components to NA (not assembled)."

This board has an oscillator for CD2 but there is nothing populated for CD1.  I have ordered one from Mouser and should be here tomorrow.

I'm pretty sure the code is good, it's pretty simple:


  JTAGEN_bit = 0        ' Disable JTAG
  TRISH = 0             ' Initialize PORTH as output
  LATH = 0              ' Set PORTH to zero   (LED OFF)

while TRUE

  LATH = not PORTH    ' Invert PORTH value
  Delay_us(1000)
  wend
end.

Once the oscillator is installed and tested, I'll report if that resolves the issue or not.

Thanks again!

Stanimir5F

#4
Hello!

I decided to double check the example (blinking led) to see if there could be any kind of hardware issues related to the oscillators that you mentioned in your last post. But it still worked fine. And as I change the value of the delay loop it changes the frequency of blinking to the expected one.

I am not familiar with the setup that you are using (the programmer, compiler, libraries, IDE etc.) so I can't say anything for sure. But few tings comes to my mind as a suggestions.
1) try to toggle only the LED pin (H2) instead the whole register. While I doubt this would cause the problem it's worth trying.
2) make sure to disable all kind of optimizations for the purpose of testing the blinking LED. Very often they are quite confusing and cause problems in seemingly simple code.
3) double check the delay function.
Quote from: boattowed on October 04, 2023, 08:20:53 PMwhile TRUE

  LATH = not PORTH    ' Invert PORTH value
  Delay_us(1000)
  wend
end.
Once again I don't know what stands behind the function you are calling but usually "us" mean microseconds, instead of milliseconds (which is usually "ms"). So in the example you showed it could be 1000 MICROseconds delay instead of 1000 MILLIseconds resulting in a total delay of 1 milliseconds. So if your goal is to blink it once a second then it will blink 1000 times faster than expected.
May the Source be with You!

boattowed

Oh my goodness, what a help to have a 2nd set of eyes on it.  Switching between Arduino and MikroBasic has bit me before.  Changing to Delay_ms did it.  I would feel stupid if I wasn't so happy to have this resolved :-)
Thank you so much!
Charles

Stanimir5F

You are welcome! :)
Glad to hear that it worked! :)
May the Source be with You!