News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Device current consumption, how to

Started by TimB, Mar 01, 2021, 09:36 PM

Previous topic - Next topic

TimB

I have a temp meter I'm finishing work on and trying to calculate the current consumption. I go to great lengths to keep the current as low as possible. But there are some chips on the board that likes to gulp the electrons. So I do my best to keep the gulps as short as possible.

A multi meter is no use so I fitted an analogue dial current meter to the power supply. The residual current is around 5ma due to the step up and the glcd. Other parts flick the needle but they are over quickly so it never moves to the full scale. Back lights and sounders also hit the juice. Simple maths and sticking my finger in the air have me guesstimating the current on average around 6-7ma.

That puts the battery life at around 300+ hours with a couple of decent AA cells.

If thar is right then were talking 12 days continues use. I suppose it would not be unreasonable to suck and see for 12 days. However I'm curious to see if there is a device to actually measure the current over say 1 min so I can do the calculations and not wait the 12 days. Perhaps use the result to fine tune the consumption even more.

One thing I found with the analogue meter was how handy it is to see what was going on. I found spurious call to electron sucking routines I did not see by watching the meter jump around.

Again the question, any device to accurately measure intermittent current consumption?

Analogue meter

Screenshot 2021-03-01 at 21.26.31.png

Video

https://youtu.be/QmSFqSqJhd4
 

top204

I still regret getting rid of my analogue meters because they are better than digital meters for some operations. They operate a lot faster and can actually measure higher frequency voltage changes. I used to have a beautiful old Avo meter that belonged to my Dad, but I couldn't get the 15 Volt batteries it took, so it eventually rotted away in the shed. :-(

To make a current meter that can be used to measure currents over a time period, take a look at the INA219 chip or board. They operate via I2C and give good results. I created a program that stored the cuurent of a unit over 12-hours so I could see what was going on. I added a simple RTC to the unit so the EEPROM stored time and current for playback to a serial terminal. They are available from Ebay for a very small price.

Here's a library I created for the INA219:

$ifndef _INA219_INC_
$define _INA219_INC_
'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A library to read from an INA219 current sensor device using an I2C interface
' Written by Les Johnson for the Proton8 BASIC compiler version 3.7.4.6 onwards
'
' Setup the default pins used for the I2C interface to the INA219 device
'
$ifndef INA219_SDA_Pin                                      ' Has the $define been used in the main program?
    $define INA219_SDA_Pin PORTC.3                          ' No. So set the default INA219 SDA (Data) pin
    $SendWarning "Using the INA219_SDA_Pin default pin setting" ' Give a warning message
$endif
$ifndef INA219_SCL_Pin                                      ' Has the $define been used in the main program?
    $define INA219_SCL_Pin PORTC.4                          ' No. So set the default INA219 SCL (Clock) pin
    $SendWarning "Using the INA219_SCL_Pin default pin setting" ' Give a warning message
$endif
'
' Defines for use with the INA219 device
'
$define cINA219_I2C_Address $40                             ' Once shifted left, will be %1000000 (A0 + A1 = GND)
$define cINA219_Conf_Reset $8000                            ' Reset bit

$define cINA219_Conf_BusVoltRange_16V  $0000                ' 0-16V Range
$define cINA219_Conf_BusVoltRange_32V  $2000                ' 0-32V Range

$define cINA219_Conf_Gain_1_40mV     $0000                  ' Gain 1, 40mV Range
$define cINA219_Conf_Gain_2_80mV     $0800                  ' Gain 2, 80mV Range
$define cINA219_Conf_Gain_4_160mV    $1000                  ' Gain 4, 160mV Range
$define cINA219_Conf_Gain_8_320mV    $1800                  ' Gain 8, 320mV Range

$define cINA219_Conf_BusADCres_9bit  $0080                  ' 9-bit bus res = 0..511
$define cINA219_Conf_BusADCres_10bit $0100                  ' 10-bit bus res = 0..1023
$define cINA219_Conf_BusADCres_11bit $0200                  ' 11-bit bus res = 0..2047
$define cINA219_Conf_BusADCres_12bit $0400                  ' 12-bit bus res = 0..4097

