Battery series connection algorithm