Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Trying to on led using the input from pir sensor

Hi guys im very new in VHDL and im trying to write a program as to turn on an LED from the GPIO_0 which i put a PIR sensor to it..the PIR sensor is directly connectted to GPIO_O(0).. so the problem is that when i run the program some error show up and i havent have any idea how to correct it back. please help me guys..

:):):)

15 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    There are several problems here. I would suggest to read a book or an online course on VHDL first.

    use IEEE.STD_LOGIC_SIGNED;
    use IEEE.STD_LOGIC_UNSIGNED;
    use ieee.std_logic_1164.all;
    use IEEE.numeric_std.all;
    please don't do that. The non standard std_logic_signed and std_logic_unsigned cause many problems, especially when used at the same time than numeric_std. If you include both it is even worse because the operators on std_logic_vector are overloaded for both signed and unsigned operations. There is no way to know what will happen. Please only include std_logic_1164 and numeric_std

    variable count:std_logic_vector(2 downto 0) := "000";
    as you are using numeric_std, you can declare this variable as an unsigned instead of std_logic_vector, and that way you can use the + and - operators on it.

    count := DIN;
    once you change count to the unsigned type, this line won't work any more because count and DIN are different types. Either change the DIN port to also be an unsigned, or do an explicit cast:

    count := unsigned(DIN);

    count := "count+1 >";
    there are several syntax errors there. I don't know where the '>' is coming from, and the quotes "" are only used to specify a literal value. If you just want to increase the counter, do

    count := count+1;

    Your code doesn't do anything yet when the counter reaches its final value.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hm base on your explanation mr daixiwen how should i program my counter so that the output can hold at any time. how about some example or tutorial that i can refer to..tq mr daixiwen

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I don't know any example or tutorial about this subject, it is a rather trivial VHDL construction. Just have a counter value that you increase or decrease and do something when it reaches a predetermined value.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i am creating a program tO TURN ON LED USINg switches from the de2 board. the problem is the program runs without errror just warning. and while i test it on my de2 board it doesnot goes as plan. so for my program is there is 3 switch the first switch must be turn on and the led will turn on, the second switch will turn on the second led and the 3rdrn on both switch also will turn the 3 led.. i wanted the first switch to be the main controller.. if the first switch does not turn switch 2 and 3 cannot turn on the led.. but when i try runn it with my de2 it doesnot work that way. only 1 led turn on.. i have set the pin assignment correctly..really need some advice on sloving this tq in advance

    entity Mux is

    port(

    A_bus : in std_logic_vector(2 downto 0);

    output : out std_logic_vector(2 downto 0));

    end Mux;

    architecture arc_nnmux of Mux is

    begin

    process(A_bus)

    begin

    if A_bus <= (2=>'0',1=> '0', 0=>'1')then

    output <="001";

    elsif A_bus <=(2=>'0',1=>'1',0=>'1')then

    output <="011";

    elsif A_bus <=(2=>'1',1=>'1',0=>'1')then

    output <="111";

    else output<= "000";

    end if;

    end process;

    end arc_nnmux;
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You code is rather confusing. Instead of using the <= operator I think it would be a lot easier to check individual bits of A_bus in your ifs. It would make the priority order more visible.

    What do you call "first switch"? Is it the one connected to A_bus(0) or A_bus(2)?

    Did you check the polarity of the switch and led signals?