$define cINA219_Conf_SADCres_9bit_1S_84uS     $0000         ' 1 x 9-bit shunt sample
$define cINA219_Conf_SADCres_10bit_1S_148uS   $0008         ' 1 x 10-bit shunt sample
$define cINA219_Conf_SADCres_11bit_1S_276uS   $0010         ' 1 x 11-bit shunt sample
$define cINA219_Conf_SADCres_12bit_1S_532uS   $0018         ' 1 x 12-bit shunt sample
$define cINA219_Conf_SADCres_12bit_2S_1060uS  $0048         ' 2 x 12-bit shunt samples averaged together
$define cINA219_Conf_SADCres_12bit_4S_2130uS  $0050         ' 4 x 12-bit shunt samples averaged together
$define cINA219_Conf_SADCres_12bit_8S_4260uS  $0058         ' 8 x 12-bit shunt samples averaged together
$define cINA219_Conf_SADCres_12bit_16S_8510uS $0060         ' 16 x 12-bit shunt samples averaged together
$define cINA219_Conf_SADCres_12bit_32S_17MS   $0068         ' 32 x 12-bit shunt samples averaged together
$define cINA219_Conf_SADCres_12bit_64S_34MS   $0070         ' 64 x 12-bit shunt samples averaged together
$define cINA219_Conf_SADCres_12bit_128S_69MS  $0078         ' 128 x 12-bit shunt samples averaged together

$define cINA219_Conf_Mode_PowerDown           $0000
$define cINA219_Conf_Mode_SVolt_Triggered     $0001
$define cINA219_Conf_Mode_BVolt_Triggered     $0002
$define cINA219_Conf_Mode_SandBVolt_Triggered $0003
$define cINA219_Conf_Mode_ADCOff              $0004
$define cINA219_Conf_Mode_SVolt_Cont          $0005
$define cINA219_Conf_Mode_BVolt_Cont          $0006
$define cINA219_Conf_Mode_SandBVolt_Cont      $0007
'
' INA219 Registers
'
$define cINA219_Reg_Config       0                          ' Config register (R/W)
$define cINA219_Reg_ShuntVoltage 1                          ' Shunt Voltage Register (R)
$define cINA219_Reg_BusVoltage   2                          ' Bus Voltage Register (R)
$define cINA219_Reg_Power        3                          ' Power Register (R)
$define cINA219_Reg_Current      4                          ' Current Register (R)
$define cINA219_Reg_Calibration  5                          ' Calibration Register (R/W)
'
' Setups for the calibration
'
$define cConfig_32V_2A    cINA219_Conf_BusVoltRange_32V | cINA219_Conf_Gain_8_320mV | cINA219_Conf_BusADCres_12bit | cINA219_Conf_SADCres_12bit_1S_532uS | cINA219_Conf_Mode_SandBVolt_Cont
$define cConfig_32V_1A    cINA219_Conf_BusVoltRange_32V | cINA219_Conf_Gain_8_320mV | cINA219_Conf_BusADCres_12bit | cINA219_Conf_SADCres_12bit_1S_532uS | cINA219_Conf_Mode_SandBVolt_Cont
$define cConfig_16V_400mA cINA219_Conf_BusVoltRange_16V | cINA219_Conf_Gain_1_40mV  | cINA219_Conf_BusADCres_12bit | cINA219_Conf_SADCres_12bit_1S_532uS | cINA219_Conf_Mode_SandBVolt_Cont
'
' Create some variables for use with the library routines
'
    Dim INA219_bAddress       As Byte                       ' Holds the I2C address of the INA219 being used
    Dim INA219_wCalValue      As Word                       ' Holds the calibration value for the INA219
    Dim INA219_fCurrentDiv_mA As Float                      ' Holds the division required for calibration
    Dim INA219_fPowerMult_mW  As Float                      ' Holds the multiplier required for calibration
    Dim INA219_fRes           As Float                      ' Used as an alias for the results of the procedures
    Dim INA219_wReg           As SWord

