overdischarge protection
overdischarge protection
hey,
I want to connect the 18650 cell battery to my pyboard. these cells have no protection.. does the board have any Liion overdischarge protection?
I want to connect the 18650 cell battery to my pyboard. these cells have no protection.. does the board have any Liion overdischarge protection?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: overdischarge protection
You might be able to DIY by periodically reading the battery voltage using an ADC. If it's too low, shut down the Pyboard.
Disclaimer: I know nothing about the characteristics of these cells so this may not be practicable. You may need a resistive divider to ensure the ADC input voltage is always within range.
Disclaimer: I know nothing about the characteristics of these cells so this may not be practicable. You may need a resistive divider to ensure the ADC input voltage is always within range.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: overdischarge protection
Generally I would only buy these little Lion batteries with a protection circuit.
But in saying that most of these protection ciruits on these batteries will only protect from discharge below 2.8v which is below what is recommended for not to discharge below. For longer life of the cell don't discharge below 3v.
But in saying that it is likely that your pyboard will shut down well before that. Without looking at the voltage regulator for the Pyboard not sure what the drop out voltage is but likely to be above 3.4v.
If your pyboard does shut down because of low voltage (flat battery) then make sure that u disconnect the battery as even though the pyboard has shut down it will still have a quiescent draining the battery and if you leave it connected it will damage the battery by continuing to draining it.
There is a couple of work arounds for you as pycoder suggested a voltage divider to the ADC and in your software to periodically check it.
You can also get a battery charger and protection module for less than $1 that has a 1amp Lipo constant current/constant voltage charger with the same protection curuits normally on batteries see https://www.aliexpress.com/item/LCD-Boa ... autifyAB=0
and a demo of it in action https://www.youtube.com/watch?v=jE0O8PP-wsw
But in saying that most of these protection ciruits on these batteries will only protect from discharge below 2.8v which is below what is recommended for not to discharge below. For longer life of the cell don't discharge below 3v.
But in saying that it is likely that your pyboard will shut down well before that. Without looking at the voltage regulator for the Pyboard not sure what the drop out voltage is but likely to be above 3.4v.
If your pyboard does shut down because of low voltage (flat battery) then make sure that u disconnect the battery as even though the pyboard has shut down it will still have a quiescent draining the battery and if you leave it connected it will damage the battery by continuing to draining it.
There is a couple of work arounds for you as pycoder suggested a voltage divider to the ADC and in your software to periodically check it.
You can also get a battery charger and protection module for less than $1 that has a 1amp Lipo constant current/constant voltage charger with the same protection curuits normally on batteries see https://www.aliexpress.com/item/LCD-Boa ... autifyAB=0
and a demo of it in action https://www.youtube.com/watch?v=jE0O8PP-wsw
Re: overdischarge protection
In general I don't recommend using Li rechargeable batteries without protection circuit. However, even protected Li batteries should not be operated to it's limits. Best practice is to monitor Vref and put the device into deepsleep mode once a certain lower threshold voltage is reached. A pyboard will work quite well with supply voltage below 3 V although USB cannot be used below 3 V.
To examine Vref no external components are required as reading Vref (ADCAll.read_vref()) just evaluates the operating voltage of the MCU. Under normal conditions Vref should read 3.3V. This means VBAT is at least 3.3V + drop-out voltage of the LDO (MCP1703).
If a pyboard (V1.1 or LITE) is in deepsleep mode, it will only draw ~5µA without any external consumers. A typical 18650 cell with remaining charge of 10% will probably last for another 5 years in deepsleep.
To examine Vref no external components are required as reading Vref (ADCAll.read_vref()) just evaluates the operating voltage of the MCU. Under normal conditions Vref should read 3.3V. This means VBAT is at least 3.3V + drop-out voltage of the LDO (MCP1703).
If a pyboard (V1.1 or LITE) is in deepsleep mode, it will only draw ~5µA without any external consumers. A typical 18650 cell with remaining charge of 10% will probably last for another 5 years in deepsleep.
Re: overdischarge protection
Thank you all for suggestions!
Will start to experiment with ADC readings and deep sleep.
Will start to experiment with ADC readings and deep sleep.
Re: overdischarge protection
with the code example from documentation I get the error
stm.ADC does not have the attribute ADC?Traceback (most recent call last):
File "<stdin>", line 31, in <module>
File "<stdin>", line 29, in temperature
File "<stdin>", line 18, in adcread
AttributeError: 'module' object has no attribute 'ADC'
>>>
Code: Select all
import stm
import pyb
def adcread(chan): # 16 temp 17 vbat 18 vref
assert chan >= 16 and chan <= 18, 'Invalid ADC channel'
start = pyb.millis()
timeout = 100
stm.mem32[stm.RCC + stm.RCC_APB2ENR] |= 0x100 # enable ADC1 clock.0x4100
stm.mem32[stm.ADC1 + stm.ADC_CR2] = 1 # Turn on ADC
stm.mem32[stm.ADC1 + stm.ADC_CR1] = 0 # 12 bit
if chan == 17:
stm.mem32[stm.ADC1 + stm.ADC_SMPR1] = 0x200000 # 15 cycles
stm.mem32[stm.ADC + 4] = 1 << 23
elif chan == 18:
stm.mem32[stm.ADC1 + stm.ADC_SMPR1] = 0x1000000
stm.mem32[stm.ADC + 4] = 0xc00000
else:
stm.mem32[stm.ADC1 + stm.ADC_SMPR1] = 0x40000
stm.mem32[stm.ADC + 4] = 1 << 23
stm.mem32[stm.ADC1 + stm.ADC_SQR3] = chan
stm.mem32[stm.ADC1 + stm.ADC_CR2] = 1 | (1 << 30) | (1 << 10) # start conversion
while not stm.mem32[stm.ADC1 + stm.ADC_SR] & 2: # wait for EOC
if pyb.elapsed_millis(start) > timeout:
raise OSError('ADC timout')
data = stm.mem32[stm.ADC1 + stm.ADC_DR] # clear down EOC
stm.mem32[stm.ADC1 + stm.ADC_CR2] = 0 # Turn off ADC
return data
def temperature():
return 25 + 400 * (3.3 * adcread(16) / 4096 - 0.76)
print( temperature() )
Re: overdischarge protection
According to the datasheet, the register containing the ADC value is called ADC_DR. Looking at the datasheet, I see no register called simply ADC. Which register are you looking for?
You can see all of the ADC registers by doing:
You can see all of the ADC registers by doing:
Code: Select all
>>> [d for d in dir(stm) if d.startswith('ADC')]
['ADC1', 'ADC2', 'ADC3', 'ADC123_COMMON', 'ADC_SR', 'ADC_CR1', 'ADC_CR2', 'ADC_SMPR1', 'ADC_SMPR2', 'ADC_JOFR1', 'ADC_JOFR2', 'ADC_JOFR3', 'ADC_JOFR4', 'ADC_HTR', 'ADC_LTR', 'ADC_SQR1', 'ADC_SQR2', 'ADC_SQR3', 'ADC_JSQR', 'ADC_JDR1', 'ADC_JDR2', 'ADC_JDR3', 'ADC_JDR4', 'ADC_DR']
>>>
Re: overdischarge protection
I just copy/pasted the code from documentation and it is not working. I am just learning and do not know much about registers