dbuezas / lgt8fx

Board Package for Logic Green LGT8F328P LGT8F328D and LGT8F88D
359 stars 90 forks source link

Fixed powerDown-Dps2.ino #282

Closed wollewald closed 1 year ago

wollewald commented 1 year ago

Found a bug in powerDown-Dps2.ino: IOCWK = PORTD2) | PORTD4);

should be

IOCWK = (1<<PORTD2) | (1<<PORTD4);

And some issues in the comments.

LaZsolt commented 1 year ago

Thank you for reviewing the examples. This is an untested example I haven't tested. I tested DPS2 mode without setting wake up sources.

LaZsolt commented 1 year ago

However, a 1-second sleep lasts much longer than 1 second.

wollewald commented 1 year ago

I also found that the parameters for LowPower.adcNoiseReduction() and LowPower.powerDown() in lgt_LowerPower/readme.md do not match the allowed parameters. In the examples it's all good.

I forgot to say: Thank you for your great work on this library! I took a LQFP32 "Pro Mini" MiniEVB, removed the LEDs and the voltage regulator, supplied it with 5 V and tested the sleep modes with regards to the supply current. This is what I found:

power_consumption_in_sleep_modes

Fantastic!

LaZsolt commented 1 year ago

I also found that the parameters for LowPower.adcNoiseReduction() and LowPower.powerDown() in lgt_LowerPower/readme.md do not match the allowed parameters. In the examples it's all good.

The error in readme.md comes from the fact that the datasheet does not seem completely clear, so at first I experimented with more variable parameters than what was included in the final version. For example, switching the main clock to 32kHz did not reduce the current draw in DPS0 or DPS1 mode. The another interesting thing for me was that I measured the same current consumption in both DPS0 and DSP1 modes.

According to my measurement I measured the same current consumption in DPS0/1/2 modes than you.

In a few days I will merge your changes.

LaZsolt commented 1 year ago

I took a LQFP32 "Pro Mini" MiniEVB, removed the LEDs ....

I wrote the examples so that if you don't remove the LED off from D13 output you still measure the same current values in DPS0/1 modes. But not in DPS2 mode.

wollewald commented 1 year ago

You are right. In order to test your examples it makes no sense to remove the LEDs. But the purpose of my tests was different. I wanted to measure how far you get down in power consumption. And for this I didn't want that any LED would comsume power. I tested the different sleep modes with this sketch by uncommenting the relevant lines:

#include "lgt_LowPower.h"

void setup()
{
  // Pin settings for low consumption in sleep mode.
    DDRB  = 0x00;                 // Set all pins to input
    DDRC  = 0x00;
    DDRD  = 0x00;
    DDRE  = 0x00;
    PORTB = 0xFF;                 // Set all input with internal pull up resistors
    PORTC = 0xFF;
    PORTD = 0xFF;
    PORTE = 0xFF;
//    IOCWK = (1<<PORTD4);  // for deepSleep2 mode 
}

void loop() {
    delay(10000); // To get stable power consumption in active mode

//    LowPower.idle(SLEEP_32S,ADC_OFF,TIMER3_OFF,TIMER2_OFF,TIMER1_OFF,TIMER0_OFF,
//    SPI_OFF,USART0_OFF,TWI_OFF,PCIC_OFF,FLASHCTL_OFF);

//    LowPower.adcNoiseReduction(SLEEP_32S, ADC_ON, TIMER2_OFF);

//    LowPower.powerStandby(SLEEP_FOREVER, ADC_OFF, BOD_OFF, TIMER2_OFF);  

//    LowPower.powerExtStandby(SLEEP_FOREVER, ADC_OFF, BOD_OFF, TIMER2_OFF);

    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

//    LowPower.deepSleep2(SLEEP_FOREVER);

}
dbuezas commented 1 year ago

The CI broke somehow, I'll fix it soon and release

dbuezas commented 1 year ago

released