'------------------------------------------------------------------------------------------------------
' Set the address of the INA219 being used
' Input     : pAddr holds the I2C address
' Output    : None
' Notes     : Shifts the address left so that the address in the datasheet can be used ($40 for pins A0 and A1 to Gnd)
'
Proc INA219_SetAddress(pAddr As Byte)
    INA219_bAddress = pAddr << 1
EndProc

'------------------------------------------------------------------------------------------------------
' Writes to a register in the INA219 device
' Input     : pReg holds the register address
'             pValue holds the value to write
' Output    : None
' Notes     : None
'
Proc INA219_WriteRegister(pReg As Byte, pValue As Word)
    I2COut INA219_SDA_Pin, INA219_SCL_Pin, INA219_bAddress, pReg, [pValue]
EndProc

'------------------------------------------------------------------------------------------------------
' Reads a register's value from the INA219 device
' Input     : pReg holds the register address
' Output    : Returns the 16-bit value read (Result is aliased to global variable; INA219_wReg
' Notes     : None
'
Proc INA219_ReadRegister(pReg As Byte), INA219_wReg
    I2CIn INA219_SDA_Pin, INA219_SCL_Pin, INA219_bAddress, pReg, [Result]
EndProc

'---------------------------------------------------------------------------------------------------------
' Configures the INA219 to be able to measure up to 32V and 2A of current.
' Each unit of current corresponds to 100uA, and each unit of power corresponds to 2mW.
' Counter overflow occurs at 3.2A.
' Input     : None
' Output    : INA219_fCurrentDiv_mA holds divisor required for some calculations in other procedures
'           : INA219_fPowerMult_mW holds multiplier required for some calculations in other procedures
' Notes     : These settings are for a 0.1 Ohm resistor on the INA219 PCB
'
Proc INA219_SetCal_32V_2A()
    INA219_wCalValue = 4096
    INA219_fCurrentDiv_mA = 10.0                                    ' Current LSB = 100uA per bit (1000/100 = 10)
    INA219_fPowerMult_mW = 2.0                                      ' Power LSB = 1mW per bit (2/1)

    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue) ' Load the Calibration register
    INA219_WriteRegister(cINA219_Reg_Config, cConfig_32V_2A)        ' Load the Config register to take into account the settings
EndProc

'---------------------------------------------------------------------------------------------------------
' Configures the INA219 to be able to measure up to 32V and 1A of current.
' Each unit of current corresponds to 40uA, and each unit of power corresponds to 800mW.
' Counter overflow occurs at 1.3A.
' Input     : None
' Output    : INA219_fCurrentDiv_mA holds divisor required for some calculations in other procedures
'           : INA219_fPowerMult_mW holds multiplier required for some calculations in other procedures
' Notes     : These settings are for a 0.1 Ohm resistor on the INA219 PCB
'
Proc INA219_SetCal_32V_1A()
    INA219_wCalValue = 10240
    INA219_fCurrentDiv_mA = 25.0                                        ' Current LSB = 40uA per bit (1000/40 = 25)
    INA219_fPowerMult_mW = 0.8                                          ' Power LSB = 800uW per bit
    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue)     ' Load the Calibration register
    INA219_WriteRegister(cINA219_Reg_Config, cConfig_32V_1A)            ' Load the Config register to take into account the settings
EndProc

