Author Topic: Simblee getting input voltage  (Read 3160 times)

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 126
  • Karma: +2/-0
    • View Profile
Simblee getting input voltage
« on: May 16, 2016, 12:49:48 PM »
Hi ..

The Simblee datasheet lists "Battery/Supply voltage monitoring" as a feature. I haven't seen documentation to describe implementing it. For RFduino, we implemented battery level with this code:

Code: [Select]
    unsigned long batteryLevel;
   
    analogSelection(VDD_1_3_PS);  //Selects VDD with 1/3 prescaling as the analog source
    delay(100);  // Might help with stability of next analogRead
    int sensorValue = analogRead(1); // the pin has no meaning, it uses VDD pin
    float batteryVoltage = sensorValue * (3.6 / 1023.0); // convert value to voltage
   
    analogSelection(AIN_1_3_PS); // Selects the ananlog inputs with 1/3 prescaling as the analog source
    delay(100);  // Might help with stability of next analogRead
   
    batteryLevel = batteryVoltage * 1000; // millivolts

This method is not always accurate. Hoping Simblee offers a better solution. We're powering Simblee with 2 AA batteries.

Any experience with this?

Many thanks,

Tim

tolson

  • Global Moderator
  • *****
  • Posts: 880
  • Karma: +21/-0
    • View Profile
    • Thomas Olson Consulting
Re: Simblee getting input voltage
« Reply #1 on: May 16, 2016, 01:54:12 PM »
Hi Tim,

The Simblee datasheet lists "Battery/Supply voltage monitoring" as a feature. I haven't seen documentation to describe implementing it.

I think that 'feature' just means that VDD can be internally connected to the built-in ADC.

Quote
For RFduino, we implemented battery level with this code:
Code: [Select]

unsigned long batteryLevel;
   
    analogSelection(VDD_1_3_PS);  //Selects VDD with 1/3 prescaling as the analog source
    delay(100);  // Might help with stability of next analogRead
. . .

This method is not always accurate. Hoping Simblee offers a better solution. We're powering Simblee with 2 AA batteries.

Any experience with this?

Many thanks,
Tim

I think the problem may be a conflict in the definition of VDD_1_3_PS.
Check out the  wiring_constants.h file in Simblee and RFduino libraries. VDD_1_3_PS is defined twice.

Code: [Select]
// wiring_constants.h
. . .

#define VDD_1_3_PS     ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling   
// Use VDD with 1/3 prescaling. (Only applicable when VDD is in the
range 2.5V  3.6V)
 . . .

#define VDD_1_3_PS     ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling
// Supply voltage with 1/3 prescaling used as input for the conversion
« Last Edit: August 24, 2017, 09:45:25 AM by RFD_Nelson »

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 126
  • Karma: +2/-0
    • View Profile
Re: Simblee getting input voltage
« Reply #2 on: May 16, 2016, 04:27:42 PM »
Thanks Tolson. Is this simple to do? I've learned how to write low level code for timers, GPIOTE, PPI, etc. Would I be looking at section 12 (Power management (POWER)) in the nRF51 v3.0 reference manual? I don't see any obvious registers for reading VDD.

Thx -Tim
« Last Edit: August 24, 2017, 09:45:45 AM by RFD_Nelson »

tolson

  • Global Moderator
  • *****
  • Posts: 880
  • Karma: +21/-0
    • View Profile
    • Thomas Olson Consulting
Re: Simblee getting input voltage
« Reply #3 on: May 16, 2016, 06:00:05 PM »
Hi Tim,

Thanks Tolson. Is this simple to do? I've learned how to write low level code for timers, GPIOTE, PPI, etc. Would I be looking at section 12 (Power management (POWER)) in the nRF51 v3.0 reference manual? I don't see any obvious registers for reading VDD.

Thx -Tim

