电机的PWM控制

设计电机转速与转向控制电路,要求该控制电路能够实现电机转向控制、转速控制,该综合设计包含如下模块的设计工作:
1.计数器、比较器模块。
2.电机速度控制电路:要求电机速度能够四档可调。
3.电机方向控制电路。
写出设计代码,给出仿真波形。

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;



entity MOTOR_PWM is

    port( CLK : in std_logic;

          speed : in std_logic_vector(3 downto 0);

          direction_control : in std_logic;

          positive : out std_logic;

          negative : out std_logic);

end MOTOR_PWM;



architecture BHV of MOTOR_PWM is

signal T, CNT : std_logic_vector(4 downto 0);

signal PWM : std_logic;

begin

    process(CLK)

    begin

        if rising_edge(CLK) then

            CNT <= CNT + 1;

        end if;

    end process;

    

    process(speed)

    begin

        case speed is 

            when "0111"=>

                T <= "00001";

            when "1011"=>

                T <= "00011";

            when "1101"=>

                T <= "00111";

            when "1110"=>

                T <= "01111";

            when others=>

                T <= "00000";

        end case;

    end process;

    

    process(T, CNT)

    begin

        if (CNT <= T) then

            PWM <= '0';

        else

            PWM <= '1';

        end if;

    end process;

    

    process(PWM, direction_control)

    begin

        if (direction_control = '0') then

            positive <= PWM;

            negative <= '0';

        else

            positive <= '0';

            negative <= PWM;

        end if;

    end process;

end BHV;



扫一扫在手机打开当前页