'---------------------------------------------------------------------------------------------------------
' Configure the INA219 to be able to measure up to 16V and 400mA max, with a resolution of 0.1mA
' Input     : None
' Output    : INA219_fCurrentDiv_mA holds divisor required for some calculations in other procedures
'           : INA219_fPowerMult_mW holds multiplier required for some calculations in other procedures
' Notes     : These settings are for a 0.1 Ohm resistor on the INA219 PCB
'
Proc INA219_SetCal_16V_400mA()
'
' Calibration that uses the highest precision for current measurement (0.1mA), and supporting 16V at 400mA max.
'
' V_Bus_Max = 16V
' V_Shunt_Max = 0.04 (Assumes Gain 1, 40mV)
' R_Shunt = 0.1 (Resistor value in ohms)
'
' 1... Determine max possible current
'   MaxPossible_I = VShunt_Max / R_Shunt
'   MaxPossible_I = 0.4A
'
' 2... Determine max expected current
' MaxExpected_I = 0.4A
'
' 3... Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
'   MinimumLSB = MaxExpected_I / 32767
'   MinimumLSB = 0.0000122 (12uA per bit)
'   MaximumLSB = MaxExpected_I / 4096
'   MaximumLSB = 0.0000977 (98uA per bit)
'
' 4... Choose an LSB between the min and max values (Preferrably a roundish number close to MinLSB)
'   CurrentLSB = 0.00005 (50uA per bit)
'
' 5... Calculate the calibration register
'   CalValue = trunc (0.04096 / (Current_LSB * R_Shunt))
'   CalValue = 8192

    INA219_wCalValue = 8192
'
' 6... Calculate the power LSB
'   PowerLSB = 20 * CurrentLSB
'   PowerLSB = 0.001 (1mW per bit)
'
' 7... Calculate the maximum current and shunt voltage values before overflow
'   Max_Current = Current_LSB * 32767
'   Max_Current = 1.63835A before overflow
'
'   If Max_Current > Max_Possible_I Then
'       Max_Current_Before_Overflow = MaxPossible_I
'   Else
'       Max_Current_Before_Overflow = Max_Current
'   EndIf
'
'   Max_Current_Before_Overflow = MaxPossible_I
'   Max_Current_Before_Overflow = 0.4
'
'   Max_ShuntVoltage = Max_Current_Before_Overflow * R_Shunt
'   Max_ShuntVoltage = 0.04V
'
'   If Max_ShuntVoltage >= VShunt_Max Then
'       Max_ShuntVoltage_Before_Overflow = VShunt_Max
'   Else
'       Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
'   EndIf
'
'   Max_ShuntVoltage_Before_Overflow = VShunt_Max
'   Max_ShuntVoltage_Before_Overflow = 0.04V
'
' 8... Calculate the Maximum Power
'   MaximumPower = Max_Current_Before_Overflow * V_Bus_Max
'   MaximumPower = 0.4 * 16V
'   MaximumPower = 6.4W
'
    INA219_fCurrentDiv_mA = 20.0                                        ' Current LSB = 50uA per bit (1000/50 = 20)
    INA219_fPowerMult_mW = 1.0                                          ' Power LSB = 1mW per bit
    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue)     ' Load the Calibration register
    INA219_WriteRegister(cINA219_Reg_Config, cConfig_16V_400mA)         ' Load the Config register to take into account the settings
EndProc

'---------------------------------------------------------------------------------------------------------
' Configure the INA219 to be able to measure up to 16V and 40mA max, with a resolution of 0.01mA
' Input     : None
' Output    : INA219_fCurrentDiv_mA holds divisor required for some calculations in other procedures
'           : INA219_fPowerMult_mW holds multiplier required for some calculations in other procedures
' Notes     : The default 0.1 Ohm resistor on the PCB must be changed to a 1.0 Ohm resistor
'
Proc INA219_SetCal_16V_40mA()
    INA219_wCalValue = 8192                                             ' Calibration value
    INA219_fCurrentDiv_mA = 200                                         ' Current LSB = 5uA per bit (1000/5 = 200)
    INA219_fPowerMult_mW = 1.0                                          ' Power LSB = 100mW per bit
    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue)     ' Load the Calibration register
    INA219_WriteRegister(cINA219_Reg_Config, cConfig_16V_400mA)         ' Load the Config register to take into account the settings
EndProc

'---------------------------------------------------------------------------------------------------------
' Get the shunt voltage in mV (+-327mV) from the INA219 device
' Input     : None
' Output    : Returns the Shunt Voltage value in milliVolts
' Notes     : None
'
Proc INA219_GetShuntVolts(), INA219_fRes
    Result = INA219_ReadRegister(cINA219_Reg_ShuntVoltage)         ' Read the Shunt Voltage register
    Result = Result / 100
