Type of powering

Hello,

I mean this example:

  • Core unit powered by MicroUSB and Mini Battery module with batteries attached into it.
  • I understand, when current is supplied by MicroUSB, batteries are not used at this moment.
  • When MicroUSB is disconnected or without current, batteries will act.

Is it possible to get information from SDK which type of powering is currently used?

Thanks.

Hello,

A) bc_system_get_vbus_sense

you can use bc_system_get_vbus_sense() but this signal is from FTDI and it reacts to USB enumeration, no to the USB power. So it will detect computer, but not charger.

However I read here that it could be reconfigured in FTDI, not sure.

B) Read analog voltage VDD

read analog voltage of VDD pin. When the system is powered by batterry, you read around 3.1V, when from USB you read 3.29 V. I connected VDD pin on Core Module to P4 pin and here is the example:

#include <application.h>

// Find defailed API description at https://sdk.hardwario.com/

// LED instance
bc_led_t led;

float gadc;

static void _adc_event_handler(bc_adc_channel_t channel, bc_adc_event_t event, void *param)
{
    (void) channel;
    (void) param;

    if (event == BC_ADC_EVENT_DONE)
    {
        float adc;
        bc_adc_async_get_voltage(BC_ADC_CHANNEL_A4, &adc);
        if (adc > 3.25)
        {
            bc_led_set_mode(&led, BC_LED_MODE_ON);
        }
        else
        {
            bc_led_set_mode(&led, BC_LED_MODE_BLINK_FAST);
        }
    }
}

// Application task function (optional) which is called peridically if scheduled
void application_task(void)
{
    bc_adc_async_measure(BC_ADC_CHANNEL_A4);
    bc_scheduler_plan_current_from_now(1000);
}


// Application initialization function which is called once after boot
void application_init(void)
{
    bc_log_init(BC_LOG_LEVEL_DEBUG, BC_LOG_TIMESTAMP_ABS);

    // Initialize LED
    bc_led_init(&led, BC_GPIO_LED, false, 0);
    bc_adc_set_event_handler(BC_ADC_CHANNEL_A4, _adc_event_handler, NULL);

    bc_adc_init();
}

C) BATT_OFF gpio pin

This signal is 5V when the USB power is connected. You can wire it to the GPIO P6 or P7 which can handle 5V signals. If you connect 5V to ADC GPIOs you can damage the pins.
Check the pinout on developers page.

This solution is better then reading ADC value.

void application_task(void)
{
    if (bc_gpio_get_input(BC_GPIO_P6))
    {
        bc_led_set_mode(&led, BC_LED_MODE_ON);
    }
    else
    {
        bc_led_set_mode(&led, BC_LED_MODE_BLINK_FAST);
    }

    bc_scheduler_plan_current_from_now(1000);
}

// Application initialization function which is called once after boot
void application_init(void)
{
    bc_log_init(BC_LOG_LEVEL_DEBUG, BC_LOG_TIMESTAMP_ABS);

    // Initialize LED
    bc_led_init(&led, BC_GPIO_LED, false, 0);

    bc_gpio_init(BC_GPIO_P6);
    bc_gpio_set_mode(BC_GPIO_P6, BC_GPIO_MODE_INPUT);
    bc_gpio_set_pull(BC_GPIO_P6, BC_GPIO_PULL_DOWN);
}
2 Likes