Digital PLL loses lock every time mesage crosses zero I think my digital PLL is almost ready, but I've encountered this problem and I don't know what might be causing it, so I'd appreciate if you could help.

I'm using the DPLL in a Costas loop. It seems to work fine but whenever the message crosses zero, lock is lost. After that, it ends up locking again. You can see here:



Input to the Costas loop is:
$$
x(t) = m(t)cos(2\pi f_ct+\theta_{in})
$$
$$
m(t) = cos(2\pi f_mt)
$$
where $f_m &lt;&lt; f_c$

Not sure if this is a known phenomenom (it probably is) but I haven't been able to find anything related. It'd be nice if you could point out what's going on and/or how to fix the temporary loss of lock?

One way I've managed to get it "working" consisted of squaring the message signal (although phase error rises a bit when message goes near zero), but I don't wish to square it so that wouldn't be of use to me.

This is the Costas loop I'm implementing for this test:
You are having trouble because that's not a Costas loop.  A Costas loop uses demodulated data in some form to change the phase that's expected from the signal.  

You're just taking the I/Q demodulated signal and applying it to the atan2 function; that makes a sort of linearized extended phase detector, but without determining that the phase should have flipped by 180 degrees, your loop is naturally trying to follow the phase that's actually coming in.

You could make your loop into a simple Costas loop by changing the atan2 function into a multiply, and following it by a proper loop filter.