CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how is the deep sleep?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Sun Sep 30, 2018 8:45 am     Reply with quote

Thanks you to everyone.
I have bad the command sleep ... so now the consume its 0.4mA that is good, but no for IoT application... and really the best way is turn off the module.

As I said, the problem is in TX and RX wire... (without pic or module the power its 0.001mA) I put low and still its the same... maybe its problem draw PCB...
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Sep 30, 2018 2:10 pm     Reply with quote

As a comment, all the I/O pins on the LoRa module are floating. This is a classic way of drawing extra current. Try programming all of these as outputs and pulling them low. You may well find the consumption drops significantly.
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Sun Sep 30, 2018 4:28 pm     Reply with quote

Well...

I share this code... I make many test ( to trash 3 PCB)
to end I know my problem is wiht the pin RC7 ....
Well the consume now is 0.008mA

But when I conect the pin RC7 (RX) to (TX module)... the power go to 10mA...

What I need do?

Code:
#include <18LF26K22.H>
#fuses NOWDT, BROWNOUT_NOSL, PUT, NOPBADEN, NOHFOFST, INTRC_IO, MCLR , NOLVP, NOXINST
//HSH.... No. You are using the internal RC, you don't want the HS oscillator
//enabled.
//#fuses WDT_SW         //No Watch Dog Timer, enabled in Software
//Brownout now disabled when sleeping
#use delay(internal=4MHz)
////////////////////  UARTs  ///////////////////////////////
#use rs232(baud=57600,xmit=PIN_c6,rcv=PIN_c7,bits=8,parity=N,ERRORS,stream=lora)   /// UART 1 LORA
#use rs232(baud=57600,xmit=PIN_b6,rcv=PIN_b7,bits=8,parity=N,ERRORS,stream=debug)  /// UART 2 DEBUG
#DEFINE RN2903_RST  PIN_C4    // RESET RN2903
#define LED_CMD PIN_C5 //whatever pin your LED is on
#byte ANSELA=getenv("SFR:ANSELA")
#byte ANSELB=getenv("SFR:ANSELB")
#byte ANSELC=getenv("SFR:ANSELC")
int8 messageReady=0;
int8 moduleBufferIndex=0;
unsigned char moduleResonseBuffer[20]="";
char bufferByte=0x00;
void wakeup();
void blink_led(int);
// global flag to send processor into sleep mode
short sleep_mode;

