Advertisement
Guest User

Untitled

a guest
May 9th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ------------------------------------------------------------------------- --
  2. // Title         : DCF77-Decoder
  3. // Project       : Praktikum FPGA-Entwurfstechnik
  4. // ------------------------------------------------------------------------- --
  5. // File          : timeAndDateClock.v
  6. // Author        : Tim Stadtmann
  7. // Company       : IDS RWTH Aachen
  8. // Created       : 2018/09/20
  9. // ------------------------------------------------------------------------- --
  10. // Description   : Decodes the dcf77 signal
  11. // ------------------------------------------------------------------------- --
  12. // Revisions     :
  13. // Date        Version  Author  Description
  14. // 2018/09/20  1.0      TS      Created
  15. // ------------------------------------------------------------------------- --
  16.  
  17. module dcf77_decoder(clk,             // Global 10MHz clock
  18.                      clk_en_1hz,      // Indicates start of second
  19.                      nReset,          // Global reset
  20.                      minute_start_in, // New minute trigger
  21.                      dcf_Signal_in,   // DFC Signal
  22.                      timeAndDate_out,
  23.                      data_valid,      // Control signal, High if data is valid
  24.                      dcf_value,       // Decoded value of dcf input signal
  25.                             LED_DEBUG_MIN,
  26.                             LED_DEBUG_DATA,
  27.                             LED_DEBUG_CLK_1,
  28.                             LED_RECEIVING,
  29.                             recv_buffer
  30.                             );
  31.                      
  32. input clk,
  33.       clk_en_1hz,    
  34.       nReset,  
  35.       minute_start_in,
  36.       dcf_Signal_in;  
  37.      
  38. output reg[43:0]  timeAndDate_out;
  39. output reg        data_valid;
  40. output            dcf_value;
  41.    
  42. // ---------- YOUR CODE HERE ----------
  43.  
  44. output LED_DEBUG_MIN;
  45. output LED_RECEIVING;
  46. output reg LED_DEBUG_DATA;
  47. output reg LED_DEBUG_CLK_1;
  48.  
  49. reg receiving;
  50. reg [5:0] seconds_counter;
  51. output reg [58:0] recv_buffer;
  52. reg data_ok;
  53.  
  54. assign LED_DEBUG_MIN = minute_start_in;
  55. assign LED_RECEIVING = receiving;
  56.  
  57. always @(posedge clk, negedge nReset) begin
  58.     if(nReset == 0) begin
  59.         receiving <= 0;
  60.         seconds_counter <= 'b0;
  61.         data_valid <= 0;
  62.         timeAndDate_out <= 'b0;
  63.         recv_buffer <= 'b0;
  64.     end else begin
  65.        
  66.         if (minute_start_in == 1) begin
  67.             receiving <= 1;
  68.             seconds_counter <= 'b0;
  69.             recv_buffer <= 'b0;
  70.            
  71.         end else if(seconds_counter == 6'd59) begin
  72.             receiving <= 0;
  73.            
  74.             timeAndDate_out[6:0] <= 'b0; //seconds = 0
  75.        
  76.             timeAndDate_out[10:7 ] <= recv_buffer[24:21]; //minute LSD
  77.             timeAndDate_out[13:11] <= recv_buffer[27:25]; //minute MSD
  78.            
  79.             timeAndDate_out[17:14] <= recv_buffer[32:29]; //hour LSD
  80.             timeAndDate_out[19:18] <= recv_buffer[34:33]; //hour MSD
  81.            
  82.             timeAndDate_out[23:20] <= recv_buffer[39:36]; //day LSD
  83.             timeAndDate_out[25:24] <= recv_buffer[41:40]; //day MSD
  84.            
  85.             timeAndDate_out[29:26] <= recv_buffer[48:45]; //month LSD
  86.             timeAndDate_out[30   ] <= recv_buffer[49]; //month MSD
  87.            
  88.             timeAndDate_out[34:31] <= recv_buffer[53:50]; //year LSD
  89.             timeAndDate_out[38:35] <= recv_buffer[57:54]; //year MSD
  90.            
  91.             timeAndDate_out[41:39] <= recv_buffer[44:42]; //weekday
  92.             timeAndDate_out[43:42] <= recv_buffer[18:17]; // timezone & DST
  93.            
  94.             data_ok <= ( ~^recv_buffer[28:21] ) &&  ( ~^recv_buffer[35:29] ) && ( ~^recv_buffer[58:36] ); //parity bit check
  95.             seconds_counter <= 'b0;
  96.            
  97.         end else if( (clk_en_1hz == 1) && (receiving == 1) ) begin
  98.        
  99.             LED_DEBUG_CLK_1 <= ~LED_DEBUG_CLK_1;
  100.             LED_DEBUG_DATA <= ~dcf_Signal_in;
  101.             recv_buffer[seconds_counter] <= ~dcf_Signal_in;
  102.             seconds_counter <= seconds_counter + 1;
  103.            
  104.         end
  105.        
  106.         if(clk_en_1hz) begin
  107.             if(data_ok) begin
  108.                 if(data_valid) begin
  109.                     data_ok <= 0;
  110.                     data_valid <= 0;
  111.                 end else begin
  112.                     data_valid <= 1;
  113.                 end
  114.             end
  115.         end
  116.        
  117.  
  118.     end
  119.    
  120. end
  121.  
  122.  
  123. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement