Subversion Repositories ngs

Rev

Rev 3 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. // part of NeoGS project (c) 2007-2008 NedoPC
  2. //
  3. // sound_dac is a serializer of 16 bit data for TDA1543 DAC
  4. // input is clock at 24 MHz and 16-bit parallel data
  5. // the module generates strobe signal for data sender - load, indicating when it loaded new portion of data,
  6. // and allowing sender to begin preparing new data. dac_leftright is also to be used by sender (by locking it
  7. // when load is 1).
  8. //
  9. // dac_clock is symmetrical clock at 1/10 of input clock (2.4 MHz)
  10. // load is positive 1 clock cycle pulse informing that new data has just loaded
  11.  
  12. module sound_dac(
  13.         clock,         // input clock (24 MHz)
  14.  
  15.         dac_clock,     // clock to DAC
  16.         dac_leftright, // left-right signal to DAC (0 - left, 1 - right)
  17.         dac_data,      // data to DAC
  18.  
  19.         load,          // output indicating cycle when new data loaded from datain bus
  20.  
  21.         datain         // input 16-bit bus
  22. );
  23.  
  24.         input clock;
  25.  
  26.         output dac_clock;
  27.  
  28.         output dac_leftright;
  29.  
  30.         output dac_data;
  31.  
  32.         output reg load;
  33.  
  34.  
  35.         input [15:0] datain;
  36.  
  37.         reg [16:0] data; // internal shift register
  38.  
  39.         reg [2:0] fifth; // divide by 5
  40.         reg [6:0] sync; // sync[0] - dac_clock
  41.                         // sync[6] - dac_leftright
  42.  
  43.         wire load_int;
  44.  
  45.  
  46.  
  47.         // for simulation purposes
  48.         initial
  49.         begin
  50.                 fifth <= 0;
  51.                 sync <= 0;
  52.                 data <= 0;
  53.                 load <= 0;
  54.         end
  55.  
  56.  
  57.         // divide input clock by 5
  58.         always @(posedge clock)
  59.         begin
  60.                 if( fifth[2] )
  61.                         fifth <= 3'b000;
  62.                 else
  63.                         fifth <= fifth + 3'd1;
  64.         end
  65.  
  66.         // divide further to get dac_clock and dac_leftright
  67.         always @(posedge clock)
  68.         begin
  69.                 if( fifth[2] )  sync <= sync + 7'd1;
  70.         end
  71.  
  72.  
  73.         // load signal generation
  74.         assign load_int = fifth[2] & (&sync[5:0]);
  75.  
  76.         always @(posedge clock)
  77.         begin
  78.                         load <= load_int;
  79.         end
  80.  
  81.         // loading and shifting data
  82.         always @(posedge clock)
  83.         begin
  84.                 if( fifth[2] && sync[0] )
  85.                 begin
  86.                         if( load_int )
  87.                                 data[15:0] <= datain;
  88.                         else
  89.                                 data[15:0] <= { data[14:0], 1'b0 }; // MSB first
  90.  
  91.                         data[16] <= data[15];
  92.                 end
  93.         end
  94.  
  95.         assign dac_leftright = sync[6];
  96.         assign dac_clock = sync[0];
  97.         assign dac_data  = data[16];
  98.  
  99. endmodule
  100.  
  101.