EndProc

'---------------------------------------------------------------------------------------------------------
' Get the Bus voltage in Volts from the INA219 Device
' Input     : None
' Output    : Returns the Bus Voltage value
'           : Returns 0 if an invalid reading is taken
' Notes     : None
'
Proc INA219_GetBusVolts(), Byte
    Dim fBsVolts As Float
    Result = 1
    INA219_wReg = INA219_ReadRegister(cINA219_Reg_BusVoltage)   ' Read the Bus Voltage register
'
' Shift to the right x3 to strip CNVR and OVF bits and then multiply by LSB(4mV)
'
    'INA219_wReg = ((INA219_wReg >> 3) * 4)
    INA219_wReg = INA219_wReg / 8
    INA219_wReg = INA219_wReg * 4

    fBsVolts = INA219_wReg
    fBsVolts = fBsVolts * 0.001                                 ' Convert mV to V
'
' Check for a valid reading.
'
    If INA219_wReg.0 = 1 Then                                   ' If bit 0 is set then an overflow has occured
        Result = 0                                              ' So current and INA219_fPower readings could be invalid.
    EndIf
EndProc

'---------------------------------------------------------------------------------------------------------
' Get the Power reading from the INA219 Device
' Input     : None
' Output    : Returns the power value
' Notes     : None
'
Proc INA219_GetPower(), INA219_fRes
    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue)     ' Reset the calibration value before reading the register
    Result = INA219_ReadRegister(cINA219_Reg_Power)                     ' Read the Power register
    Result = Result * INA219_fPowerMult_mW
EndProc

'---------------------------------------------------------------------------------------------------------
' Get the raw current value (16-bit signed integer, so +-32767) from the INA219 Device
' Input     : None
' Output    : Returns the raw current reading
' Notes     : None
'
Proc INA219_GetCurrent_Raw(), SWord
    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue)     ' Reset the calibration value before reading the register
    Result = INA219_ReadRegister(cINA219_Reg_Current)                   ' Read the Current register
EndProc

'---------------------------------------------------------------------------------------------------------
' Get the current value in mA from the INA219 device
' Input     : None
' Output    : Returns the current value in milliAmps
' Notes     : None
'
Proc INA219_GetCurrent_mA(), INA219_fRes
    Dim fShuntV As Float

    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue)     ' Reset the calibration value before reading the register
    fShuntV = INA219_GetShuntVolts()                                    ' Read the Shunt Voltage register
    Result = INA219_ReadRegister(cINA219_Reg_Current)                   ' Read the Current register

    Result = Result / INA219_fCurrentDiv_mA

    If fShuntV < 0.1 Then
        Result = fShuntV
    EndIf
EndProc

'---------------------------------------------------------------------------------------------------------
' Get the current value in uA from the INA219 device
' Input     : None
' Output    : Returns the current value in microAmps
' Notes     : The default 0.1 Ohm resistor on the PCB must be changed to a 1.0 Ohm resistor
'
Proc INA219_GetCurrent_uA(), INA219_fRes
    INA219_WriteRegister(cINA219_Reg_Calibration, INA219_wCalValue)     ' Reset the calibration value before reading the register
    Result = INA219_ReadRegister(cINA219_Reg_Current)                   ' Read the Current register
    Result = Result / 0.2
EndProc

'---------------------------------------------------------------------------------------------------------
' Check the prescence of the INA219 by sending a reset command and reading the config register back
' Input     : None
' Output    : 1 if the INA219 is present, 0 if not present
' Notes     : None
'
Proc INA219_Check(), Bit
    Result = 0
    INA219_WriteRegister(cINA219_Reg_Config, $8000)                     ' Send a reset command to INA219
    INA219_wReg = INA219_ReadRegister(cINA219_Reg_Config)               ' Read the Configuration register

    If INA219_wReg = $399F Then                                         ' $399F is the default reset state
        Result = 1
    EndIf
EndProc

$endif  ' _INA219_INC_

And here is a simple demo of it operating:

