Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Sleep mode test with PIC12F1840

Status
Not open for further replies.

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,461
Helped
296
Reputation
592
Reaction score
280
Trophy points
1,363
Location
France 01800
Activity points
10,476
Hello,

I made a test to evaluate the sleep mode with a PIC12F1840
I used WDT timeout to wake up at every 34 secondes


After deeply reading the datasheet , i fund that after going in "sleep mode"
to wake up the MCU by incomming carcatere on UART, it needs a special caractere
"BREAK car" wich is made of all bits at 0 value.. so car =0x00.

I tried this solution and fund it doesn't works every times.. so i sended 2 car at 0 values
to be sure to go out sleep mode.. and it's works !
I don't know wile i need to send 2 car (0 value)..maybe because FiFo in UART Hardware ?


My first test was not a good example , because the main consumption is the LCD 4x20 + Backlight
(with this LCD, we can't see anything without back light!)
so for this case, i added an external circuit with a Mosfet to drive the BackLight Led
with is the main consumption (~30mA).
My PIC (DIP8) doesn't have any extra output (i allready use UART + I2C => 4 pins)
because the remaining pin RA3 can only be used as input ..
another way : use of TX output to drive the mosfet. in my software i allways send echo when i receive
a carcaterer (Break or other commande)..
in the main loop, i also sens ADC measure to UART..
so LCD backlight is ON every time i send a commande to the PIC trough UART ( via PC terminal)
or when it goes out of sleep, after WDT elapsed time.


link to this test ( Hardware & software mikroC )
nota: i don't have ISIS simultaor , so only real world to test it.


My question :
I know , i have to do another test to see the effect of sleep mode
concerning the lowest main consumption...
Does someone allready use the wake up by incomming car on UART ?
is it by a similar way i used ? or other..
 

I have used sleep mode and UART to wake PIC18F46K22 from sleep and then print some data to UART. It works fine. I sent BREAK character from Realterm and then send a characater like 'W' to wakeup PIC from sleep and print some data to UART. I did this in mikroC PRO PIC.

Not related to your issue. You can use CopyConst2Ram() function for strings used for UART and LCD. You can place the strings in ROM and bring it to RAM when needed. PIC12F has less RAM, So, it is better to use CopyConst2Ram().

https://www.mikroe.com/forum/viewtopic.php?f=13&t=23669&p=119155&hilit=CopyConst2Ram#p119155
 
Last edited:

Hello Milan,

I have used sleep mode and UART to wake PIC18F46K22 from sleep and then print some data to UART. It works fine. I sent BREAK character from Realterm and then send a characater like 'W' to wakeup PIC from sleep and print some data to UART. I did this in mikroC PRO PIC.

is your BREAK character the value 0x00 ?
Do you send your 'W' char collapsed to BREAK, or in another invoice ?
What about comsumption decreasing when in sleep state ,in your case ?

To don't use too much RAM for displayng Texte,i use this
Code:
I2C_LCD_Out(2,1,(const char *)"Init Interrupts TMR2");
This behavior is the same as using CopyConst2Ram.... but more easy,
so it don't use the RAM space because TEXT is stored in code area .
 

is your BREAK character the value 0x00 ?

I don't know. I used Realterm. It has a button to send BREAK character. I didn't check what value it sent. I sent 'W' after sending BREAK character. So, one character is sent at a time.

What about comsumption decreasing when in sleep state ,in your case ?

What do you mean by that ? Are you asking about PIC's power consumption in sleep mode ? If yes, I didn't check it. I was just learning to use sleep command.

To don't use too much RAM for displayng Texte,i use this

I am not sure about this. Does casting a string to const char* really store it in ROM ? I have to check that.

- - - Updated - - -

Made a quick test and it works. Try my attached mikroC PRO PIC project. See image. In image see Realterm window. In green it shows that I sent BREAK and W and it printed 'W' Received.

If you put
Code:
asm sleep
inside while(1) loop then you need to send two characters and then 'W'. I put sleep instruction before entering while(1) loop.

If sleep instruction is put inside while(1) loop then when BREAK is received it doesn't match with 'W'. So, the PIC wakes and then goes to sleep again but I don't know how when two BREAK's are sent and then 'W' is sent it prints "'W' Received".

Code:
char uart_rd = 0;

void interrupt() {
     if(RCIF_bit) {
          if(OERR_bit) {
                OERR_bit = 0;
                CREN_bit = 0;
                CREN_bit = 1;          
          }
     
          uart_rd = UART1_Read();     
     
          RCIF_bit = 0;
     }
}

void main() {

     CM1CON0 = 0x00;
     ANSELA = 0x00;
     TRISA = 0x02;
     PORTA = 0x00;
     LATA = 0x00;
     
     UART1_Init(9600);
     Delay_ms(200);
     UART1_Write_Text("Send BREAK character and 'W' to wake up PIC from Sleep\r\n");
     
     RCIE_bit = 1;
     PEIE_bit = 1;
     GIE_bit = 1;
     WUE_bit = 1;
     RCIF_bit = 0;
     
     asm sleep
     
     while(1) {     
           
           if(uart_rd == 'W') {
                  UART1_Write_Text("'W' Received\r\n");
                  uart_rd = 0;   
           }     
     }
}

broken link removed

It shows 0x03 is the BREAK character.
 

Attachments

  • PIC Sleep Test.rar
    78.4 KB · Views: 33
  • sleep.png
    sleep.png
    56.6 KB · Views: 78
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top