Jump to content
phaseform

getting the hibernate library to play nice

Recommended Posts

Trying to get the hibernate library to work as in the pastebin example for the tm4c123 here. I've modified it with the request at the end.
 

//#include <DateTimeLibrary.h>

#include "driverlib/hibernate.c"
boolean redstate = false;
boolean bluestate = false;
int green = 0;
void setup()
{
  uint32_t hibact = HibernateIsActive();
  // put your setup code here, to run once:
  pinMode(GREEN_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);
  HibernateEnableExpClk(F_CPU);
  HibernateRTCEnable();
  HibernateRTCMatchSet(0,HibernateRTCGet()+5);
  HibernateIntRegister(HibernateHandler);
  HibernateIntEnable(HIBERNATE_INT_RTC_MATCH_0);
  HibernateRTCTrimSet(0x7FFF);
}
 
void HibernateHandler(void)
{
  //Use this to reset interrupt flag
  uint32_t ui32Status = HibernateIntStatus(1);
  HibernateIntClear(ui32Status);
  //Place here code to execute every second, ex: LCD or 7 segment display
  //Altough it should be as fastest as possible
  redstate = !redstate;
 
  //To keep the interrupt hapening every second you need this
  HibernateRTCMatchSet(0,HibernateRTCGet()+5);
}
 
void loop()
{
  // put your main code here, to run repeatedly:
  bluestate = !bluestate;
  if(redstate ==0){
   green = 0;
  }
  else green = 64;
  analogWrite(GREEN_LED, green);
  if (bluestate) {
    analogWrite(BLUE_LED, 64);
  }
  else {
    analogWrite(BLUE_LED, 0);
  }
  delay(750);
  HibernateRequest();
}

Been reading through 16.2 API Functions for the hibernate module here and can figure out whats going on. I just want the hibernate module to be requested once main has run, this doesn't seem to happen and the hibernate interrupt just seems to function as a timer running alongside the main function...???
Tried adding HibernateWakeSet(HIBERNATE_WAKE_RTC); to the setup

Share this post


Link to post
Share on other sites

That code as just to use the hibernation module RTC and Calendar mode, it's not even a library! There is 0 power saving features implemented. I actually never used it for that. 

" the hibernate interrupt just seems to function as a timer running alongside the main function.." that's exactly what's it's doing.

Btw the calendar mode only works with the tm4c129x if I remember correctly.

"
 I just want the hibernate module to be requested once main has run" well, it is requested, it's already on :P
Please explain a bit more.

Share this post


Link to post
Share on other sites

Ok so I want to save battery life, I thought I could get the chip to power down when hibernating (which I assumed meant main would not run?).

I also thought not as relevantly I could save power by powering via vbus and removing the jumper pin to (I hoped) disconnect the debug chip...
I dont need calendar mode since I'm using a timedate library.

 

Am I totally misunderstanding the hibernate module??!

Share this post


Link to post
Share on other sites

Nope, you just totally misunderstand the purpose of that code example. That just shows how to use some of the features, that actually can be use in normal run mode.
In any sleep mode there's not any code that will run. You need a wake up source to get back to the code, in hibernate mode (compared to other sleep modes) there's actually very few wake up sources.
There's actually a sleep() function in Energia but I never tested it out. I think you can set the device to sleep of x milliseconds. 

The debug chip actually consumes a lot (something like 50mA in the TM4C123 if I am not mistaken) and as far as I know, you can't actually disconnect it in the tm4c123 launchpad as weird as it seems.

Share this post


Link to post
Share on other sites

I don't understand how TI brought this out to go against Arduino when example codes for the hardware are so scarce, clearly they don't focus on the hobbyist market, or at least they really suck at doing it. Energia is linked on the launchpad website.. should it be confusing something as simple as power management would appear so tricky. I guess I'm just going to keep poking it with a stick until it works?

Share this post


Link to post
Share on other sites

This type of code as nothing to do with Energia/Arduino!
This is low level coding with low level libraries (just above register programming)! Like in arduino you can use register programming, or if using a Arduino Due, use low level libraries too, to have full access to your hardware. Of course with time there's high level libraries that appear but this type of feature is MCU specific = less likely for a library to appear.

Power management = simple? It can actually be quite complex! Which sleep mode? Which peripherals should be on? With which clock on and in which bus? What are the wake up sources? Chose the right core voltage and clock source and speed for different wake up times and consumption.
 

Granted that there's fewer code examples for some features but don't compare the size of the community + lots of users here go to low level programming for the advantages it brings (or a mix).

You should be able to use these for delays where the cpu sleeps:

void sleep(uint32_t milliseconds);
void sleepSeconds(uint32_t seconds);

There's also a void suspend(void); that I think works by using a interrupt as a wake up source.

And if you really want to go for low level programming with Tivaware libraries, there's actually plenty of examples on the package including some for the hibernate module

Share this post


Link to post
Share on other sites

What @L.R.A said, and to elaborate further...

 

There are several places where sleep(), sleepSeconds(), suspend(), and wakeup() are discussed in 43oh forums.  Energia on the TI microcontrollers actually has fairly sophisticated energy management features.  For example, see this recent post on the 43oh blog and this simple example.  I tried the example just now on the EK-TM4C123GXL with Energia 16 on my Windows 10 machine and it works fine.

Share this post


Link to post
Share on other sites

@@phaseform

 

I have used it successfully on MSP430 microcontrollers as documented in the blog post linked above. I am not as familiar with the other TI microcontrollers and after looking back I am not sure how the functions are implemented in Energia on the EK-TM4C123GXL. If you want full control of power modes it is better to use the libraries that TI provides and CCS as L.R.A suggests.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×