I think after successfully tackling low level GPIOTE, PPI, and Timers, you can do ADC easy.
Yes v3.0 reference manual. But section 31 on ADC.
A picture explains a lot to what needs connected...
« Last Edit: August 24, 2017, 09:46:07 AM by RFD_Nelson »

tolson

  • Global Moderator
  • *****
  • Posts: 880
  • Karma: +21/-0
    • View Profile
    • Thomas Olson Consulting
Re: Simblee getting input voltage
« Reply #4 on: May 16, 2016, 08:53:58 PM »
Hi Tim,

Here is a simple low-level subroutine to get the VDD supply voltage.

Code: [Select]
// myADC_VDD test
// Thomas Olson teo20160516.01

asm(".global _printf_float"); //float support for printf

void setup()
{

  Serial.begin(9600);
  delay(2000); // give me time to start a serial monitor
  Serial.println("ADC - Tests - VDD voltage");

}

void loop()
{

  printf("VDD voltage is %.03f\n",3.6 * readVDD()/1023);
  delay(2000);

}

uint16_t readVDD()
{
uint16_t value;

  // Compare VDD against VBG(1.2v reference) at 10 bit resolution
  NRF_ADC->CONFIG = 0x0000001A;
 
  NRF_ADC->ENABLE = 0x00000001; // Enable the ADC
   
  NRF_ADC->TASKS_START = 1; // Start a conversion
 
  while(NRF_ADC->BUSY == 1){} // Busy Wait for completion
  delay(1); // needed if used on RFduino for some reason.

  value = (uint16_t)NRF_ADC->RESULT; // Read the ADC Result

  NRF_ADC->TASKS_STOP = 1; // Turn off ADC

  NRF_ADC->ENABLE = 0; // Disable the ADC
 
  return(value);
}
« Last Edit: January 04, 2018, 04:56:22 PM by tolson »

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 126
  • Karma: +2/-0
    • View Profile
Re: Simblee getting input voltage
« Reply #5 on: May 17, 2016, 09:35:36 AM »
That's very helpful Tolson. Many, many thanks. I've learned a lot from you. :).

Best,

Tim

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 126
  • Karma: +2/-0
    • View Profile
Re: Simblee getting input voltage
« Reply #6 on: June 06, 2016, 09:35:30 PM »
I've been testing your code, Tolson, and am finding variation in the VDD value reported. Here's a sample set of values measured at 50 second intervals:

818, 844, 860, 866, 866, 865, 865, 865, 865, 835, 864

That's a voltage variation of 0.165396 volts. Is this reasonable and expected?

Our power circuit is very similar to that of RFduino's dual AAA battery shield less the regulator. We use AA batteries instead of AAA.

Many thanks,

Tim

Wayne

  • RFduino Jr. Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Simblee getting input voltage
« Reply #7 on: August 18, 2017, 07:46:52 AM »
Has anyone fix the wide range of differences?


tolson

  • Global Moderator
  • *****
  • Posts: 880
  • Karma: +21/-0
    • View Profile
    • Thomas Olson Consulting
Re: Simblee getting input voltage
« Reply #8 on: August 18, 2017, 09:37:24 AM »
Has anyone fix the wide range of differences?

Hi Wayne,

Are you getting these variations. Of so, then not. If not, then so. I guess.

On a project I am using the above on, I am getting 4mV differences. All depends on battery load at moment of test.
« Last Edit: August 18, 2017, 10:10:51 AM by tolson »

Wayne

  • RFduino Jr. Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Simblee getting input voltage
« Reply #9 on: August 18, 2017, 12:43:45 PM »
Hi Tolson,

Yup exactly what I'm getting..  Depends on what the simblee is doing.. My case, I read the values and lite an led if the voltage is around 2.1 volts or less (1.8 is the min for simblee) and I
send this date divided by 4 to the receiver and multiply it by 4.. So a little difference here.

I'm using Simblee Off routine.. So the current draw is 4na (confirmed when asleep) and wakes up pretty fast.

 

anything