Page 1 of 1

PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 8:26 am
by stefan.erni
Hi Ben

To let the PIC sleep I config first an interrupt on portG, Pin G15 to wake him up if I press ON-Button on G15.

Then I let him sleep with this asm comand
asm volatile ( "wait" );
in a C code Icon.
sleep.PNG
(6.15 KiB) Downloaded 2188 times

It's working like this...
By the program start the PIC(board) needs 140mA
after the wait command the PIC(board) needs 90mA and some buttons has no fuction.
If I press the ON-Button it goes back to 140mA and the another buttons are working again.
90mA is still to much.....
In the manual I found this info
OSCCON:
bit 4 SLPEN: Sleep Mode Enable bit
1 = Device will enter Sleep mode when a WAIT instruction is executed
0 = Device will enter Idle mode when a WAIT instruction is executed
I read the value of the register and send it to the terminalprogram.

It give me this value
1 0001 0010 0010
Means bit 4 is 0 (idle mode)

In FC8, how can I set register OSSCON bit4 to 1 ?
sleep2.PNG
(7.39 KiB) Downloaded 2188 times

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 10:45 am
by Benj
Hello,

You can simply do this using a C code icon.

Code: Select all

OSCCONbits.SLPEN = 1;
Alternatively you can do it by ORing a mask.

Code: Select all

OSCCON |= 0x00000010;

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 11:10 am
by stefan.erni
Hi Ben

I tried both, but both does not change the OSCCON bit4 or the powerconsum.

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 11:16 am
by medelec35
For bit 4

Code: Select all

OSCCON |= 0x00010000;

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 11:32 am
by Benj
medelec35 wrote:For bit 4

Code: Select all

OSCCON |= 0x00010000;
That looks like bit 16 to me ;)

Maybe Martin meant this.

Code: Select all

OSCCON |= 0b00010000;
Not sure why the code isn't working for you. It certainly should be from the looks of it and the bit is read and write so you should be able to write to it and read it back.

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 11:39 am
by stefan.erni
Hi Martin


I think Ben is using hex and Martin bin..,,

I made some test with the watchdog divider
I send it to the terminalprogram and it shows me
2
then I change in the project option config
and my terminalprogram shows
10
then I use the c command
WDTCON |= 0x0000010;

and it shows still
10

FCV_REGISTER32=WDTCON;

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 11:43 am
by Benj
Hello,

Bits 0, 2, 3, 4, 5 and 6 of the WDTCON register are read only. Bit 1 is writeable and corresponds to the window setting.

set bit 1

WDTCONbits.WDTWINEN = 1;

or

WDTCON |= 0x02;


clear bit 1

WDTCONbits.WDTWINEN = 0;

or

WDTCON &= 0xFFFFFFFD;

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 11:45 am
by medelec35
Woops :oops: , silly me not concentrating
I did mean

Code: Select all

OSCCON |= 0b00010000;
sorry.
Of course Ben was correct in the first place so my post should be ignored.

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 12:15 pm
by stefan.erni
I tried both....I mean all the 4...
It shows always 10
sleep3.PNG
(23.69 KiB) Downloaded 2160 times

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 1:10 pm
by Benj
Aha hang on a minute it's a PIC32 isn't it. These are different and you don't have direct write access to registers like on other devices....

Please try this instead.

Code: Select all

_SFR_BIT_SET(&OSCCON, 4);
Fingers crossed this will do it.

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 2:39 pm
by stefan.erni
Hi Ben

We are on the right way, but not finished yet.

I read about the SET/CLR/INV and also about the virtual adress of register....

The command
_SFR_BIT_SET(&OSCCON, 4);
did not change the bit

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 2:54 pm
by stefan.erni
Hi Ben
Some more we have to do....
A write to the OSCCON register requires an unlock sequence first. Refer to the device datasheet for more information on this unlock sequence. Here is an example:
http://microchipdeveloper.com/faq:2131

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 2:58 pm
by Benj
Aha brilliant well found. Is that working better for you now then?

If not maybe try using the register write function.

Code: Select all

//Unlock Combination
_SFR_WRITE(&SYSKEY, 0xAA996655);
_SFR_WRITE(&SYSKEY, 0x556699AA);

// now change the OSCCON register
_SFR_BIT_SET(&OSCCON, 4);

// now lock again
_SFR_WRITE(&SYSKEY, 0x0);

Re: PIC32MZ standby / wakeup is ok, how change it to sleep?

Posted: Fri Oct 26, 2018 3:24 pm
by stefan.erni
Hi Ben

I just copy the code in FC8 and it's working. The powerconsum goes down to 50mA from the complet PIC Board (with a lot of hardware)
Some hardware I have to turn off....
And when I press the ON Button it's starting the board

the terminalprogram shows for the OSCCON register
1 0001 0011 0010 // with the code
1 0001 0010 0010 // without the code

The Code you give me is also working nice.
Thank you for the help.

/*
Enter C code below this comment
*/
SYSKEY = 0xAA996655;
SYSKEY = 0x556699AA;
// now change the OSCCON register
OSCCONbits.SLPEN = 1;
// now lock again
SYSKEY = 0x0;
asm volatile ( "wait" );