Custom PMIC settings for Monitor One

I am not sure if I am doing something wrong nor right with respect to Power Manger settings. I am trying to increase the min. power source voltage so my 12 v (350ma) solar panel will charge the battery and not go into the low voltage state (flashing red on the chrg light). So my questions that I could figure out on my own are.

  1. Does the "SystemPowerConfiguration conf" go into void setup () or void start up ()?
  2. Do you need to call "PMIC power(true);" in void loop ()?
  3. Is there are way to verify the setting with a location call back. (I tried putting PMIC power(true) in the call back and it unit stopped working)?

I am also using Vin on the main board and not one of the expansion boards.

Thank you in advance.

Here is the code below.

#include "Particle.h"
#include "Arduino.h"
#include "edge.h"
#include "SparkFun_ADS1015_Arduino_Library.h"


SYSTEM_THREAD(ENABLED);\
SYSTEM_MODE(SEMI_AUTOMATIC);

#if EDGE_PRODUCT_NEEDED
PRODUCT_ID(EDGE_PRODUCT_ID);
#endif // EDGE_PRODUCT_NEEDED
PRODUCT_VERSION(EDGE_PRODUCT_VERSION);

STARTUP(
    Edge::startup();
);

SerialLogHandler logHandler(115200, LOG_LEVEL_TRACE, {
    { "app.gps.nmea", LOG_LEVEL_INFO },
    { "app.gps.ubx",  LOG_LEVEL_INFO },
    { "ncp.at", LOG_LEVEL_INFO },
    { "net.ppp.client", LOG_LEVEL_INFO },
});
char buf[256];
ADS1015 adcSensor;
void myLocationGenerationCallback(JSONWriter &writer, LocationPoint &point, const void *context);


void setup()
{
	SystemPowerConfiguration conf;

	conf.powerSourceMaxCurrent(900) 
        .powerSourceMinVoltage(4300) 
        .batteryChargeCurrent(850) 
        .batteryChargeVoltage(4210);
	int res = System.setPowerConfiguration(conf);
	Log.info("setPowerConfiguration=%d", res);
	//System.setPowerConfiguration(SystemPowerConfiguration());
	
   

	Serial.begin(9600);
    Edge::instance().init();
	TrackerLocation::instance().regLocGenCallback(myLocationGenerationCallback);


  if (adcSensor.begin() == true)
 {
        Log.error("ADC Successfully Started");
        Particle.publish("Log", "ADC Successfully Started");
 }
 else
 {
   		Log.error("ADC Failed");
  		Particle.publish("Log", "Failed");
 }


}

void loop()
{
Edge::instance().loop();


        //PMIC power(true);
       // Log.info("Current PMIC settings:");
        //Log.info("VIN Vmin: %u", power.getInputVoltageLimit());
        //Log.info("VIN Imax: %u", power.getInputCurrentLimit());
        //Log.info("Ichg: %u", power.getChargeCurrentValue());
       // Log.info("Iterm: %u", power.getChargeVoltageValue());
//delay (11000);

// Testing the ADC module
	//short adc0, adc1, adc2, adc3;
	//adc0 = adcSensor.getSingleEnded(0);
	//adc1 = adcSensor.getSingleEnded(1);
	//adc2 = adcSensor.getSingleEnded(2);
	//adc3 = adcSensor.getSingleEnded(3);
	//Serial.print("AIN0: "); Serial.print(adc0);
	//Serial.print("AIN1: "); Serial.print(adc1);
	//Serial.print("AIN2: "); Serial.print(adc2);
	//Serial.print("AIN3: "); Serial.print(adc3);
	//delay (2000);
  }


void myLocationGenerationCallback(JSONWriter &writer, LocationPoint &point, const void *context)
{
int PB1 = adcSensor.getSingleEnded(0);
int PB2 = adcSensor.getSingleEnded(1);
int PB3 = adcSensor.getSingleEnded(2);

String Bearing1;
String Bearing2;
String Bearing3;


writer.name("Bearings").beginObject();
writer.name("PB1").value(PB1);
writer.name("PB2").value(PB2);
writer.name("PB3").value(PB3);
writer.endObject();

if (PB1 > 1200 && PB1 <3200)
	{
		Bearing1 = "Running";
	}
	else
	{
		Bearing1 = "Failed";
	}
if (PB2 > 1200 && PB2 <3200)
	{
		Bearing2 = "Running";
	}
	else
	{
		Bearing2 = "Failed";
	}
if (PB3 > 1200 && PB3 <3200)
	{
		Bearing3 = "Running";
	}
	else
	{
		Bearing3 = "Failed";
	}	

Particle.publish("Bearing 1=", Bearing1, PRIVATE | WITH_ACK);
Particle.publish("Bearing 2=", Bearing2, PRIVATE | WITH_ACK);
Particle.publish("Bearing 3=", Bearing3, PRIVATE | WITH_ACK);



}
  1. Setup is good.
  2. See below for an example.
  3. From docs:

void loop() {
{
PMIC power(true);
Log.info("Current PMIC settings:");
Log.info("VIN Vmin: %u", power.getInputVoltageLimit());
Log.info("VIN Imax: %u", power.getInputCurrentLimit());
Log.info("Ichg: %u", power.getChargeCurrentValue());
Log.info("Iterm: %u", power.getChargeVoltageValue());

    int powerSource = System.powerSource();
    int batteryState = System.batteryState();
    float batterySoc = System.batteryCharge();

    constexpr char const* batteryStates[] = {
        "unknown", "not charging", "charging",
        "charged", "discharging", "fault", "disconnected"
    };
    constexpr char const* powerSources[] = {
        "unknown", "vin", "usb host", "usb adapter",
        "usb otg", "battery"
    };

    Log.info("Power source: %s", powerSources[std::max(0, powerSource)]);
    Log.info("Battery state: %s", batteryStates[std::max(0, batteryState)]);
    Log.info("Battery charge: %f", batterySoc);
}

Thank you. It seems to be working. Is there any risk with inserting PMIC Power(true) into mylocationGenerationCallback? I wanted the battery and charging information to be part of the loc callback when I put the unit to sleep.

Thanks

Jon

You should be able to do that from the location generation callback.

1 Like

I was able to add those to the my location callback. Thanks for all the help.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.