Some grains help build foam, while others help retain it.
I have found that grains higher in protein(ex. 6 row, wheat, rye) help build a good head. I have also noticed that the higher my mash temperature is, the thicker the head is. I am assuming it is from all of the residual/unfermented sugars left in the beer.
Grains like carapils help maintain your head. Carafoam is the same grain, but grown in Europe. I have found that 8 to 12 oz. of carapils does a very good job, and more is overkill.
Other grains that contribute to foam stability are the caramel/crystal grains. such as caramel 20, caramel 60, etc, etc.
1 more observation I have made... letting a beer condition in the bottle a little longer gives better foam performance. If it seems flat at 3 weeks, let them sit another week.
Are you doing all grain or extract?