+end
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Tag -> PM3:
+// modulation detector. Looks for the steepest falling and rising edges within a 16 clock period. If there is both a significant
+// falling and rising edge (in any order), a modulation is detected.
+reg signed [10:0] rx_mod_falling_edge_max;
+reg signed [10:0] rx_mod_rising_edge_max;
+reg curbit;
+
+`define EDGE_DETECT_THRESHOLD 5
+
+always @(negedge adc_clk)
+begin
+ if(negedge_cnt[3:0] == mod_detect_reset_time)
+ begin
+ // detect modulation signal: if modulating, there must have been a falling AND a rising edge
+ if ((rx_mod_falling_edge_max > `EDGE_DETECT_THRESHOLD) && (rx_mod_rising_edge_max < -`EDGE_DETECT_THRESHOLD))
+ curbit <= 1'b1; // modulation
+ else
+ curbit <= 1'b0; // no modulation
+ // reset modulation detector
+ rx_mod_rising_edge_max <= 0;
+ rx_mod_falling_edge_max <= 0;
+ end
+ else // look for steepest edges (slopes)