首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要增量pwm_count变量吗?

我需要增量pwm_count变量吗?
EN

Stack Overflow用户
提问于 2019-05-07 22:35:43
回答 1查看 69关注 0票数 0

我现在正在学习VHDL语言,我在理解课程中的一部分代码时遇到了一些问题。我不能理解if(pwm_count < max_pwm_count),,freq_counter,->,max_pwm_count,的值,我看不到变量pwm_count,的任何增量。

谢谢,伙计们!

代码语言:javascript
复制
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use  IEEE.numeric_std.all;

entity PWM is
    generic ( 
        freq            : integer := 50; --50Hz
        INPUT_CLK       : integer := 50000000; --50MHz
        BITH_DEPTH      : integer := 8
          );

    Port (    
       ENABLE       : in std_logic;
       CLK          : in std_logic;
       PWM_OUT      : out std_logic;
       DUTY_CYCLE   : in std_logic_vector(BITH_DEPTH-1 downto 0)
          );

end PWM;

architecture behavioral of PWM is

constant max_freq_count    :     integer:= INPUT_CLK/freq;
constant pwm_step          :     integer := max_freq_count/2**BITH_DEPTH;

signal PWM_value        :  std_logic := '0';
signal freq_count       :  integer range from 0 to max_freq_count := 0;
signal pwm_count        :  integer range from 0 to 2**BITH_DEPTH := 0;
signal max_pwm_count    :  integer range from 0 to 2**BITH_DEPTH := 0;
signal pwm_step_count   :  integer range from 0 to max_freq_count := 0;

begin

max_pwm_count <= TO_INTEGER(unsigned(DUTY_CYCLE));
PWM_OUT <= PWM_value;

freq_counter: process(CLK)
begin
if rising_edge(CLK) then 
    if(ENABLE='0') then
       if(freq_count < max_freq_count) then
            freq_count <= freq_count + 1;  
                if(pwm_count < max_pwm_count) then 
                    PWM_value<='1';
                    if(pwm_step_count<pwm_step) then
                        pwm_step_count<=pwm_step_count+1;
                    else
                        pwm_step_count<=0;
                        pwm_count<=0;
                    end if;
                else
                    pwm_value<='0';
                end if;
       else
            freq_count <= 0;
            pwm_count <= 0;
       end if;
    else 
        PWM_value <= '0';
    end if;
end if;
end process freq_counter;

end PWM;
EN

回答 1

Stack Overflow用户

发布于 2019-05-13 01:22:33

我们知道max_pwm_count的值:它被初始化为0,并且永远不会重新赋值。所以如果永远不会是真的.等等。

就增量PWM_Count而言,您的理解似乎比作者更好,这使您处于一个合理的位置,可以进行必要的重写。

我建议先写一个测试平台,这样你就可以观察它的行为,并在模拟中得到正确的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56025012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档