int act=0;
void main() {   
   
   setup_adc(ADC_OFF); //Otherwise by default this will be controlling B0
   setup_adc_ports(NO_ANALOGS);
   setup_comparator(NC_NC_NC_NC); //disable comparator
   setup_dac(DAC_OFF);
   ANSELA=0;
   ANSELB=0;
   ANSELC=0; //select all pins for digital I/O
   
   output_a(0); //drive all  I/O pins low
   output_b(0); //drive all  I/O pins low
   output_c(0); //drive all  I/O pins low
   
   //ext_int_edge(0,L_TO_H);
   disable_interrupts(global);                     // Habilita interrupciones
   
disable_interrupts(INT_AD);//   Analog to digital conversion complete
disable_interrupts(INT_BUSCOL);  // Bus collision
disable_interrupts(INT_BUSCOL2);//   MSSP2 Bus Collision
disable_interrupts(INT_CCP1);  // Capture or Compare on unit 1
disable_interrupts(INT_CCP2);  // Capture or Compare on unit 2
disable_interrupts(INT_CCP3);  // Capture or Compare on unit 3
disable_interrupts(INT_CCP4); //  Capture or Compare on unit 4
disable_interrupts(INT_CCP5); //  Capture or Compare on unit 5
disable_interrupts(INT_COMP); //  Comparator event
disable_interrupts(INT_COMP2);//   Comparator 2 detect
disable_interrupts(INT_CTMU);  // Cap sense unit
disable_interrupts(INT_EEPROM );//  Write complete
disable_interrupts(INT_EXT); //   External interrupt
disable_interrupts(INT_EXT1); //  External interrupt #1
disable_interrupts(INT_EXT2); //  External interrupt #2
disable_interrupts(INT_HLVD); //  Low-Voltage Detect interrupt
disable_interrupts(INT_OSCF  ); // System oscilator failed
disable_interrupts(INT_RB   ); //Port B any change on B4-B7
disable_interrupts(INT_RDA  ); // RS232 receive data available
disable_interrupts(INT_RDA2); //   RS232 UART 2 receive data available
disable_interrupts(INT_RTCC); //   Timer 0 overflow (using RTCC name)
disable_interrupts(INT_SSP ); //  SPI or I2C activity
disable_interrupts(INT_SSP2 ); //  SPI or I2C activity for Port 2
disable_interrupts(INT_TBE  ); // RS232 transmit buffer empty
disable_interrupts(INT_TBE2); //   RS232 transmit buffer 2 empty
disable_interrupts(INT_TIMER0); //   Timer 0 overflow (using TIMER0 name)
disable_interrupts(INT_TIMER1  ); // Timer 1 overflow
disable_interrupts(INT_TIMER2  ); // Timer 2 overflow
disable_interrupts(INT_TIMER3  ); // Timer 3 overflow
disable_interrupts(INT_TIMER4  ); // Timer 4 overflow
disable_interrupts(INT_TIMER5 ); //  Timer 5 overflow
disable_interrupts(INT_TIMER6 ); //  Timer 6 overflow
disable_interrupts(INT_TMR1G  ); // Timer 1 gate
disable_interrupts(INT_TMR3G  ); // Timer 3 gate
disable_interrupts(INT_TMR5G ); //  Timer 5 gate
   

 fprintf (lora,"sys sleep 4000\r\n");
 delay_ms(6000);    // time to see the consume
 output_low(LED_CMD);         

 enable_interrupts(INT_EXT);// turn on interrupts
 enable_interrupts(GLOBAL);
   
 while(1){ 
 output_toggle(LED_CMD);  // to see when wake up
 delay_ms(500);
 fprintf (lora,"sys sleep 8000\r\n");
 output_low(LED_CMD);                   
 delay_ms(1000);
 sleep();
 delay_cycles(1);
 }
}

void wakeup(){
   setup_uart(FALSE, LORA);    //turn off the UART
   output_low(PIN_C6);         //
   delay_us(250);              //at 57600 174uSec is required for a break
   output_high(PIN_C6);        //
   setup_uart(57600, LORA);    //re-enable the UART
   fputc(0x55,LORA);
   //The lora module will now be awake.
}

// external interrupt when button pushed and released
#INT_EXT
void ext_isr() {
act=1;
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Oct 01, 2018 1:41 am     Reply with quote

Switch off the UART before you try to sleep.
So:
Code:

 fprintf (lora,"sys sleep 8000\r\n");
 delay_ms(1); //Allow time for this to have sent
 setup_uart(FALSE, LORA);    //turn off the UART
 output_low(LED_CMD);                   
 delay_ms(1000);
 sleep();
 delay_cycles(1);


I suspect the sleeping LoRa module is pulling it's TX low. So the PIC UART is seeing a continuous break.
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Mon Oct 01, 2018 2:05 pm     Reply with quote

Ttelmah wrote:
Switch off the UART before you try to sleep.
So:
Code:

 fprintf (lora,"sys sleep 8000\r\n");
 delay_ms(1); //Allow time for this to have sent
 setup_uart(FALSE, LORA);    //turn off the UART
 output_low(LED_CMD);                   
 delay_ms(1000);
 sleep();
 delay_cycles(1);


I suspect the sleeping LoRa module is pulling it's TX low. So the PIC UART is seeing a continuous break.


thank you...The fix it was :

Code:
#use fast_io(C)
set_tris_c(0b10000000);

Now not there short circuit Smile all is ok.


I have one last question....how do you know what time is for the break ...?
Code:

void wakeup(){
   setup_uart(FALSE, LORA);    //turn off the UART
   output_low(PIN_C6);           //
   delay_us(250);                   //at 57600 174uSec is required for a break
   output_high(PIN_C6);          //
   setup_uart(57600, LORA);    //re-enable the UART
   fputc(0x55,LORA);
   //The lora module will now be awake.
}

Sometime not work... so for be sure better I reset the module...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group