Created Thu, 04 Aug 2016 15:51:32 +0000 by afrenett
Thu, 04 Aug 2016 15:51:32 +0000
The title is pretty much self explanatory. I want to change the sysclock rate from 80 MHz to 60 MHz (or something at least less than 70 MHz). I understand that other IDEs may allow you to easily change the configuration bits, but the code I'm working with works well with MPIDE. Is there any way to change the PLL mulitplier in MPIDE? If not, advice on the easiest way to do so would be appreciated.
Thu, 04 Aug 2016 17:48:27 +0000
You will need a custom bootloader with the different clock settings in it. You will also need to change the clock speed in the boards.txt file for the variant to match, or everything will be calculated wrong.
Sent from my SM-T555 using Tapatalk
Thu, 04 Aug 2016 20:04:05 +0000
Thanks for the response. A few questions (I'm relatively new to this):
Where would I find such a custom bootloader, and how do I get it onto the board? I'm currently communicating via USB and using MPIDE. I know I probably need another cable, but am not sure which.
Where in the boards.txt file do I need to change the speed? Just a brief glance through tells me that there's more than one location.
Thu, 04 Aug 2016 22:30:53 +0000
Actually, you should be able to vary the PLL settings at runtime using the OSCCON register. Details here:
Of course, doing so will mean the chip is running at the "wrong" speed, so you still need to change boards.txt to compensate. The specific file is pic32/variants/Max32/boards.txt for MPIDE and pic32/boards.txt for Arduino IDE. You're looking for mega_pic32.build.f_cpu.
Fri, 05 Aug 2016 14:17:58 +0000
I had seen the OSCCON register, but I noticed that the PLL divider/multiplier bits should or could not be manipulated while PLL is enabled.
I have tried using "#pragma PLLODIV = 2" at the beginning of the MPIDE file, but to no effect. Should I be trying a different way?
Fri, 05 Aug 2016 19:54:10 +0000
You can't specify config bits from within MPIDE, they are hard coded in the bootloader.
Switching the PLL settings is a multi-stage process and involves switching clock sources numerous times.
In theory it should work fine if you:
One caveat of this, though, is that clock switching has to be enabled, and I am not sure that it is by default in the MAX32 bootloader. It's in the config bits, so is hard-coded in the bootloader and can't (easily) be changed without recompiling the bootloader and reprogramming it using a hardware programmer - in which case you may as well set the PLL up how you want it at the same time and not then need to mess with OSCCON.
The bootloader source is here: https://github.com/chipKIT32/PIC32-avrdude-bootloader but Digilent in their wisdom decided that they didn't want us to have our own configurations for their boards (I have no idea why, they often don't make sense to me) so you will have to take something similar and bend it to the MAX32. I do, though, have sneaky backups of all the Digilent configurations in my own fork, so you could maybe use those and feed them into your own clone of the repo: https://github.com/majenkotech/PIC32-avrdude-bootloader/blob/digilent/bootloaders/configs/digilent.h
Mon, 08 Aug 2016 15:31:34 +0000
Okay, thanks. Is there an available hex file with the Digilent configuration on your site? I'm not totally sure how to upload a new bootloader, but I know you can use the MPLAB IPE (I have the chipKit PGM cable). It asks for a hex file, however.
Mon, 08 Aug 2016 16:36:27 +0000
There are HEX files available, but they have the PLL set up to 80MHz. If you want anything other than that you'll have to compile your own.
I have to ask, though, why, really, you feel you need to have a 60MHz clock. You're just needlessly slowing the system down. Whatever you are doing can be done just as well (if not better) at 80MHz.
Mon, 08 Aug 2016 17:37:17 +0000
The end goal is not to simply slow the machine down. I'll need to mess with other configuration bits, and I figured that modifying the PLL gives an easy mechanism to check whether or not the configuration actually changed.
Mon, 08 Aug 2016 17:40:34 +0000
I have managed to change the config bits from software before now. Its risky business, and you risk corrupting your bootloader, but it can be done. Otherwise you will have to get the hang of building your own bootloader.
I will see if I can dig out the work I did to edit the config bits and see if it still works...
Sent from my SM-T555 using Tapatalk
Mon, 08 Aug 2016 17:54:40 +0000
After messing around in the IPE a while, I have an idea (a good idea? I don't know). In the MPLAB IPE there is an option to "Fill Memory", where one can write directly to memory addresses. Could I modify the information already in the configuration registers using this function? (i.e. read the value currently in the register, figure out the value with the modified bits, and write the modified word to the same address?)
Mon, 08 Aug 2016 18:56:00 +0000
No, you can't. The config bits share the same flash page as part of the bootloader. To write to them you have to first erase the page they are in, and that kills the bootloader.
I have a program that will allow you to modify the config bits on a running MAX32. It's the ConfigBits example that comes with my Flash library:
Use it very very carefully - you can easily brick your board with it and have to re-flash the bootloader (which you can download from the MAX32 page on Digilent's site).
Changing the PLL settings is not a good idea since it would render the serial port inoperable (unless you can calculate the new strange baud rate to use), but you can use it for other things like changing the watchdog time, turning clock switching on and off, etc.
It needs the ANSI library installing, which is bundled with the example sketch - copy it to be with the rest of your libraries - and it needs a real ANSI capable terminal program, not MPIDE's serial monitor.
Wed, 10 Aug 2016 13:48:19 +0000
What program would you recommend I use to run the code? And will do - I won't touch the PLL bits.
Wed, 10 Aug 2016 14:47:41 +0000
MPIDE, Arduino IDE + chipKIT Core or UECIDE. It won't work in anything else.
Wed, 10 Aug 2016 18:16:51 +0000
You said MPIDE doesn't have a complex enough terminal, and the chipKit core for the Arduino IDE doesn't support the Max32 board. That leaves UECIDE. When I open the .ino file in UECIDE though, it cannot find the xc.h library (which I can't find either). Am I loading the program correctly, or should I be doing something else?
Wed, 10 Aug 2016 20:17:24 +0000
You said MPIDE doesn't have a complex enough terminal,
That doesn't mean you can't use an external terminal program such as PuTTY, TeraTerm, etc.
and the chipKit core for the Arduino IDE doesn't support the Max32 board
It most certainly does!
When I open the .ino file in UECIDE though, it cannot find the xc.h library
They you may not have installed the right plugins. xc.h is part of the compiler.
Thu, 11 Aug 2016 13:41:59 +0000
Got it - was using the wrong compiler. The ConfigBits seems to work, thanks!!