Turn off the 5.6s power off feature VS1005

Writing software that controls the system and peripherals such as displays, SD cards, Buttons, LEDs, Serial Ports etc.
Post Reply
jedm@vpitech.com
Senior User
Posts: 43
Joined: Wed 2016-11-02 22:50

Turn off the 5.6s power off feature VS1005

Post by jedm@vpitech.com » Mon 2017-01-16 20:56

The VS1005g manual states that the PWRBTN turns off the power if held low for 5.6 seconds and that this feature can be turned off by software. I can't find any references on how to do this (I can read its state).


Jed

User avatar
Panu
VLSI Staff
Posts: 2427
Joined: Tue 2010-06-22 13:43

Re: Turn off the 5.6s power off feature VS1005

Post by Panu » Mon 2017-01-16 21:51

Hi!

Where did you read this? Because I don't think that it's accurate. It doesn't turn off the power, it causes a reset. And actually, each HIGH state WILL cause a reset after a few seconds, unless disabled, regardless of whether the power button is held high or not. So that functionality needs hand-holding by software (in the power button interrupt and another timer interrupt) and as such is not very practical; I think other methods are more practical.

Here and there in the kernel you can see this line:
    PERIP(ANA_CF1) |= ANA_CF1_BTNDIS; //Disable power button reset
That line causes the automatic power button reset NOT to be taken.

I think there's a program called PowerOff (POWEROFF.DL3) in the root, and its source code may be a good read, see: viewtopic.php?f=13&t=1752&p=8553

The Stop Trace driver (inttrace.dl3) can be used as an example on how to do a power button interrupt handler.

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

jedm@vpitech.com
Senior User
Posts: 43
Joined: Wed 2016-11-02 22:50

Re: Turn off the 5.6s power off feature VS1005

Post by jedm@vpitech.com » Mon 2017-01-16 23:27

Oh dear, I must have looked at the ANA_CF1 bits table 20 times and didn't see that line immediately below.

I rehashed the power off example but turned all the regulators off since this is a battery powered system. I haven't had a chance to see if this really turns stuff off.

Thank you for pointing it out.

void powerOff(void)
/* This code abstracted from PowerOff example, viewtopic.php?f=13&t=1752.
* Turn off the PWM, disable the OS, turn off regulators,
* Parameters: none
* External References:
* PWM_FRAMELEN, PWM_PULSELEN: PWM may or may not be used. It is used during startup and is probably left on
* so it needs to be shut down.
* REGU_CF: Regulator control register. Turn off all the features we can find.
* Returned values: never gets out of here.
*/
{

USEY(PWM_FRAMELEN) = 255; // PWM registers in Y space.
USEY(PWM_PULSELEN) = 0; // And output width to 0.

Forbid();
SetPower((PCL_SDCARD | PCL_USB_A | PCL_USB_AB | PCL_USB_5V), 0);
Delay(100);

// Turn off all the internal regulators.
PERIP(REGU_CF) |= REGU_CF_SNFOFF | REGU_CF_ADOFF | REGU_CF_FMOFF | REGU_CF_AOFF | REGU_CF_IOOFF | REGU_CF_COFF;
PERIP(REGU_CF) &= ~(REGU_CF_REGCK); // Flip the regulator latch control (11.6.2, page 54).
PERIP(REGU_CF) |= (REGU_CF_REGCK); // This toggles in the off bits.
PERIP(REGU_CF) &= ~(REGU_CF_REGCK);

while(1); // Should never get here.
}

jedm@vpitech.com
Senior User
Posts: 43
Joined: Wed 2016-11-02 22:50

Re: Turn off the 5.6s power off feature VS1005

Post by jedm@vpitech.com » Mon 2017-01-16 23:33

And, I'm not sure where I read that, can't find it in the manual. I suspect it was something in one of the forum that made me think that it caused power down.

User avatar
pasi
VLSI Staff
Posts: 1416
Joined: Thu 2010-07-15 16:04

Re: Turn off the 5.6s power off feature VS1005

Post by pasi » Tue 2017-01-17 12:53

Yes, that code should turn off the regulators.