'
'  /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\    \/\\\                                                /\\\          /\\\
'  \/\\\\\\\\\\\/        /\\\\\    /\\\\\\\\\\    /\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'    \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\    \/\\\        \/\\\        /\\\\\\\\\\
'      \/\\\    \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\    \/\\\ /\\  /\\\/////\\\
'      \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\  \//\\\\\\\\/\\
'        \///        \///    \/////    \//////////    \//////////      \/////        \/////    \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Read an INA219 current sensor device and display the current value on a serial terminal
'
    Device = 18F26K40                                  ' Choose the device
    Declare Xtal = 16                                  ' Set the oscillator to 16MHz
    Declare Float_Display_Type = Fast                  ' Alter the floating point display routine to faster and more accurate
'
' Setup the configurations for HRSout1
'   
    Declare Hserial_Baud = 9600                       
    Declare HRSOut1_Pin = PORTC.6
'
' Setup the pins to use for the I2C interface for the INA219 device
'
$define INA219_SDA_Pin PORTC.3                          ' The INA219 I2C SDA (Data) pin
$define INA219_SCL_Pin PORTC.4                          ' The INA219 I2C SCL (Clock) pin

    Include "INA219.inc"                                ' Load the INA219 library routines into the program

    Dim fShuntVoltage As Float                          ' Holds the Voltage result from procedure INA219_GetShuntVolts
    Dim fCurrent_mA  As Float                          ' Holds the Current result in milliAmps from the procedure INA219_GetCurrent_mA
    Dim fCurrent_uA  As Float                          ' Holds the Current result in microAmps from the procedure fCurrent_uA
   
'------------------------------------------------------------------------------------------------------
Main:
    INA219_SetAddress($40)                              ' Set the I2C address of the INA219 being used
'
'  Check the prescence of the INA219
'
    'While INA219_Check() = 0 : Wend

    INA219_SetCal_16V_40mA()                            ' Set the INA219 to the required configuration to read low currents
   
    Do
        fCurrent_mA  = INA219_GetCurrent_mA()          ' Read the Current in milliAmps
        fCurrent_uA  = INA219_GetCurrent_uA()          ' Read the Current in microAmps
       
        HRSOutLn "----------------------"
        HRSOutLn "Current: ", Dec2 fCurrent_mA, " mA"  ' Display the milliAmps on a serial terminal     
        HRSOutLn "Current: ", Dec0 fCurrent_uA, " uA"  ' Display the microAmps On a serial terminal
        DelayMS 1000                                    ' A small delay between readings so we can see things change
    Loop

If you change the resistor on the board to a 1 Ohm type, instead of the supplied 0.1 Ohm, the library I created can read microAmps as well with a resolution of 10uA.

TimB


Thanks Les

I'm looking into that device now. One thing I'm not sure on is how to handle the current spikes and accurately measure them.

I will have to poll the device as fast as possible to log the current used. I know that I draw ~12ma for 80ms 3 x a second for the PT100 converter and I also 12ma x a second for a few ms for the Bluetooth.

I'm thinking should I have a large cap inline so the peaks are smoothed out and it will be easier to get a true reflection of the actual current used.

I will play with the INA219 to see what I can come up with. Like polling fast and storing the data for a min in ram then dump it, to make a graph.

Gamboa

#3
Tim,

There is a MAXIM circuit that measures small currents and has an evaluation board with PC software that would serve as a working tool.
MAX17055
https://www.maximintegrated.com/en/products/power/battery-management/MAX17055.html#design-developement

With this device you can measure the energy you are consuming as well as the current.

Regards,
Gamboa
Long live for you

david

Hi Tim,
Years back I remember making Coulomb counters using low drift integrators but often the simple circuit attached will do all you need.  You may need to change the current shunt (1R, 10R) and the filter time constant depending on the period of the peaks.  You can still use your digital meters.......

Cheers,
David

Craig

Hi Tim What might be worth looking into if standard AA Batteries won't give a long enough life are
the batteries made by http://www.tadiranbat.com/. They are a bit more expensive but, Brilliant!
They will also be able to give all the correct specs etc on the battery discharges etc.
Regards
Craig

