TNT was first prepared in 1863 by German chemist Julius Wilbrand and originally used as a yellow dye. Its potential as an explosive was not appreciated for several years, mainly because it was so difficult to detonate and because it was less powerful than alternatives. Its explosive properties were first discovered by another German chemist, Carl Häussermann, in 1891. (Wiki)
You don't tell us anything about why you're asking the question. If you're looking to write an alternative history story that uses improved TNT during the U.S. Civil War then you need to:
Look into the history of Julius Wildbrand and see if his research can discover TNT ealier (at least 5 years earlier) and,
Look into the history of Carl Häussermann to see if either his research could be pulled up 30+ years.
Yes, there is always the possibility of serendipity. Wildbrand wasn't actually looking for an explosive, so in frustration he could have thrown a batch of TNT into a furnace for incineration, resulting in the instantaneous discovery of its explosive properties. After that it wouldn't take long to figure out how to detonate it predictably. Assuming he lived through the moment, that would have eliminated Häussermann from the picture completely and saved you 30 years of development.
Note that by 1863 the U.S. Civil War was already turning against the Confederate States and TNT would not change history substantially (which is another way of saying it wouldn't have changed it at all). If the Civil War is the focus of your story, then you need both the invention of TNT and the discovery of its explosive properties to happen no later than 1861.
Finally, while I can't speak to what, if any, improvements were made to TNT between 1863 and 1902 when the German military started using it in their ordinance, I can say that it wouldn't have mattered. TNT wasn't used in the Civil War, as you suggest, because it's original state was too impure to be a decent explosive. It wasn't used because it's so stable no one understood that it was an explosive. Even in the state of its original discovery, it might have changed the war substantially... especially if the Confederates got hold of it first and could figure out how to detonate it using a cannon ball.