The voltage does not drop that quickly though, so in reality that while(1); will get executed quite a few times.

I would probably also disable interrupts and drop to 1.0x clock before turning off the regulators. ( Disable(); PERIP(CLK_CF) &= ~CLK_CF_FORCEPLL; /*1.0x mode*/ )
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

jedm@vpitech.com
Senior User
Posts: 43
Joined: Wed 2016-11-02 22:50

Re: Turn off the 5.6s power off feature VS1005

Post by jedm@vpitech.com » Mon 2017-06-26 23:15

Still working this problem:

vs1005g.h lists three routines: PowerShutDownFlash, PowerOff, and RealPowerOff. PowerOff appears in the VSOS documentation though it's not explained. Do these do anything in addition to the regulator power off? Which one should I call, if any?

After shutting down the regulators, as in code below, pulling PWRBTN high doesn't seem to restart things. Pulling XRESET low gets things started again which suggests that the loop at the end is still executing even after a few minutes. VHIGH is still at 3.7 volts. Is this a problem?

Thank you in advance.
Jed

Code: Select all

void powerOff(void)
{
      USEY(PWM_FRAMELEN) = 255;           // PWM registers in Y space.
    USEY(PWM_PULSELEN) = 0;             // And output width to 0.
    Forbid();
 
    SetPower((PCL_SDCARD | PCL_USB_A | PCL_USB_AB | PCL_USB_5V), 0);
    Delay(100);

    // The following suggested by Pasi at VLSI.
    Disable();                          // Turn off interrupts.
    PERIP(CLK_CF) &= ~CLK_CF_FORCEPLL;  // Switch to 1.0x Clock.
    
    // Turn off all the internal regulators.
    PERIP(REGU_CF) |= REGU_CF_SNFOFF | REGU_CF_ADOFF | REGU_CF_FMOFF | REGU_CF_AOFF | REGU_CF_IOOFF | REGU_CF_COFF;
    PERIP(REGU_CF) &= ~(REGU_CF_REGCK); // Flip the regulator latch control (11.6.2, page 54).
    PERIP(REGU_CF) |= (REGU_CF_REGCK);  // This toggles in the off bits.
    PERIP(REGU_CF) &= ~(REGU_CF_REGCK);

    // The regulators take a while to discharge so this statement will get executed a number of times. By this
    // time interrupts are disabled and we'll be running 12. mhtz or so which makes it last even longer.
    // Pasi from VLSI.
    while(1) ;
}

User avatar
Panu
VLSI Staff
Posts: 2427
Joined: Tue 2010-06-22 13:43

Re: Turn off the 5.6s power off feature VS1005

Post by Panu » Tue 2017-06-27 12:32

Hi!
After shutting down the regulators, as in code below, pulling PWRBTN high doesn't seem to restart things ... which suggests that the loop at the end is still executing even after a few minutes. VHIGH is still at 3.7 volts. Is this a problem?
Do you think there might be leakage from VHIGH (or from ANY other power source, such as an I/O pin, classic example is UART RX pin feeding 3.3V) to any of the power rails? Or even to any pin on the device, since practically all pins are connected to some power rail via the protection structure (diode with reverse polarity)?

Any external voltage source on any pin may potentially leak to any voltage rail through one or more diodes in reverse polarity, preventing the core from being shut down.

Does anything come to mind?

Hmm, there's a bit in CF_CTRL that disables internal brown-out reset. Can you check what value it is and if flipping it causes any change in functionality? Here's a helpful code snippet:

Code: Select all

	#define CF_CTRL 0xFC25
	#define CF_ENABLE 0xFC26
	#define CF_KEY 0x5A7D
	
	printf("CF_CTRL=%04x\n",PERIP(CF_CTRL));
	PERIP(CF_ENABLE) = CF_KEY;
	PERIP(CF_CTRL) &= ~(1<<15);
	printf("CF_CTRL=%04x\n",PERIP(CF_CTRL));
Finally, be very careful what you write in CF_CTRL. Don't touch any of the other bits, that might be dangerous and for that reason we don't even put that register into the header files, inviting people to poke around with it.

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

Post Reply