I don't know how much you could do in the time allowed, but one possibility would be Cardiff - Merthyr Tydfil, then bus to Aberdare. Journey time is no more than 40 minutes and it's a frequent service. Then Aberdare back down to Pontypridd and from there to Treherbert and back to Cardiff.
Other possibilities making use of bus connections are Cardiff - Merthyr Tydfil then bus (about 25 minutes journey time) to Rhymney for the line from there to Cardiff. You could also get a bus (about 40 minutes journey time) from Merthyr to Ebbw Vale for the line from there to Cardiff.
--- old post above --- --- new post below ---
To add, with the first of those suggestions you could change at Radyr on the way back and fit in the City Line, continuing all the way to Coryton and back if there's time, then changing at Queen Street for the short hop to Cardiff Bay and back.