I'm a beginner trying to make a linear regulator and made some decent progress on a breadboard powering from a 20V laptop charger. After battling off the typical opamp instability issues I seemed to get a pretty acceptable adjustable CC/CV output with no ripple so I decided try it out with a more realistic input source, a mains transformer.
The transformer has dual isolated 12VAC windings and the circuit above shows the setup I'm using. The maximum output voltage of the supply should be ~20V at 2A and so C1 and C2 are sized appropriately to give enough headroom for the output pass transistor. The diode and C3 into the linear regulator is for powering the control loop circuitry, which draws < 50mA and must stay at 28V. I can provide a diagram for the control circuit if necessary, It looks something like the circuit in another question I asked here
When the mains transformer is used all of my circuit is plagued with 100Hz ripple -- it seems to be everywhere. The output ripple is at least 50mV and increases with load up to 300mV and beyond. The ripple is not being introduced by the voltage references since they are being powered off a stable DC supply to make sure. Here's a scope trace of the AC coupled output: https://i.imgur.com/DvnZAIW.jpg
The ripple at the LM317's input is just 50mV yet the ripple at the output is 20mV, completely unexpected based on the PSRR of a chip like this. Dropout is not the issue here either. I don't think it's ripple on the supply of the op amps either which are decoupled and see a pretty smooth DC voltage. I thought that it might have something to do with bad grounding, since I saw the ripple even between different grounds which were physically far from one another. After making more of an effort to ground properly this ripple between grounds is almost gone, but not at all from the output of my circuit.
I'm not sure where to go from here as I don't know enough, I definitely don't understand where the problem lies. I'm almost certain that if powered from a smooth DC source the problems would go but that's not really the point in a regulator. I would have thought that a couple of volts of input ripple would be no problem for a circuit like this to regulate, especially with such a headroom. The problem must be from the input supply, is a better input filter (like a Pi filter) needed? Is it because I'm putting two rectified outputs in series but only smoothing the 0-36V rail? Worth noting that the 18V rail looks like a completely unfiltered rectifier output.
Any help would be greatly appreciated.