24小时热门版块排行榜    

查看: 2069  |  回复: 2

fxx5013572

新虫 (初入文坛)

[求助] VHDL状态机A/D采样控制电路实现

(老师说程序有错  请高手指点!谢谢! 请帮忙给个正确的程序!         哪几个输入需要自己设置的???)
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ADCINT IS
    PORT(D  : IN STD_LOGIC_VECTOR(7 DOWNTO 0);  --来自0809转换好的8位数据
CLK  : IN STD_LOGIC;                          --状态机工作时钟
EOC  : IN STD_LOGIC;                  --转换状态指示,低电平表示正在转换
ALE  : OUT STD_LOGIC;                 --8个模拟信号通道地址锁存信号
START  : OUT STD_LOGIC;                 --转换开始信号
OE  : OUT STD_LOGIC;                 --数据输出3态控制信号
ADDA  : OUT STD_LOGIC;                --信号通道最低位控制信号
LOCK0  : OUT STD_LOGIC;               --观察数据锁存时钟
Q  : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)); --8位数据输出
END ADCINT;
ARCHITECTURE behav OF ADCINT IS
TYPE states IS (st0, st1, st2, st3,st4) ; --定义各状态子类型
  SIGNAL current_state, next_state: states :=st0 ;
  SIGNAL REGL : STD_LOGIC_VECTOR(7 DOWNTO 0);
  SIGNAL LOCK : STD_LOGIC; -- 转换后数据输出锁存时钟信号
BEGIN
ADDA <= '1';--当ADDA<='0',模拟信号进入通道IN0;当ADDA<='1',则进入通道IN1
Q <= REGL; LOCK0 <= LOCK ;
  COM: PROCESS(current_state,EOC)  BEGIN  --规定各状态转换方式
   CASE current_state IS           
   WHEN st0=>ALE<='0';START<='0';LOCK<='0';OE<='0';  next_state <= st1; --0809初始化
   WHEN st1=>ALE<='1';START<='1';LOCK<='0';OE<='0';  next_state <= st2; --启动采样
   WHEN st2=> ALE<='0';START<='0';LOCK<='0';OE<='0';   
     IF (EOC='1') THEN next_state <= st3; --EOC=1表明转换结束
         ELSE next_state <= st2;  END IF ;    --转换未结束,继续等待
   WHEN st3=> ALE<='0';START<='0';LOCK<='0';OE<='1'; next_state <= st4;--开启OE,输出转换好的数据
   WHEN st4=> ALE<='0';START<='0';LOCK<='1';OE<='1'; next_state <= st0;
   WHEN OTHERS => next_state <= st0;  
   END CASE ;
