+ end
+
+ // detect modulation signal: if modulating, there must be a falling and a rising edge
+ if (rx_mod_falling_edge_max > 6 && rx_mod_rising_edge_max > 6)
+ curbit <= 1'b1; // modulation
+ else
+ curbit <= 1'b0; // no modulation
+
+
+ // store previous samples for filtering and edge detection:
+ adc_d_4 <= adc_d_3;
+ adc_d_3 <= adc_d_2;
+ adc_d_2 <= adc_d_1;
+ adc_d_1 <= adc_d;
+
+
+ // Relevant for TAGSIM_MOD only (timing the Tag's answer. See above)
+ // When we see end of a modulation and we are emulating a Tag, start fdt_counter.
+ // Reset fdt_counter when modulation is detected.
+ if(~after_hysteresis /* && mod_sig_buf_empty */ && mod_type == `TAGSIM_LISTEN)
+ begin
+ fdt_counter <= 11'd0;
+ fdt_elapsed = 1'b0;
+ fdt_indicator <= 1'b0;
+ temp_buffer_reset = 1'b0;
+ mod_sig_ptr <= 5'b00000;
+ mod_sig = 1'b0;
+ end
+
+
+ if(negedge_cnt[3:0] == 4'd1)
+ begin
+ // What do we communicate to the ARM
+ if(mod_type == `TAGSIM_LISTEN)
+ sendbit = after_hysteresis;
+ else if(mod_type == `TAGSIM_MOD)
+ /* if(fdt_counter > 11'd772) sendbit = mod_sig_coil; // huh?
+ else */
+ sendbit = fdt_indicator;
+ else if (mod_type == `READER_LISTEN)
+ sendbit = curbit;
+ else
+ sendbit = 1'b0;
+ end
+
+ //------------------------------------------------------------------------------------------------------------------------------------------
+ // Prepare 8 Bits to communicate to ARM
+
+ // in SNIFFER mode: 4 Bits data sniffed as Tag, 4 Bits data sniffed as Reader
+ if(mod_type == `SNIFFER)
+ begin
+ if (negedge_cnt == 7'd63)