Forum: FPGA, VHDL & Co. Mehrbit A2D Wandler in VHDL-AMS


von Niko (Gast)


Lesenswert?

Hello World =)
Vielleicht kennt sich jemand besser aus mit AMS, als ich! Aufgabe ist, 
einen AD-Wandler zu schreiben, der für eine Eingangsspannung zwischen 0 
und 5 V 8 digitale Werte ausgibt. Hier mein Code:
--library ieee;
--use ieee.electrical_systems.all;
LIBRARY DISCIPLINES;      -- Ich benutze hAMSter
USE DISCIPLINES.ELECTROMAGNETIC_SYSTEM.ALL;

entity a2d is
generic (vthreshold : real := 0.625);
        port (D_output : out bit_vector (2 downto 0);
        terminal a_input, electrical_ref : electrical);
end entity a2d;

architecture behavioral of a2d is
quantity vin ACROSS a_input to electrical_ref;
begin
process (vin) is

begin
IF (vin'above(vthreshold)) then   -- 0 - 0,625 V
d_output <= '000';
ELSE IF  (vin'above(vthreshold*2)) then   -- 0,626 - 1,25 V
d_output <=           '001';
ELSE IF  (vin'above(vthreshold*3)) then   -- ... - 1,875 V
d_output <=            '010';
ELSE IF  (vin'above(vthreshold*4)) then   -- ... - 2,5 V
d_output <=            '011';
ELSE IF  (vin'above(vthreshold*5)) then   -- ... - 3,125 V
d_output <=            '100';
ELSE IF    (vin'above(vthreshold*6)) then   -- ... - 3,75 V
d_output <=            '101';
ELSE IF    (vin'above(vthreshold*7)) then   -- ... - 4,375 V
d_output <=            '110';
ELSE    -- (vin'above(vthreshold*8)) then   -- ... - 5 V
d_output <=            '111';
end process;
end architecture behavioral;

begin
vin == sin(2.0  math_pi  f * NOW);
end;

Ich müsste unbedingt noch abgrenzen, also z.B. '001' bei (not 
(vin'above(vthreshold)) && vin'above(vthreshold*2)) oder so...
Hat jemand eine Idee?

von Mathi (Gast)


Lesenswert?

Hi,

wie wäre es einfach die Reihenfolge der Abfragen zu vertauschen. Also 
erst auf die höchste Spannung abzufragen, dann auf die zweithöchste, ...

Gruß

von Niko (Gast)


Lesenswert?

Mein Simulator hAMSter scheint diese Ausdrücke nicht zu mögen: 
vthreshold*7
Ist es micht so, dass man auch den Rest ausschließen muss??


LIBRARY DISCIPLINES;
USE DISCIPLINES.ELECTROMAGNETIC_SYSTEM.ALL;

entity a2d is
generic (vthreshold : real := 0.625);
        port (D_output : out bit_vector (2 downto 0);
        terminal a_input, electrical_ref : electrical);
end entity a2d;

architecture behavioral of a2d is
quantity vin ACROSS a_input to electrical_ref;
begin
process (vin) is

begin
IF (vin'above(vthreshold*7)) then   -- ... - 5 V  7*vthreshold
d_output <= "111";
ELSE IF  (vin'above(vthreshold*6)) then   --  ... - 4,375 V
d_output <=           "110";
ELSE IF  (vin'above(vthreshold*5)) then   --   ... - 3,75 V
d_output <=            "101";
ELSE IF  (vin'above(vthreshold*4)) then   --   ... - 3,125 V
d_output <=            "100";
ELSE IF  (vin'above(vthreshold*3)) then   --   ... - 2,5 V
d_output <=            "011";
ELSE IF    (vin'above(vthreshold*2)) then   --   ... - 1,875 V
d_output <=            "010";
ELSE IF    (vin'above(vthreshold)) then   --   0,626 - 1,25 V
d_output <=            "001";
ELSE    --                                --   0 - 0,625 V
d_output <=            "000";
end process;
end architecture behavioral;

begin
vin == sin(2.0  math_pi  f * NOW);
end;

von J. S. (engineer) Benutzerseite


Lesenswert?

Ich würde den Term mit dem Threshhold getrennt ausrechnen und damit den 
Multiplexer statisch machen. Im Grunde kannst Du diesen einfache ADC 
aber auch voll analytisch schreiben, da er ja offenbar global linear 
ist.

AMS braucht man ja im Grunde nur bei partiell nichtlinearem Verhalten 
wie bei gesättigtem und invertiertem Kurvenverhalten sowie bei 
nichtlinearen Energiespeichern wie diesen hier:

Beitrag "Re: Simulation von Spulen und Übertragern in VHDL"

von Niko (Gast)


Lesenswert?

Das hier funktioniert nicht: Unerwartete Eingabe: PROCESS

LIBRARY DISCIPLINES;
USE DISCIPLINES.ELECTROMAGNETIC_SYSTEM.ALL;

entity a2d is
        port (D_output : out bit_vector (2 downto 0);
        terminal a_input, electrical_ref : electrical);
end entity a2d;

architecture behavioral of a2d is
quantity vin ACROSS a_input to electrical_ref;
begin
process (vin) is

begin
IF vin'above(4.375) then   -- ... - 5 V  7*vthreshold
d_output <= "111";
ELSIF  vin'above(3.75) then   --  ... - 4,375 V
d_output <=           "110";
ELSIF  vin'above(3.125) then   --   ... - 3,75 V
d_output <=            "101";
ELSIF  vin'above(2.5) then   --   ... - 3,125 V
d_output <=            "100";
ELSIF  vin'above(1.875) then   --   ... - 2,5 V
d_output <=            "011";
ELSIF    vin'above(1.25) then   --   ... - 1,875 V
d_output <=            "010";
ELSIF    vin'above(0.625) then   --   0,626 - 1,25 V
d_output <=            "001";
ELSE    --                                --   0 - 0,625 V
d_output <=            "000";

end process;  -- Fehler: unerwartete Eingabe: Process
end architecture behavioral;

begin
vin == sin(2.0  math_pi  f * NOW);
end;

von J. S. (engineer) Benutzerseite


Lesenswert?

Da fehlt eine Klammer

von Niko (Gast)


Lesenswert?

port (D_output : out bit_vector (2 downto 0);
 terminal (a_input, electrical_ref : electrical);

Wenn Du die meinst, dann heißt es "unerwartete Eingabe"!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.