END PROCESS COM ;
  REG: PROCESS (CLK)  
    BEGIN
     IF (CLK'EVENT AND CLK='1') THEN current_state<=next_state; END IF;
   END PROCESS REG ;      -- 由信号current_state将当前状态值带出此进程:REG
  LATCH1: PROCESS (LOCK) -- 此进程中,在LOCK的上升沿,将转换好的数据锁入
         BEGIN
        IF LOCK='1' AND LOCK'EVENT THEN   REGL <= D ; END IF;
       END PROCESS LATCH1 ;
  END behav;[ Last edited by fxx5013572 on 2011-8-31 at 10:02 ]
回复此楼
希望多学到点东西...
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119

木虫 (著名写手)

引用回帖:
1楼: Originally posted by fxx5013572 at 2011-08-30 10:39:17:
(老师说程序有错  请高手指点!谢谢! 请帮忙给个正确的程序!         哪几个输入需要自己设置的???)
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ADCINT IS
    PORT(D  : IN STD_LOGIC_VECTOR( ...

altera quartus下面的?还是cadence下面的?
好好学习,天天向上。
2楼2011-11-23 16:29:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

黑色风信子

荣誉版主 (文坛精英)

皇家神龍教KOKO或KOKO猪

【答案】应助回帖

感谢参与,应助指数 +1
我给你个可用的ADC0804直流采样和显示的程序吧
--ADC0804直流采样和显示
--输入电压范围0-5V,显示0-255数位
--**************库定义、 包定义********************
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--******************实体定义***********************
entity adc0804_new is
port(
  reset          : in         std_logic;--复位输入
  clk                  : in         std_logic;--主时钟输入
  intr          : in         std_logic;--AD转换结束输入
  data_i         : in         std_logic_vector(7 downto 0);--数据输入
  data_o         : out         std_logic_vector(7 downto 0);--数码管数据输出
  l                        : out         STD_LOGIC_VECTOR(5 downto 0);--输出数码管位选
  bell                : out        std_logic;--蜂鸣器
  cs                  : out std_logic;--使能
  wr                  : out std_logic;--写控制
  rd                  : out std_logic--读控制
  );
end adc0804_new;
--******************结构体***********************
architecture Behavioral of adc0804_new is

type state is (start, convert, read1, read2);--状态机定义
signal current_state, next_state : state;--状态定义
signal read_data : std_logic;--读数据寄存器
signal clock : std_logic;--扫描时钟
signal p : integer range 0 to 255;--数据寄存器
signal b0,b1,b2 : integer range 0 to 9;--3位数码管显示数据寄存器
signal cnt : integer range 0 to 3:=0;--扫描寄存器
begin
bell<='1';
--********************显示进程**********************************
process(p,clk)
        begin
                case p is
                        when 0|10|20|30|40|50|60|70|80|90|100|110|120|130|140|150|160|170|180|190|200|210|220|230|240|250=>b0<=0;
                        when 1|11|21|31|41|51|61|71|81|91|101|111|121|131|141|151|161|171|181|191|201|211|221|231|241|251=>b0<=1;
                        when 2|12|22|32|42|52|62|72|82|92|102|112|122|132|142|152|162|172|182|192|202|212|222|232|242|252=>b0<=2;
                        when 3|13|23|33|43|53|63|73|83|93|103|113|123|133|143|153|163|173|183|193|203|213|223|233|243|253=>b0<=3;
                        when 4|14|24|34|44|54|64|74|84|94|104|114|124|134|144|154|164|174|184|194|204|214|224|234|244|254=>b0<=4;
                        when 5|15|25|35|45|55|65|75|85|95|105|115|125|135|145|155|165|175|185|195|205|215|225|235|245|255=>b0<=5;
                        when 6|16|26|36|46|56|66|76|86|96|106|116|126|136|146|156|166|176|186|196|206|216|226|236|246=>b0<=6;
                        when 7|17|27|37|47|57|67|77|87|97|107|117|127|137|147|157|167|177|187|197|207|217|227|237|247=>b0<=7;
                        when 8|18|28|38|48|58|68|78|88|98|108|118|128|138|148|158|168|178|188|198|208|218|228|238|248=>b0<=8;
                        when 9|19|29|39|49|59|69|79|89|99|109|119|129|139|149|159|169|179|189|199|209|219|229|239|249=>b0<=9;
                        when others=>--b0<=10;
                end case;
               
                                case p is
                        when 0|1|2|3|4|5|6|7|8|9|100|101|102|103|104|105|106|107|108|109|200|201|202|203|204|205|206|207|208|209=>b1<=0;
                        when 10|11|12|13|14|15|16|17|18|19|110|111|112|113|114|115|116|117|118|119|210|211|212|213|214|215|216|217|218|219=>b1<=1;
                        when 20|21|22|23|24|25|26|27|28|29|120|121|122|123|124|125|126|127|128|129|220|221|222|223|224|225|226|227|228|229=>b1<=2;
                        when 30|31|32|33|34|35|36|37|38|39|130|131|132|133|134|135|136|137|138|139|230|231|232|233|234|235|236|237|238|239=>b1<=3;
                        when 40|41|42|43|44|45|46|47|48|49|140|141|142|143|144|145|146|147|148|149|240|241|242|243|244|245|246|247|248|249=>b1<=4;                       
                        when 50|51|52|53|54|55|56|57|58|59|150|151|152|153|154|155|156|157|158|159|250|251|252|253|254|255=>b1<=5;
                        when 60|61|62|63|64|65|66|67|68|69|160|161|162|163|164|165|166|167|168|169=>b1<=6;
                        when 70|71|72|73|74|75|76|77|78|79|170|171|172|173|174|175|176|177|178|179=>b1<=7;
                        when 80|81|82|83|84|85|86|87|88|89|180|181|182|183|184|185|186|187|188|189=>b1<=8;
                        when 90|91|92|93|94|95|96|97|98|99|190|191|192|193|194|195|196|197|198|199=>b1<=9;
                        when others=>--b0<=10;
                end case;
                if p<100 then
                        b2<=0;
                elsif p>=100 and p<200 then
                        b2<=1;
                elsif p>=200 then
                        b2<=2;
                end if;
end process;
--**********************分频进程*************************
process(clk)
        variable cnt1 : integer range 0 to 100;
        variable cnt2 : integer range 0 to 20;
        begin
                if clk'event and clk='1' then
                if cnt1=100 then
                        cnt1:=0;
                        if cnt2=20 then
                                cnt2:=0;
                                clock<=not clock;
                                if(cnt=3)then
                                        cnt<=0;
                                else
                                        cnt<=cnt+1;
                                end if;
                        else
                                cnt2:=cnt2+1;
                        end if;
                else
                        cnt1:=cnt1+1;
                end if;
        end if;
end process;
--**************状态驱动进程**********************
sync :process(clock,reset)
begin
  if(reset = '0') then
   current_state <= start;
  elsif(clock'event and clock='1') then
   current_state <= next_state;
  end if;
end process sync;
--***************adc0804驱动进程*******************
comb :process(current_state, intr)
begin
  case current_state is
   when start =>                                 --启动状态
    next_state <= convert;
    cs <= '0';
    wr <= '0';
    rd <= '1';
    read_data <= '0';
   when convert =>--初始化
    if(intr = '0') then
     next_state <= read1;
    else
     next_state <= convert;
    end if;
    cs <= '1';
    wr <= '1';
    rd <= '1';
    read_data <= '0';
   when read1 =>--读状态1
    next_state <= read2;
    cs <= '0';
    wr <= '1';
    rd <= '0';
    read_data <= '1';
   when read2 =>--读状态2
    next_state <= start;
    cs <= '1';
    wr <= '1';
    rd <= '1';
    read_data <= '0';
   when others =>--其他状态
    next_state <= start;
  end case;
end process comb;
--****************读取AD数据********************
get_data: process(clock,reset)
begin
  if(reset = '0') then
   p<=0;
  elsif(clock'event and clock='1') then
   if(read_data = '1') then
    p<=conv_integer(data_i);
   end if;
  end if;
end process;
--********************显示进程***************************************
process(cnt)
          FUNCTION b_to_s7(bcd8421:INTEGER RANGE 0 TO 9) RETURN STD_LOGIC_VECTOR IS
       VARIABLE smg7: STD_LOGIC_VECTOR(7 DOWNTO 0);
       BEGIN
        CASE bcd8421 IS                                                                        --计算输出值
              WHEN 0 => smg7:="11111100";                                        --abcdefgh
              WHEN 1 => smg7:="01100000";
              WHEN 2 => smg7:="11011010";
              WHEN 3 => smg7:="11110010";
              WHEN 4 => smg7:="01100110";
              WHEN 5 => smg7:="10110110";
          WHEN 6 => smg7:="10111110";
              WHEN 7 => smg7:="11100000";
              WHEN 8 => smg7:="11111110";
              WHEN 9 => smg7:="11110110";
                  WHEN OTHERS=>smg7:="10001110";
       END CASE;
       RETURN smg7;
      END b_to_s7;
   begin
                        case cnt is
                                 when 0 => l<="111110";data_o<=b_to_s7(b0);
                                 when 1 => l<="111101";data_o<=b_to_s7(b1);
                                when 2 => l<="111011";data_o<=b_to_s7(b2);
                                when others=>l<="111111";--data_o<=b_to_s7(8);
                        end case;
end process;
end Behavioral;
以后多交流哦,如果有事儿,可站内联系我
如果你哭,你的对手就会笑。如果你笑,你的对手就会哭。人生就像愤怒的小鸟,每次你失败的时候,总有几只猪在笑。你要做的就是无视嘲笑的声音,给自己打气。自.
3楼2012-02-10 15:50:25
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 fxx5013572 的主题更新
信息提示
请填处理意见