I ended up going with the power cycle version of the code that looks like this. It works super well for what we need.
On the STM I am running a super simple motor control program inside the stabilizer task. In the future we will expand this a bit and maybe save state to memory during the on period or something. But at the moment this is what we need.
Code: Select all
// power cycle off if the ON time has been reached
else if ((pmGetState() == pmSysRunning) && ((systickGetTick() - powerTick) >= TICK_BETWEEN_POWER_ON))
{
powerTick = systickGetTick();
LED_OFF();
//stm bootloader
pmSysBootloader(true);
pmSetState(pmSysOff); // turn off system
}
// power cycle on if on_flag set in low power timer is set
else if ((pmGetState() == pmSysOff) && ((systickGetTick() - powerTick) >= TICK_BETWEEN_POWER_OFF))
{
powerTick = systickGetTick(); // get tick to start again
LED_ON();
//stm bootloader
pmSysBootloader(false);
pmSetState(pmSysRunning); // turn system on
}
I do have one last question. During the 'off' state, it's still pulling a bunch of current. I've spent the past week trying to set it to sleep and it's not working. Actually sleeping is not an issue. I tested it and it's pulling in the micro amp range. The issue is the timer interrupt. The sleep wakes during the interrupt so the 1ms timer does not work. I wrote a second timer (timer0) that could sleep for n number of seconds when started. That works fine. I tested it in main by commenting everything else out and just toggeling the LED each interrupt.
Code: Select all
// Make sure any pending events are cleared
//__SEV();
//__WFE(); // go to sleep until interrupt wakes
//__WFE();
I then modified the power cycling to look like this:
Code: Select all
// power cycle off if the ON time has been reached
else if ((pmGetState() == pmSysRunning) && ((systickGetTick() - powerTick) >= TICK_BETWEEN_POWER_ON))
{
LED_OFF();
//stm bootloader
pmSysBootloader(true);
pmSetState(pmSysOff); // turn off system
timer0_init(5000); // 5 second timer - working
// Make sure any pending events are cleared
//__SEV();
//__WFE(); // go to sleep until interrupt wakes
//__WFE();
}
// power cycle on if on_flag set in low power timer is set
else if ((pmGetState() == pmSysOff) && on_flag)
{
on_flag = false;
systickInit(1000); // start normal tick timer again and turn off timer0
LED_ON();
//stm bootloader
pmSysBootloader(false);
pmSetState(pmSysRunning); // turn system on
} */
on_flag is getting set each time the timer0 interrupt hits. And inside of timer0_init() I turn off timer 2 and start timer 0. But the system enters indeterminate state. I think this is due to the lack of 'tick' timer to run the pmProcess() and it gets stuck.
I tried a number of different ideas with turning the two timers on and off and setting flags to wake/sleep but it usually enters a strange state. Do you have any ideas about the best way to get it sleep when the main STM32 is off? I assume there are a number of ways to solve this problem and my approach is not working
