EDIT:
I know there was an article that was mentioned in another thread on here about tidal locking for K classes (while I agree that tidal locking would be an issue for M class red dwarfs, I'm skeptical about it on K class), but I'm wondering if a planet orbiting one of those two would be tidally affected by the companion star? I have no idea if it would, the effect might even be negligible, but it's a thought.
Basically, tidal locking time turns out to involve a ridiculous number of variables which can drastically affect the results if not perfectly accurate.
I have found one formula which may work, from:
http://solar-flux.forumandco.com/t704-rotation-period-for-fictional-and-real-planets D = 0.0483((AM²)/d)^(1/6)
where D is the distance required for a planet to tidally lock (AU), d is the density of the planet (kg/m^3), A is the age of the system (y), and M is the mass of the star (suns). The original link says density should be measured in tons per cubic decimeter (t/dm^3). Do not use this: it will not give you the right numbers.
For our solar system and a density of 5500 (about the density of Earth), this can be calculated to be 0.475 AU. At the tidal locking distance, a planet of the given density takes about 5 Gy to be locked.
Note: denser planets will take longer to become locked. For a planet with the density of Saturn the tidal lock distance is about 0.67 AU.
In general, we can set A to equal 10^10 years. (planets older than that may become uninhabitable due to stellar evolution, loss of internal heat, or loss of atmosphere). We will set d to equal 2500 kg/m^3, which is equivalent to an ocean planet with water as a major component of the mass. Habitable planets won't likely get much less dense than this, and denser planets will be stable a bit further out. Thus, we get the equation:
D = 0.0483 (4*10^6 M^2)^(1/6). Given the mass of a star, this tells us the tidal locking distance. What this doesn't tell us is where the tidal locking distance is relative to the habitable zone.
Fortunately, we have other useful formulas. The mass to luminosity relationship of a main-sequence star is L = M^3.9. The relationship between planet temperature, star luminosity, and planet distance is T = k/(D/L^0.5)^0.5. k is a constant which is related to the albedo of the planet and a bunch of other stuff we don't care about. For Earth, which has an equilibrium temperature of 255 K, k=255, so we get:
255 = 255/(D/L^0.5)^0.5.
multiplying both sides by the denominator of that fancy fraction:
255(D/L^0.5)^0.5 = 255.
(D/L^0.5)^0.5 = 1
squaring both sides:
D/L^0.5 = 1
D = L^0.5
D is now an orbital distance somewhere in the middle of the habitable zone. Substituting M^3.9 for L:
D = (M^3.9)^0.5
D = M^1.95
So, given the mass of the star, we now have an approximate habitable distance and a tidal locking distance. If the habitable distance is less than the tidal locking distance, any habitable planets of the star will be tidally locked. If the habitable distance is greater than the tidal locking distance, habitable planets may rotate as they please. Therefore, the minimum mass M of the star for a habitable planet to not be tidally locked is the value of M such that the habitable distance is equal to the tidally locking distance. Translating this into algebra:
kM^1.95 = 0.0483 (4*10^6 M^2)^(1/6)
this is a mess. However, we can get rid of the obnoxious fractional exponent by raising everything to the power of 6:
M^11.7 = 1.270*10^-8 * 4*10^6 M^2
Let's simplify the constant...
M^11.7 = 0.0508 M^2.
Dividing by M^2:
M^11.7 / M^2 = 0.0508
M^9.7 = 0.0508
M = 0.0508^(1/9.7)
M = 0.736
So, if a star has a mass smaller than 0.736 suns, its habitable planets will probably be tidally locked. But what spectral class is the star at the threshold? well...
This list:
http://en.wikipedia.org/wiki/List_of_exoplanetary_host_stars can be sorted by mass, giving us an idea of some real stars of this mass. It turns out that these stars are in the range of K1V to K4V. So, in general, this formula tells us that stars of K3V or cooler will tidally lock their habitable planets. Denser planets can be closer in while being locked.
This doesn't bode well for habitable moons of gas giants... or does it? The density of the planet affects the tidal locking distance, but not much (the term with density in it is taken the the power of 1/6. This means that a planet 50% less dense than Earth will have a tidal locking distance only 1.6% larger. In addition, the combined mass of the moons of a gas giant is about 0.02% the mass of the planet. This means that for the moon of a gas giant to be large enough to retain an atmosphere and generate a magnetic field (lets' say 0.1 earth masses... don't forget that tidal heating will help keep the moon geologically active, and the planet's magnetic field may provide some shielding) the gas giant needs to be at least 500 earth masses. Gas giants of above this mass don't change much in radius (provided they aren't extremely hot and puffy, which rules them out as parents of habitable moons anyway) so they can be as dense or denser than terrestrial planets.
Note: this assumes a planet somewhere in the middle of its habitable zone, perhaps a little bit towards the inside edge. Planets on the outer edge of their habitable zones (including planets with thick atmospheres... and moons of gas giants if the parent provides enough tidal heating) can orbit somewhat smaller stars without becoming tidally locked. Planets with ammonia-based life, which would exist at colder temperatures (surface temperature 200-240 K, possibly hotter for planets with high atmospheric pressure) could due fine around even colder stars.
To determine the exact numbers, we just need to change the equilibrium temperature of the planet, and thus the distance. For mars, on the outer edge of the HZ, the distance is 1.5 AU for a sunlike star. For an ammonia planet, the distance may be 2 AU to 2.5 AU, depending on the strength of the greenhouse effect. We add this as a coefficient to our habitable distance formula:
Mid-range water planet: D = M^1.95.
Outer range water planet: D = 1.5 M^1.95
Inner range ammonia planet: D = 2 M^1.95
Outer range ammonia planet: D = 2.5 M^1.95.
we now get the equation
kM^1.95 = 0.0483 (4*10^6 M^2)^(1/6), where k is the coefficient based on the equilibrium temperature of the planet. From here, we can proceed as before, but dividing the "0.0483" constant by k.
We now get a more complete set of masses. HZa means habitable zone for liquid-ammonia-based-life.
For a planet of about Earthlike distance, M = 0.736 suns, or about K3V star.
For an outer HZ water planet, M = 0.572 suns, or about a K9V star.
For an inner HZa planet , M = 0.479 suns, or about an M0V star
For an outer HZa planet, M= 0.417 sun, or about an M1V star.
Conclusion: If your star is G class, the habitable planets won't be tidally locked. If the star is M class, they will. If the star is K class, check the tidal locking distance with this: D = 0.0483((AM²)/d)^(1/6).
Use the actual density and age of your planet.