TimB


Hi Craig

AA batteries are more than adequate for the product. I am just looking to have reasonably accurate specs in the manual.

 

top204

#7
What I did was use a seperate PSU for the current meter and sample it as fast as I could, with a set time per sample, for 12 hours. If the previous current reading was different to the latest current reading, it got logged with its time, if it was the same it did not get logged. This way I could use an EEPROM to store the time and current value as integers, then a button on the unit transmitted the values from the EEPROM to a serial terminal, where I used the Rep modifier to see a type of chart on it, with the time on the left of the screen, then the current value, then the line of asterisks leading from the values, based upon the current value. To expand it, I also made a program that filled in the samples that were the same on the serial terminal, based upon time. This gave a more linear chart effect, because I knew the repetition times of taking the samples. 

Before I discovered the INA219, I used to use a simple op-amp operating in non-inverted mode, with a low Ohm resistor from the circuit's ground to actual ground. The voltage across the resistor matches the current used in the circuit (Ohm's Law) and the op-amp amplifies it so it can be read by the ADC, extemely quickly. That's the principle of the INA219. A resistor with a value of 0.01 Ohm or 0.1 Ohm or 1 Ohm, makes the calculation for voltage to current extremely easy! But the lower the Ohmage, the less voltage is across it, so more amplification is required and then a good quality op-amp is needed to stop drift if taking samples for many hours, and measuring very low currents. Otherwise, to read milliAmps, a simple LM358 and a 0.1 Ohm should do, with an amplification of about x10.

If using an op-amp, you can always write a form of algorithm that looks for patterns in the current readings, and it will be as fast as the ADC reading will allow because the writing to EEPROM can be made RAM buffered, so it is writing to EEPROM and reading the ADC at the same time. i.e. Double, triple or quadruple buffered while the ADC is taking its reading and re-charging its capacitor etc... However, for that many readings, you will need to use a larger flash memory chip for the storage.

Instead of a seperate RTC device, you can always write a simple RTC using a timer interrupt in the device that is taking the samples from the INA219 device or reading its ADC. It doesn't have to be exact and it is just a measure of time between current differences so you can see a set pattern emerging in a chart, if there is a pattern.

A large capacitor may mask the current spikes and dips because it will absorb some of them. Try without a capacitor first, then move up from 100uF onwards etc...

Note... If you get a negative current value from the INA219 board, its resistor is connected the wrong way round to the circuit being measured, but will cause no problems. Simply add an Abs function to its resulting value.

TimB


In reality I only need to sample for say 3-4 seconds as everything is repeating at 1hz in the code.

If you look at the video you can see it. The pulses should be 3hz however looking at the video they maybe 1.5hz. That was taken before the Bluetooth module was added and I have that automatically broadcasting at approx 4hz.

I am really interested over the short period. I have a caveat in the manual "1 Depending on usage
;D 

I will get one of the boards as they are inexpensive and the idea of a system to log the power of a board over a longer period interests me.

OG

#9
In order to use the AA battery for a longer life;
It may be useful to work with an NCP1402 or similar upconverter.
Because it can work up to 0.8V input voltage.
If it can be started with 0.8V, it can be used up to 0.3V input voltage.

NCP1402 datasheet (obsolete)

Max Output current 200mA

Output voltage options;
NCP1402SN19T1G 1,9V
NCP1402SN27T1G 2,7V
NCP1402SN30T1G 3,0V
NCP1402SN33T1G 3,3V
NCP1402SN40T1G 4,0V
NCP1402SN50T1G 5,0V

TimB


I use the TPS613221A



Not a valid attachment ID.Power section.PNG

okmn


top204

Is Q2 being used for Reverse Voltage Protection Tim?

Does it work well, because I have a project that I am using a Shottkyfor that purpose, but it drops 0.3 of a Volt.

TimB


Hi Les

Yes its used for reverse voltage protection. Not sure what the drop is but it's nowhere near 0.3v

