• PCB Bringup

    Theo03/07/2024 at 21:48 0 comments

    I received the PCBs from JLCPCB which look great, however I have found some issues with the board:

    • The TPS61023 boost converter IC I selected will operate down to 0.5V input, but I managed to overlook the point where it states that it requires 1.8V to startup. This means It won't turn on when an AAA cell is inserted. I have found a workaround to continue testing the rest of the board by briefly applying around 2V to the terminals of the cell to allow it to start up, after which it can be removed and the converter will continue to work properly. In a future board revision I will need to use a different IC.
    • The pin I selected for the pulse interrupt is not in the RTC domain, for now I will just bridge it to the adjacent GPIO pin which is in the correct domain.
    • There were 2 tracks unconnected in the PCB layout, somehow I missed the DRC error, fortunately they were an easy bodge with a blob of solder.

    Otherwise the board seems to work, the USB connection for programming works properly.

    I have not yet received the phototransistor so that part is not yet tested, but I have flashed an esphome config file and it seems to run as expected.

    The PCB includes an NTC for temperature measurement, and also a connection for monitoring the battery voltage. Screenshots show the logging in home assistant of the sensor readings over a few hours. The board can also have applications as a battery powered temperature monitor, for locations without grid power such as the loft or greenhouse.

    The current config used for esphome.
    esphome:
      name: aaa
      friendly_name: aaa
      on_boot:
        priority: 600
        then:
          - repeat:
              count: 100
              then:
                - output.turn_on: led_output
                - delay: 0.2s
                - output.turn_off: led_output
                - delay: 1s
    
    esp32:
      board: adafruit_qtpy_esp32c3
      framework:
        type: arduino
    
    output:
      - platform: gpio
        pin: 10
        id: led_output
        
    sensor:
      - platform: ntc
        sensor: resistance_sensor
        calibration:
          b_constant: 4419
          reference_temperature: 25°C
          reference_resistance: 100kOhm
        name: NTC Temperature
        
      - platform: resistance
        id: resistance_sensor
        sensor: source_sensor
        configuration: DOWNSTREAM
        resistor: 100kOhm
    
      - platform: adc
        id: source_sensor
        pin: 3
        attenuation: 11dB
        update_interval: 10s
    
      - platform: adc
        pin: 2
        name: "Battery Voltage"
        update_interval: 10s
        unit_of_measurement: "V"
        attenuation: 11dB
    
    deep_sleep:
      run_duration: 30s
      sleep_duration: 10min

  • Pulse counting (part 2)

    Theo03/01/2024 at 16:47 0 comments

    After testing if the ESP32-C3 could wake from a rising edge GPIO, it does not seem to work. The datasheet was a bit ambiguous, but after writing the RTC_CNTL_GPIO_WAKEUP_REG for edge trigger the MCU would not wake when a signal was applied to the GPIO pin.


    I will instead use the level triggered interrupt and upon waking from sleep invert the level chosen for triggering the interrupt. This means the CPU will wake for both the rising edge and falling edge of the pulse but will still spend most of the time asleep.

    void RTC_DATA_ATTR wake_stub_sleep_counter(void)
    {
        wakeup_cause = esp_wake_stub_get_wakeup_cause();
        if(wakeup_cause & 0x04)
        {
            // Wakeup cause GPIO
            ++wake_count;
            intr_type = intr_type == GPIO_INTR_HIGH_LEVEL ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL;
            gpio_ll_deepsleep_wakeup_enable(&GPIO, GPIO_NUM_4, intr_type);
            // Go back to sleep
            esp_wake_stub_sleep(&wake_stub_sleep_counter);
        }
        else
        {
            esp_default_wake_deep_sleep();
            // Return from the wake stub function to continue
            // booting the firmware.
            return;
        }
    
    } 


    I measured the time taken for the ESP32-C3 to wake and return to sleep as 12.4ms, using a 1 ohm resistor inline with the power supply, showing the current draw in this mode to be around 8.4mA. Assuming an average of 1 pulse counted per second, we can estimate the battery  life running from a 800mA 1.2V AAA not counting the wakeups to connect to WiFi.

    0.8*1.2=0.96Wh
    3.3*8.4e-3=0.0277W
    0.97/0.277=34.63H (if on continuously)
    34.6/(12.4e-3*2)=1395Hours (if one pulse per second on average)

  • Pulse counting interrupt

    Theo02/24/2024 at 22:45 0 comments

    The ESP32 has an pulse counting peripheral which would ideal for counting the LED pulses on a electricity meter, unfortunately it does not operate in deep sleep so will consume to much energy to allow for a decent battery life.

    Instead I plan to configure an input pin to wake the CPU, which can then increment a variable before going back to sleep. The ESP32 normally executes code from an SPI flash, but can keep a small amount of code in the RTC RAM that can be executed after waking from sleep without powering up the flash, which I plan to use for the variable incrementing code. This means the CPU can be awake for less time saving power.

    The ESP32-C3 reference manual indicates that it supports wake on rising edge which would be the best option, however the esp-idf library seems to indicate that it is not supported so I will have to test this.