OpenCores
URL https://opencores.org/ocsvn/modbus/modbus/trunk

Subversion Repositories modbus

[/] [modbus/] [trunk/] [enlace/] [pondera_top.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 guanucolui
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
 
6
--  Uncomment the following lines to use the declarations that are
7
--  provided for instantiating Xilinx primitive components.
8
--library UNISIM;
9
--use UNISIM.VComponents.all;
10
 
11
entity pondera_top is
12
        port(
13
                clk:    in std_logic;
14
                reset:  in std_logic;
15
                bin_HL: in std_logic_vector(7 downto 0);
16
                new_data:       in std_logic;
17
                trama_ok: in std_logic;
18
                bin:            out std_logic_vector(7 downto 0);
19
                bin_ok: out std_logic
20
        );
21
end pondera_top;
22
 
23
 
24
architecture Behavioral of pondera_top is
25
 
26
signal Sdata_H :std_logic_vector(7 downto 0):=(others=>'0');
27
signal Sdata_L :std_logic_vector(7 downto 0):=(others=>'0');
28
 
29
--Insert the following in the architecture before the begin keyword
30
   --Use descriptive names for the states, like st1_reset, st2_search
31
   type state_type is (st1_espera, st2_data_H, st3_data_L, st4_calculo);
32
   signal state, next_state : state_type;
33
   --Declare internal signals for all outputs of the state machine
34
   signal Sbin_ok: std_logic:='0';
35
begin
36
 
37
-- This is a sample state machine using enumerated types.
38
-- This will allow the synthesis tool to select the appropriate
39
-- encoding style and will make the code more readable.
40
 
41
 
42
   --other outputs
43
 
44
--Insert the following in the architecture after the begin keyword
45
   SYNC_PROC: process (clk, reset)
46
   begin
47
      if (reset='1') then
48
         state <= st1_espera;
49
      elsif (clk'event and clk = '1') then
50
         state <= next_state;
51
         --bin <= Sbin;
52
            bin_ok <= Sbin_ok;
53
         -- assign other outputs to internal signals"        
54
      end if;
55
   end process;
56
 
57
   --MOORE State Machine - Outputs based on state only
58
   OUTPUT_DECODE: process (state)
59
   begin
60
      --insert statements to decode internal output signals
61
      --below is simple example
62
      if state = st1_espera then
63
                Sbin_ok <= '0';
64
      end if;
65
 
66
      if state = st2_data_H  then
67
         Sdata_H <= bin_HL; --almacena el primer dato en una seņal para ser ponderada
68
         end if;
69
 
70
         if state = st3_data_L  then
71
                Sdata_L <= bin_HL; --almacena el segundo dato en una seņal para ser ponderada
72
         end if;
73
 
74
         if state = st4_calculo then
75
                bin <= Sdata_H(3 downto 0)&"0000" + Sdata_L;
76
                Sbin_ok <= '1';
77
         end if;
78
   end process;
79
 
80
   NEXT_STATE_DECODE: process (state, new_data)
81
   begin
82
      --declare default state for next_state to avoid latches
83
      next_state <= state;  --default is to stay in current state
84
      --insert statements to decode next_state
85
      --below is a simple example
86
      case (state) is
87
            when st1_espera =>
88
                        if new_data = '1' and trama_ok = '1' then
89
                                next_state <= st2_data_H;
90
                        end if;
91
            when st2_data_H =>
92
                        if new_data = '1' then
93
                next_state <= st3_data_L;
94
                end if;
95
         when st3_data_L=>
96
               next_state <= st4_calculo;
97
         when st4_calculo =>
98
                next_state <= st1_espera;
99
         when others =>
100
                next_state <= st1_espera;
101
      end case;
102
   end process;
103
 
104
end Behavioral;

powered by: WebSVN 2.1.0

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