• AVR Freaks

Hot!abnormally high current in pic24fj64ga702 based circuit

Author
soleil_sword
Starting Member
  • Total Posts : 47
  • Reward points : 0
  • Joined: 2009/03/12 14:03:59
  • Location: 0
  • Status: offline
2019/05/30 09:43:22 (permalink)
0

abnormally high current in pic24fj64ga702 based circuit

Hi there, I'm having a trouble with an abnormally high current in a pic24fj64ga702 based circuit.
 
So the circuit consists of pic24fj64ga702 + a few sensors, flash and other components. I'm trying to see what the minimal current consumption is and determine the battery life. 
My approach is to put the device to sleep mode, and enable them one by one to determine their current individually.
Right now all the devices are in sleep mode, however I measured a 4 mA, which is insanely high...
 
I'm wondering if you guys have some sort of ideas what's going on.
thanks a lot!
#1

16 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3065
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/05/30 13:17:38 (permalink)
    4.5 (2)
    We are not here to amuse you by wild guessing.
    Start with supplying the schematics and the BOM!

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    MBedder
    Circuit breaker
    • Total Posts : 6796
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/05/31 10:16:49 (permalink)
    5 (1)
    Not only. The very start is learning how the CMOS IC work and why their input pins should never have left floating.
    #3
    soleil_sword
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2009/03/12 14:03:59
    • Location: 0
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/26 10:27:29 (permalink)
    0
    thank you for both of your comments, a lot has been improved. Right now I'm getting a sleep current of 8 uA, which is not as low as specified in the datasheet, but it is somewhat acceptable. 
    WHat I have problem is the idle current during operation when my system is not doing anything (just a while loop). My system is consuming ~ 3 mA in this case, but my code is already complicated to debug, then I decided to start from scratch with a minimalist code.
     
    I used MPLab code configurator to generate a simplist code, my system is running at LPRC (31 kHz internal clock), which according to the datasheet should consume around 100 uA, however I'm consuming around 1 mA. Please see the below system generated code which I believe have set most of the ports correctly. I have no clue what is going on that the current is way higher than I expected; my system is connected to a motion sensor with I2C, but that sensor by default consumes a few tens of uA; I also have an analog sensor which also consumes a few tens of uA; so it seems to me that the current is really consumed by the microcontroller itselt;
     
     

    // FSEC
    #pragma config BWRP = OFF //Boot Segment Write-Protect bit->Boot Segment may be written
    #pragma config BSS = DISABLED //Boot Segment Code-Protect Level bits->No Protection (other than BWRP)
    #pragma config BSEN = OFF //Boot Segment Control bit->No Boot Segment
    #pragma config GWRP = OFF //General Segment Write-Protect bit->General Segment may be written
    #pragma config GSS = DISABLED //General Segment Code-Protect Level bits->No Protection (other than GWRP)
    #pragma config CWRP = OFF //Configuration Segment Write-Protect bit->Configuration Segment may be written
    #pragma config CSS = DISABLED //Configuration Segment Code-Protect Level bits->No Protection (other than CWRP)
    #pragma config AIVTDIS = OFF //Alternate Interrupt Vector Table bit->Disabled AIVT

    // FBSLIM
    #pragma config BSLIM = 8191 //Boot Segment Flash Page Address Limit bits->8191

    // FOSCSEL
    #pragma config FNOSC = LPRC //Oscillator Source Selection->Low-Power RC Oscillator (LPRC)
    #pragma config PLLMODE = DISABLED //PLL Mode Selection->No PLL used; PLLEN bit is not available
    #pragma config IESO = OFF //Two-speed Oscillator Start-up Enable bit->Start up with user-selected oscillator source

    // FOSC
    #pragma config POSCMD = NONE //Primary Oscillator Mode Select bits->Primary Oscillator disabled
    #pragma config OSCIOFCN = OFF //OSC2 Pin Function bit->OSC2 is clock output
    #pragma config SOSCSEL = OFF //SOSC Power Selection Configuration bits->Digital (SCLKI) mode
    #pragma config PLLSS = PLL_PRI //PLL Secondary Selection Configuration bit->PLL is fed by the Primary oscillator
    #pragma config IOL1WAY = ON //Peripheral pin select configuration bit->Allow only one reconfiguration
    #pragma config FCKSM = CSDCMD //Clock Switching Mode bits->Both Clock switching and Fail-safe Clock Monitor are disabled

    // FWDT
    #pragma config WDTPS = PS512 //Watchdog Timer Postscaler bits->1:32768
    #pragma config FWPSA = PR128 //Watchdog Timer Prescaler bit->1:128
    #pragma config FWDTEN = OFF //Watchdog Timer Enable bits->WDT and SWDTEN disabled
    #pragma config WINDIS = OFF //Watchdog Timer Window Enable bit->Watchdog Timer in Non-Window mode
    #pragma config WDTWIN = WIN25 //Watchdog Timer Window Select bits->WDT Window is 25% of WDT period
    #pragma config WDTCMX = WDTCLK //WDT MUX Source Select bits->WDT clock source is determined by the WDTCLK Configuration bits
    #pragma config WDTCLK = LPRC //WDT Clock Source Select bits->WDT uses LPRC

    // FPOR
    #pragma config BOREN = ON //Brown Out Enable bit->Brown Out Enable Bit
    #pragma config LPCFG = OFF //Low power regulator control->No Retention Sleep
    #pragma config DNVPEN = ENABLE //Downside Voltage Protection Enable bit->Downside protection enabled using ZPBOR when BOR is inactive

    // FICD
    #pragma config ICS = PGD1 //ICD Communication Channel Select bits->Communicate on PGEC1 and PGED1
    #pragma config JTAGEN = OFF //JTAG Enable bit->JTAG is disabled

    // FDEVOPT1
    #pragma config ALTCMPI = DISABLE //Alternate Comparator Input Enable bit->C1INC, C2INC, and C3INC are on their standard pin locations
    #pragma config TMPRPIN = OFF //Tamper Pin Enable bit->TMPRN pin function is disabled
    #pragma config SOSCHP = ON //SOSC High Power Enable bit (valid only when SOSCSEL = 1->Enable SOSC high power mode (default)
    #pragma config ALTI2C1 = ALTI2CEN //Alternate I2C pin Location->SDA1 and SCL1 on RB9 and RB8




    int main(void)
    {
        // initialize the device
        SYSTEM_Initialize();

        _LATA4 = 1;

        while (1)
        {
        }

        return 1;
    }


    void SYSTEM_Initialize()
    {
    /****************************************************************************
    * Setting the Output Latch SFR(s)
    ***************************************************************************/
    LATA = 0x0000;
    LATB = 0x0000;

    /****************************************************************************
    * Setting the GPIO Direction SFR(s)
    ***************************************************************************/
    TRISA = 0x0007;
    TRISB = 0xBFFF;

    /****************************************************************************
    * Setting the Weak Pull Up and Weak Pull Down SFR(s)
    ***************************************************************************/
    IOCPDA = 0x0000;
    IOCPDB = 0x0000;
    IOCPUA = 0x0000;
    IOCPUB = 0x0000;

    /****************************************************************************
    * Setting the Open Drain SFR(s)
    ***************************************************************************/
    ODCA = 0x0000;
    ODCB = 0x0000;

    /****************************************************************************
    * Setting the Analog/Digital Configuration SFR(s)
    ***************************************************************************/
    ANSA = 0x0007;
    ANSB = 0xB20C;


    // CPDIV 1:1; PLLEN disabled; DOZE 1:8; RCDIV FRC; DOZEN disabled; ROI disabled;
    CLKDIV = 0x3000;
    // STOR disabled; STORPOL Interrupt when STOR is 1; STSIDL disabled; STLPOL Interrupt when STLOCK is 1; STLOCK disabled; STSRC SOSC; STEN disabled; TUN Center frequency;
    OSCTUN = 0x00;
    // ROEN disabled; ROSWEN disabled; ROSEL FOSC; ROOUT disabled; ROSIDL disabled; ROSLP disabled;
    REFOCONL = 0x00;
    // RODIV 0;
    REFOCONH = 0x00;
    // DCOTUN 0;
    DCOTUN = 0x00;
    // DCOFSEL 8; DCOEN disabled;
    DCOCON = 0x700;
    // DIV 0;
    OSCDIV = 0x00;
    // TRIM 0;
    OSCFDIV = 0x00;
    // AD1MD enabled; T3MD enabled; T1MD enabled; U2MD enabled; T2MD enabled; U1MD enabled; SPI2MD enabled; SPI1MD enabled; I2C1MD enabled;
    PMD1 = 0x00;
    // IC3MD enabled; OC1MD enabled; IC2MD enabled; OC2MD enabled; IC1MD enabled; OC3MD enabled;
    PMD2 = 0x00;
    // PMPMD enabled; RTCCMD enabled; CMPMD enabled; CRCMD enabled; I2C2MD enabled;
    PMD3 = 0x00;
    // CTMUMD enabled; REFOMD enabled; LVDMD enabled;
    PMD4 = 0x00;
    // CCP2MD enabled; CCP1MD enabled; CCP4MD enabled; CCP3MD enabled; CCP5MD enabled;
    PMD5 = 0x00;
    // SPI3MD enabled;
    PMD6 = 0x00;
    // DMA1MD enabled; DMA0MD enabled;
    PMD7 = 0x00;
    // CLC1MD enabled; CLC2MD enabled;
    PMD8 = 0x00;
    // CF no clock failure; NOSC LPRC; SOSCEN disabled; POSCEN disabled; CLKLOCK unlocked; OSWEN Switch is Complete; IOLOCK not-active;
    __builtin_write_OSCCONH((uint8_t) (0x05));
    __builtin_write_OSCCONL((uint8_t) (0x00));
    }

    post edited by soleil_sword - 2019/06/26 10:29:50
    #4
    skruegel1
    Starting Member
    • Total Posts : 78
    • Reward points : 0
    • Joined: 2017/02/04 03:32:13
    • Location: 0
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/26 11:20:55 (permalink)
    0
    If you used FreeRTOS, you could use the idle task to enter sleep.
     
     
    #5
    du00000001
    Just Some Member
    • Total Posts : 3065
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/26 12:03:41 (permalink)
    0
    You have to disable all (currently) unused peripheral modules to get these low current values!
    From what I seem to see, you still have a lot of peripherals powered.
    DOZEN = 0 doesn't help either.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    soleil_sword
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2009/03/12 14:03:59
    • Location: 0
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/26 13:36:24 (permalink)
    0
    du00000001
    You have to disable all (currently) unused peripheral modules to get these low current values!
    From what I seem to see, you still have a lot of peripherals powered.
    DOZEN = 0 doesn't help either.


    PMD1 - PMD8 are all set to 0x00 during initialization.
    what peripherals are you specifically talking about and what commands to disable them?
    #7
    du00000001
    Just Some Member
    • Total Posts : 3065
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/26 13:41:48 (permalink)
    5 (1)
    PMDx are set to 0x00, the comments say ... Enabled.
     
    What makes perfect sense as PMD is Peripheral Module Disable.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #8
    soleil_sword
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2009/03/12 14:03:59
    • Location: 0
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/26 17:21:31 (permalink)
    0
    du00000001
    PMDx are set to 0x00, the comments say ... Enabled.
     
    What makes perfect sense as PMD is Peripheral Module Disable.


    oops... You nailed.
     
    Now I got a little current lower and I found another really strange thing.
    So basicly I have an external 10 MHz clock running. And I first disabled everything:
     
    PMD1 = 0b0011100011111001; //all disabled
    PMD2 = 0b0000011100000111; //all disabled
    PMD3 = 0b0000011110000010; //all disabled
    PMD4 = 0b0000000000001110; //all disabled
    PMD5 = 0b0000000000001111; //all disabled
    PMD6 = 0b0000000000000001; //all disabled
    PMD7 = 0b0000000000110000; //all disabled
    PMD8 = 0b0000000000001100; //all disabled
     
    When I enabled PMD1 = 0, I have a current of about 2.36 mA doing a sensor data measurement. this sensor uses I2C, and I'm using timer 2 and 3 and uart for some functions. In principle, I could do something like following:
    PMD1 = 0b0000100000011001;
    However setting PMD1 to 0b0000100000011001 instead of 0 increases my current to 2.5 mA, which totally makes no sense to me...
     
    do you have suggestions for this please?
    #9
    du00000001
    Just Some Member
    • Total Posts : 3065
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/26 23:20:39 (permalink)
    0
    What do you measure: the microcontroller's consumption or the consumption of the whole setup?
    And how?
    I2C involves at least 2 pull-ups. Depending on I2C speed, these might add significantly to power consumption. And the sensor? etc. pp.
     
    What are you? Student?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #10
    soleil_sword
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2009/03/12 14:03:59
    • Location: 0
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/27 07:52:18 (permalink)
    0
    du00000001
    What do you measure: the microcontroller's consumption or the consumption of the whole setup?
    And how?
    I2C involves at least 2 pull-ups. Depending on I2C speed, these might add significantly to power consumption. And the sensor? etc. pp.
     
    What are you? Student?




    Measurement Setup: Connect a multimeter in series Between the power supply and VDD.
    I'm measuring the whole system including the sensor. The sensor is a low power pressure sensor which consumes ~ 50 uA. And I'm running I2C at 400 kHz. The sensor is functioning correctly, and I could read sensor data without problem.
    My previous question was: I first disable all the PMDs (PMD1-PMD8), right before I do my sensor measurement I enable the required modules. All I need is I2C, timer and UART (for printing) so I should do the following:
    PMD1 = 0b0000100000011001;
    After doing this I consume 2.5 mA and the sensor is functioning.
    If I the following:
    PMD1 = 0; 
    My system is also working but I consume 2.35 mA. Which doesn't make sense to me because by enabling more modules, I consume less current.
     
     
     
    #11
    Howard Long
    Super Member
    • Total Posts : 706
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/27 08:47:54 (permalink)
    0
    In this case, breadboard your device with the absolute minimum of external parts, just decoupling caps, a 10k pullup on MCLR and an ICD header.
     
    Be aware that having a debugger or programmer connected will affect your power consumption figures very significantly at the lower end: in that case you need to measure current without the debugger or programmer connected.
     
    In your config settings, make sure you have the OSCIOFCN bit set so you can use a scope to see if the oscillator is running or not, and at what speed.
     
    Most of the time it's possible to get the Typ current figures in the datasheet, although occasionally there are typos.
     
    When I'm back in the lab I'll see if I have one of these devices and if so I'll put something together.
    #12
    du00000001
    Just Some Member
    • Total Posts : 3065
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/27 09:02:19 (permalink)
    0
    Re: ... Which doesn't make sense. ...
     
    Be careful: if there are interdependencies between the modules (I didn't check in detail), an unpowered module might load the output of a powered module. And this loading could be more than the normal supply of the module itself. (Just loading the respective output with a (protective) diode vs. GND.)
     
    So, if PMD1=0 results in a lower power consumption: use it.
    Or check interdependencies to see, which of the peripheral modules has the interconnect and does the loading :)
     
    Let me see: in PMD1, there are (according to the comments)
    AD1MD    - shouldn't hurt to disable
    T3MD     
    T1MD
    U2MD      - UART2? shouldn't hurt as well
    T2MD      
    U1MD      - this one required?
    SPI2MD   - ???
    SPI1MD   - ???
    I2C1MD   - required
     

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #13
    soleil_sword
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2009/03/12 14:03:59
    • Location: 0
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/27 11:05:10 (permalink)
    0
    du00000001
    Re: ... Which doesn't make sense. ...
     
    Be careful: if there are interdependencies between the modules (I didn't check in detail), an unpowered module might load the output of a powered module. And this loading could be more than the normal supply of the module itself. (Just loading the respective output with a (protective) diode vs. GND.)
     
    So, if PMD1=0 results in a lower power consumption: use it.
    Or check interdependencies to see, which of the peripheral modules has the interconnect and does the loading :)
     
    Let me see: in PMD1, there are (according to the comments)
    AD1MD    - shouldn't hurt to disable
    T3MD     
    T1MD
    U2MD      - UART2? shouldn't hurt as well
    T2MD      
    U1MD      - this one required?
    SPI2MD   - ???
    SPI1MD   - ???
    I2C1MD   - required
     


     
    Yes the ones I need for this sensor read are: 
    bit 13: T3MD
    bit 12: T2MD
    bit 7: I2C1MD
    bit 5: U1MD
     
    ADC, SPI, UART2 and Timer1 are the ones that I tried to disable but resulted in higher current.
    I have tried to disable them one by one, but like you said I felt there were some interdependencies that only by settting PMD1=0 I got the lowest current (2.35 mA).
    #14
    soleil_sword
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2009/03/12 14:03:59
    • Location: 0
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/27 11:09:14 (permalink)
    0
    Howard Long
    In this case, breadboard your device with the absolute minimum of external parts, just decoupling caps, a 10k pullup on MCLR and an ICD header.
     
    Be aware that having a debugger or programmer connected will affect your power consumption figures very significantly at the lower end: in that case you need to measure current without the debugger or programmer connected.
     
    In your config settings, make sure you have the OSCIOFCN bit set so you can use a scope to see if the oscillator is running or not, and at what speed.
     
    Most of the time it's possible to get the Typ current figures in the datasheet, although occasionally there are typos.
     
    When I'm back in the lab I'll see if I have one of these devices and if so I'll put something together.




    appeciate your help. Yes all my measurements were done with the programmer disconnected (the programmer consumes ~ 4 mA by itself).
     
    I was able to get a typical current figure close to the datasheet both in sleep or idle when I had all modules disconnected (PMD1-PMD8) as shown in one of my previous post. The main problem I have now is to minimize the active current during operations such as sensor reading (I2C sensors, analog sensors), flash writing (SPI) and etc. That was why I tried to use PMD registers to disable all the modules, and only enable the required ones each time before a specific funtion starts to run.
    #15
    Howard Long
    Super Member
    • Total Posts : 706
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/28 00:40:53 (permalink)
    0
    I had a brief look at this last night with a PIC24FJ256GA702, the same as your device but with more memory.
     
    I agree that there is something amiss, you should certainly be able to achieve a few 10s of uA on LPRC on the PIC24FJ series: I am seeing about 1.25mA. This kind of current is indicative to me that the FRC may still running.
     
    I'll try to take another look when I get chance, but I'm in the process of moving at the moment so please bear with me.
    #16
    Howard Long
    Super Member
    • Total Posts : 706
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: abnormally high current in pic24fj64ga702 based circuit 2019/06/28 03:31:31 (permalink)
    0
    There is a feature I notice on this device not otherwise common on PICs.
     
    Rather than act as a programmable divider, on this device RCDIV is used to mux various clock sources, including FRC (which is the default at POR). I therefore recommend trying setting RCDIV to 0b101 (LPRC).
     
    (Edit: I have not tried this myself yet).
     
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5