The whole power side I'm actually quite pleased with. Works well.

I got the temp meter unit back from calibration and was please with the results. Even got a comment from the the calibration manager that he thought it was better than he expected. I can recommend the MAX31865 and the RN4870VRM118 BTle module.

Out on site with the kit it was almost too easy using it. It shows that if you spend long enough and sweat over the details you can produce a good product. Not that it generally pays off, but at least you sleep well at night no thinking you could have done better.

OG

#14
If U4 had an enable pin, U4 would not be needed.

TCK106AF datasheet

TCK106AF.JPG

HAL

Hello

I thought that I would compile the INA219 code for the 18F24k22 (I don't have an 18F26K40).  Les made a very timely posting as I doing a PCB with an INA210 for current monitoring.  My application needs to measure about 1.4 amps so I kept the 0.1 ohm resistor... Hooked a 9V battery through a 1k 5% R.  The battery is slightly used...

Obtained the following results:

----------------------
                                                         
 Current:  9.30 mA
                                                             
 Current:  9300 uA
                                                             
Bus Volts: 8.812 Volts
                                                         
Bus Power: 82 milliwatts

----------------------

Pretty slick....  And I gained an extra pin, formerly an analog input.
 
Les, have ever considered writing a book on Code Snippets (in your spare time)?

Thanks! 

top204

#16
It is a good little chip, the INA219. Hopefully, my code was clear to read and follow.

I would love to find the time to write a book or books. It is something I should have been doing for the past 20 years. :-(

I am still thinking of some project Ebooks. I know they do not earn a lot of funds, but they will give some earnings. I have some projects in my experiments that are quite good and would make good writing. i.e. A 3D music box!  I'll keep you guessing what that could be because if I revealed it, it would loose its appeal. It would make a good project eBook, with circuits and code and not copied and pasted, explanations of what it is doing and why. :-)

 


HAL

I may have learned a couple of things along the way (only time will tell).  In the include file there are instructions Proc,  Result, and EndProc that seemed new (but looked  somewhat like a function in C which I used about 25 years ago and don't remember any relevant details:)  Also, the include file made understanding the device easier, the data sheet is most likely written by people who know the device inside out, my understanding it is something else again.  There are posts on the web explaining the data sheet... No kidding..

Regarding Ebooks:
I know that the Western Design Center published their programing manual for Kindle.  Fairly dry reading for most all people except for those of us interested in this type of thing (went downstairs and took the AIM-65 out of its hiding place....

The Western Design Center link>
https://wdc65xx.com/Programming-Manual/

I believe there would be general interest in a proton manual for Kindle.  It does explain basic programing.  I would certainly be interested.  It would be handy to read without having to use the computer.  Especially for us newbies... I realize that the language and manual are moving targets but this is another way to make both known to more people.  And I believe that the formatting for Kindle is reasonably easy.  I have done it for a small document <5meg.  Again in your spare time (of which, you likely have none).  It could be another form of advertising the compiler;)

Apologies for droning on...
HAL

top204

There are many "free" online sites that will convert a PDF to Kindle type formats, and vice-versa.

But what is the difference between reading from a good PC monitor, or a small palm top sized screen? I know I'd rather read from the good quality PC screen. :-)

With application notes and the PIC and PIC24 reference documents, I downloaded them and printed them and placed them in binders so I could read them in bed and make notes on the pages when I was learning the inner mechanisms of the devices.

HAL

I JUST THOUGHT IT MAY BE A WAY TO MAKE (PROTON) POSITRON MORE WIDELY KNOWN.  I AM FROM THE OLD SCHOOL OF THE PRINTED PAGE FOR SURE... BUT, I USUALLY TAKE THE KINDLE TO DENTIST OR DR'S OFFICE TO READ THE SMALL SCREEN.  I USUALLY GET AT LEAST 1/2 HOUR IT BEATS THE DAYTIME TV THEY USUALLY HAVE ON...  BEING HALF DEAF IS HELPFUL AS WELL!  PLEASE UNDERSTAND, IT WAS NOT MY INTENTION TO OFFEND:)