OpenCores
URL https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [grpComponents/] [unitIcs307/] [src/] [ICS307-Bhv-a.vhd] - Blame information for rev 185

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 67 rkastl
-------------------------------------------------------------------------------
2
-- Title: Serially Programmable Clock Source ICS307
3
-- Project: FH-Hagenberg/HSSE: SET5
4
-- Author: Copyright 2006 by Friedrich Seebacher and Markus Pfaff,
5
-- Linz/Austria/Europe
6
-------------------------------------------------------------------------------
7
-- $LastChangedDate: 2007-01-09 08:40:02 +0100 (Di, 09 Jän 2007) $
8
-- $LastChangedRevision: 415 $
9
-- $LastChangedBy: pfaff $
10
-- $HeadURL: file:///C:/pfaff/rpySvn/rpySvnSet5/trunk/Uebung/W06Jg04/Uebung03/unitIcs307/src/ICS307-Bhv-a.vhd $
11
-- LoginNames: pfaff - Markus Pfaff, Linz/Austria/Europe
12
-------------------------------------------------------------------------------
13
-- Description: 
14
-------------------------------------------------------------------------------
15
 
16
architecture Bhv of ICS307 is
17
  signal ShiftIn           : std_ulogic_vector (23 downto 0);
18
  signal GenClock          : std_ulogic := '0';
19
  signal Clk1CurrentPeriod : time       := 1 sec / gInputFrequency;
20
  signal DeltaPeriod       : time       := 0 ps;
21
  signal Clk1TargetPeriod  : time       := 1 sec / gInputFrequency;
22
  signal TargetTime        : time       := now;
23
begin
24
 
25
  -- Shift data in from SPI interface of ICS307
26
  ShiftInFromSpi : process (iSclk) is
27
  begin
28
    if iSclk'event and iSclk = '1' then
29
      ShiftIn <= ShiftIn(ShiftIn'high-1 downto 0) & iData;
30
    end if;
31
  end process ShiftInFromSpi;
32
 
33
 
34
  -- The data sheet gives a few constraints we should keep an eye on.
35
  assert gInputFrequency < 27E6 and gInputFrequency > 5E6
36
    report "Invalid input frequency value!"
37
    severity warning;
38
 
39
  NewTargetPeriod : process is
40
    -- The default value the ICS307 has after power up
41
    variable vDataReceived              : std_ulogic_vector (23 downto 0) := X"230406";
42
    variable vOutDiv                    : natural                         := 1;
43
    variable vVdw                       : natural                         := 1;
44
    variable vRdw                       : natural                         := 1;
45
    variable vCyclesToSpendInTransition : natural;
46
  begin
47
    wait until iStrobe = '1';
48
    wait until iStrobe = '0';
49
    -- Latch what you shifted up until now.
50
    vDataReceived := ShiftIn;
51
    -- The divider values are part of the bit field latched in.
52
    case vDataReceived(18 downto 16) is
53
      when "000"  => vOutDiv := 10;
54
      when "001"  => vOutDiv := 2;
55
      when "010"  => vOutDiv := 8;
56
      when "011"  => vOutDiv := 4;
57
      when "100"  => vOutDiv := 5;
58
      when "101"  => vOutDiv := 7;
59
      when "110"  => vOutDiv := 3;
60
      when "111"  => vOutDiv := 6;
61
      when others =>
62
        report "OD has no valid value!"
63
          severity warning;
64
    end case;
65
    vVdw := to_integer(unsigned(vDataReceived(15 downto 7)));
66
    assert vVdw > 3
67
      report "Vdw is required to be greater than 3!"
68
      severity warning;
69
    assert vVdw < 512
70
      report "Vdw required to be smaller than 512"
71
      severity warning;
72
    vRdw := to_integer(unsigned(vDataReceived(6 downto 0)));
73
    assert vRdw > 0
74
      report "Rdw required to be greater than 0!"
75
      severity warning;
76
    Clk1TargetPeriod <=
77
      ((1 sec) * ((vRdw+2)*vOutDiv)) / (gInputFrequency*2*(8+vVdw));
78
    wait for 0 ns;
79
    TargetTime <=
80
      now + gClkFrequcenyTransitionTime;
81
    assert (gClkFrequcenyTransitionTime > 1 us and gClkFrequcenyTransitionTime <= 10 ms)
82
      report "Frequency transition time has to be in the range ]0 ms,10 ms]!"
83
      severity error;
84
    -- If the period would be the average of the current and the target period,
85
    -- how many cycle would transition take?
86
    vCyclesToSpendInTransition :=
87
      gClkFrequcenyTransitionTime /
88
      ((Clk1TargetPeriod+Clk1CurrentPeriod)/2);
89
    -- What is the time difference from one cycle to the next? It maybe negative!
90
    DeltaPeriod <= (Clk1TargetPeriod - Clk1CurrentPeriod) / vCyclesToSpendInTransition;
91
  end process NewTargetPeriod;
92
 
93
 
94
  -- From the moment the data is latched in the clock frequency makes a smooth
95
  -- transition from the current frequency to the programmed frequency in
96
  -- gClkFrequcenyTransitionTime
97
  GenClkCycle : process is
98
    variable vTimeToSpendInTransition : time := 0 ps;
99
    variable vClk1CurrentPeriod       : time := 1 sec / gInputFrequency;
100
  begin
101
    -- How long to go until the target period should be reached?
102
    if TargetTime > now then
103
      vTimeToSpendInTransition := TargetTime-now;
104
    else
105
      vTimeToSpendInTransition := 0 ps;
106
    end if;
107
    if vTimeToSpendInTransition > Clk1TargetPeriod then
108
      -- Determine the current period
109
      -- Adapt the current period to get a little closer to the target value.
110
      vClk1CurrentPeriod := vClk1CurrentPeriod + DeltaPeriod;
111
    else
112
      vClk1CurrentPeriod := Clk1TargetPeriod;
113
    end if;
114
    -- Make current period available to other processes
115
    Clk1CurrentPeriod <= vClk1CurrentPeriod;
116
 
117
    -- Generate the internal clock.
118
    oClk1 <= '0';
119
    wait for vClk1CurrentPeriod/2;
120
    oClk1 <= '1';
121
    wait for vClk1CurrentPeriod/2;
122
  end process GenClkCycle;
123
 
124
end Bhv;  -- of ICS307
125
 
126
 
127
 
128
 
129
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.