overdischarge protection

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
gpson
Posts: 21
Joined: Sun Jul 31, 2016 6:55 am

overdischarge protection

Post by gpson » Sun Mar 18, 2018 9:44 pm

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?

User avatar
dhylands
Posts: 3592
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: overdischarge protection

Post by dhylands » Sun Mar 18, 2018 10:18 pm

No

User avatar
pythoncoder
Posts: 4924
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: overdischarge protection

Post by pythoncoder » Mon Mar 19, 2018 7:08 am

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.
Peter Hinch

OutoftheBOTS_
Posts: 794
Joined: Mon Nov 20, 2017 10:18 am

Re: overdischarge protection

Post by OutoftheBOTS_ » Mon Mar 19, 2018 7:54 am

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

chuckbook
Posts: 129
Joined: Fri Oct 30, 2015 11:55 pm

Re: overdischarge protection

Post by chuckbook » Mon Mar 19, 2018 10:11 am

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.

gpson
Posts: 21
Joined: Sun Jul 31, 2016 6:55 am

Re: overdischarge protection

Post by gpson » Mon Mar 19, 2018 10:30 am

Thank you all for suggestions!

Will start to experiment with ADC readings and deep sleep.

gpson
Posts: 21
Joined: Sun Jul 31, 2016 6:55 am

Re: overdischarge protection

Post by gpson » Mon Mar 19, 2018 11:33 am

with the code example from documentation I get the error
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'
>>>
stm.ADC does not have the 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() )


User avatar
dhylands
Posts: 3592
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: overdischarge protection

Post by dhylands » Mon Mar 19, 2018 2:27 pm

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:

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']
>>> 

gpson
Posts: 21
Joined: Sun Jul 31, 2016 6:55 am

Re: overdischarge protection

Post by gpson » Mon Mar 19, 2018 2:30 pm

I just copy/pasted the code from documentation and it is not working. I am just learning and do not know much about registers :)

User avatar
dhylands
Posts: 3592
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: overdischarge protection

Post by dhylands » Mon Mar 19, 2018 2:59 pm

Which documentation?

Post Reply