1 |
80 |
olivier.gi |
//----------------------------------------------------------------------------
|
2 |
|
|
// Copyright (C) 2001 Authors
|
3 |
|
|
//
|
4 |
|
|
// Redistribution and use in source and binary forms, with or without
|
5 |
|
|
// modification, are permitted provided that the following conditions
|
6 |
|
|
// are met:
|
7 |
|
|
// * Redistributions of source code must retain the above copyright
|
8 |
|
|
// notice, this list of conditions and the following disclaimer.
|
9 |
|
|
// * Redistributions in binary form must reproduce the above copyright
|
10 |
|
|
// notice, this list of conditions and the following disclaimer in the
|
11 |
|
|
// documentation and/or other materials provided with the distribution.
|
12 |
|
|
// * Neither the name of the authors nor the names of its contributors
|
13 |
|
|
// may be used to endorse or promote products derived from this software
|
14 |
|
|
// without specific prior written permission.
|
15 |
|
|
//
|
16 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19 |
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
20 |
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21 |
|
|
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22 |
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23 |
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24 |
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25 |
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
26 |
|
|
// THE POSSIBILITY OF SUCH DAMAGE
|
27 |
|
|
//
|
28 |
|
|
//----------------------------------------------------------------------------
|
29 |
|
|
//
|
30 |
|
|
// *File Name: DAC121S101.v
|
31 |
|
|
//
|
32 |
|
|
// *Module Description:
|
33 |
|
|
// Verilog model of National's DAC121S101 12 bit DAC
|
34 |
|
|
//
|
35 |
|
|
// *Author(s):
|
36 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
37 |
|
|
//
|
38 |
|
|
//----------------------------------------------------------------------------
|
39 |
|
|
// $Rev: 66 $
|
40 |
|
|
// $LastChangedBy: olivier.girard $
|
41 |
|
|
// $LastChangedDate: 2010-03-07 09:09:38 +0100 (Sun, 07 Mar 2010) $
|
42 |
|
|
//----------------------------------------------------------------------------
|
43 |
|
|
`timescale 1 ns/100 ps
|
44 |
|
|
//`include "timescale.v"
|
45 |
|
|
|
46 |
|
|
module DAC121S101 (
|
47 |
|
|
|
48 |
|
|
// OUTPUTs
|
49 |
|
|
vout, // Peripheral data output
|
50 |
|
|
|
51 |
|
|
// INPUTs
|
52 |
|
|
din, // SPI Serial Data
|
53 |
|
|
sclk, // SPI Serial Clock
|
54 |
|
|
sync_n // SPI Frame synchronization signal (low active)
|
55 |
|
|
);
|
56 |
|
|
|
57 |
|
|
// OUTPUTs
|
58 |
|
|
//=========
|
59 |
|
|
output [11:0] vout; // Peripheral data output
|
60 |
|
|
|
61 |
|
|
// INPUTs
|
62 |
|
|
//=========
|
63 |
|
|
input din; // SPI Serial Data
|
64 |
|
|
input sclk; // SPI Serial Clock
|
65 |
|
|
input sync_n; // SPI Frame synchronization signal (low active)
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
//============================================================================
|
69 |
|
|
// 1) SPI INTERFACE
|
70 |
|
|
//============================================================================
|
71 |
|
|
|
72 |
|
|
// SPI Transfer Start detection
|
73 |
|
|
reg sync_dly_n;
|
74 |
|
|
always @ (negedge sclk)
|
75 |
|
|
sync_dly_n <= sync_n;
|
76 |
|
|
|
77 |
|
|
wire spi_tfx_start = ~sync_n & sync_dly_n;
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
// Data counter
|
81 |
|
|
reg [3:0] spi_cnt;
|
82 |
|
|
wire spi_cnt_done = (spi_cnt==4'hf);
|
83 |
|
|
always @ (negedge sclk)
|
84 |
|
|
if (sync_n) spi_cnt <= 4'hf;
|
85 |
|
|
else if (spi_tfx_start) spi_cnt <= 4'he;
|
86 |
|
|
else if (~spi_cnt_done) spi_cnt <= spi_cnt-1;
|
87 |
|
|
|
88 |
|
|
wire spi_tfx_done = sync_n & ~sync_dly_n & spi_cnt_done;
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
// Value to be shifted in
|
92 |
|
|
reg [15:0] dac_shifter;
|
93 |
|
|
always @ (negedge sclk)
|
94 |
|
|
dac_shifter <= {dac_shifter[14:0], din};
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
// DAC Output value
|
98 |
|
|
reg [11:0] vout;
|
99 |
|
|
always @ (negedge sclk)
|
100 |
|
|
if (spi_tfx_done)
|
101 |
|
|
vout <= dac_shifter[11:0];
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
endmodule // DAC121S101
|
105 |
|
|
|
106 |
|
|
|