Project - G120 Clock Frequency and Peripheral Power Control

I just posted G120 Clock Frequency and Peripheral Power Control on Codeshare. Feel free to discuss and make suggestions here.

7 Likes

This is really cool stuff, and fundamental when a decent project needs to be really serious about power… I think.

I had a look through your code and its really heavy stuff to me. I am having a hard time understand the exact usage in my program.

If my code is finished doing all needed stuff, and wants to go into hibernate for say 1 hour, what is the procedure for shutting things down, and the procedure to get everything back to normal again - speeding up and turning on peripherhals…

In other words, can you provide a little bit more usage examples…

Thank you so much, looking forward to try this.

This is how set the clock speed. I just do this once at the start of my code and leave it for the duration.

myPower = new cG120PowerModes();

cG120PowerModes.PLLClock CPUspeed = cG120PowerModes.PLLClock.clock120MHz;
myPower.setPLL0(CPUspeed);
cG120PowerModes.setPeripheralPowerStatesBase(0); //You can change what this means within the class.

int commSpeed = 9600 * 120 / ((int)CPUspeed); //This is how I calculate my adjusted UART bauds. Other time related stuff may also need to be adjusted.

I use the following to enter a ‘deep sleep’ hibernate. The Wake on RTC Alarm doesn’t seem to work for me, but I just use an interrupt pin from a push button or a second supervisory uC to trigger the wake.


cG120PowerModes.LCDEnable(false);   //Backlight must be turned off separately.

Register SCR = new Register(0xe000ed10);
Register PCON = new Register(0x400fC0C0);  //Power Mode Control 
PCON.Write(0x00000100);//Clear SMFLAG
PCON.Write(0x00000200);//Clear DSFLAG
PCON.Write(0x00000400);//Clear PDFLAG
SCR.SetBits(0x00000004); //SET DEEP SLEEP MODE  

Power.Hibernate(Power.WakeUpInterrupt.InterruptInputs);
//Code resumes here when woken

debugText = "SLEEP DEEP " + PCON.Read().ToString("X8");  //Defaults to 0x00000100 = SMFLAG=1//Should = 0x200 if SLEEPDEEP worked

DateTime DT = RealTimeClock.GetTime();
Utility.SetLocalTime(DT);  //Update system clock

cG120PowerModes.LCDEnable(true);

I am actively testing all this out at the moment and am still getting the odd bug where my code doesn’t restart correctly. At the moment I don’t know the cause. It definitely wakes from hibernate as I can toggle an LED when the CPU wakes, but it locks up with the LCD displaying ‘GHI’. Hopefully I will get this fixed soon.

Currently i’m not messing with the clock rates as part of the hibernate routine.

Also the built in Power.Hibernate() method is a bit of a black box to me. I have tried replacing it with a RLP routine that shuts the thing down while blocking other threads from running, but with no luck.

Supergreat, thanks, will dive into this. Thank you so much, really great, will let you know how it goes.

Also, please keep us updated on your current project… :hand:

Its time to wake this up again… :stuck_out_tongue: after the GHI.Premium libs has changed, did anyone port this piece?