Forum: FPGA, VHDL & Co. VHDL. Genau 1 Clock Tick Generieren (Synthesierbar)


von Jonathan S. (psihodelia)


Lesenswert?

Hello,
how to get only one clock impulse ?
I need smth. to be synthesized, but readable as well.

I have two ideas but they look not very good readable (or short). So, 
maybe there is an another approach?

short but dirty:
1
process(CLK)
2
variable tmp;
3
begin
4
  if rising_edge(CLK) then
5
    impulse <= '0';
6
    if (some_event='1') and (tmp='0') then
7
      impulse <= '1';
8
    end if;
9
    tmp := some_event;
10
  end if;
11
end process;

readable but long:
1
p1:process(clk)
2
  begin
3
    if clk'event and clk = '1' then
4
      if some_event = '1' then
5
        generate_impulse = '1';
6
      end if;
7
    end if;
8
  end process p1;
9
10
p2:process(clk)
11
  begin
12
    if clk'event and clk = '0' then
13
      if some_event = '1' then
14
        generate_impulse = '0';
15
      end if;
16
    end if;
17
  end process p2;
18
19
p3:process(generate_impulse)
20
  begin
21
    if generate_impulse = '1' then
22
      impulse = '1';
23
    else
24
      impulse = '0'
25
    end if;
26
  end process p3;

von Joerg W. (joergwolfram)


Lesenswert?

In my opinion, the best way is to use a FSM or counter
1
signal zcount: std_logic_vector(1 downto 0);
2
3
process clk is
4
begin
5
   if rising_edge(clk) then
6
      if ((zcount="00") and (some_event='0')) or
7
         ((zcount="01") and (some_event='1')) or
8
         (zcount(1)='1') then
9
            zcount <= zcount+1;
10
      end if;
11
   end if;
12
end process;
13
14
impulse <= zcount(1) and not(zcount(0));

greetings by Joerg

von na (Gast)


Lesenswert?

Your second solution would not run because of multiple driven sources 
(generate_impulse cannot be written by two processes). Your first way is 
not really dirty. If you want to use no FSM, try this:
1
process(CLK)
2
begin
3
  if rising_edge(CLK) then
4
    impulse <= (not impulse) and some_event;
5
  end if;
6
end process;
In the beginning "impulse" has to be set to "0" of course.

von TheMason (Gast)


Lesenswert?

something similar (nearly the same) to the solution of na would be  :

signal input_z1 : signal;

process (clk,res)
begin
  if res = '1' then
    input_z1 <= '0';
  elsif rising_edge (clk) then
    input_z1 <= input;
    pulse_out <= input and not input_z1;
  end if;
end process;

the precondition to this one is that your input-signal is synchronous to 
your clk.

hope it'll help
greetz

rene

von na (Gast)


Lesenswert?

Okay, I think my solution does not work for your application because I 
misunderstood the problem.
Do you only want to implement a reaction on the first "some_event" 
signal (my way) or on all icoming "some_event" signals (the other 
mentioned possibilities)? Do you want to implement a debounce unit or 
sth. like that?

von Jonathan S. (psihodelia)


Lesenswert?

Joerg Wolfram wrote:
> In my opinion, the best way is to use a FSM or counter
> greetings by Joerg

nein, dein Beispiel mit Counter wird zu viel Platz benötigen. Es muss 
etwas existieren mit Feedback - wahrscheinlich zwei Flip-Flops, ein AND 
und ein Feedback, oder ?

von Jonathan S. (psihodelia)


Lesenswert?

na wrote:
> Do you only want to implement a reaction on the first "some_event"
> signal (my way) or on all icoming "some_event" signals (the other
> mentioned possibilities)?

yes, on all incoming some_event signals. for example:
 after a key is pressed, one impulse should be generated. his length 
schould be exactly one clock impulse (or variable length, e.g. N clock 
impulses)

von Rick Dangerus (Gast)


Lesenswert?

Take a look at this page:

http://www.ibrtses.com/electronics/fpgabasic.html
(Detecting a signal change)

Make an vhdl-description shouldn't be a big problem.

Rick

von Jonathan S. (psihodelia)


Lesenswert?

Rick Dangerus wrote:
> Take a look at this page:
>
> http://www.ibrtses.com/electronics/fpgabasic.html

thank you very much, this is very useful page

von Joerg W. (joergwolfram)


Lesenswert?

im fpgabasic-Beispiel ist die Länge des Ausgangsimpulses nur dann 1 
clockperide lang, wenn das Eingangssignal synchron zum Clock ist. Tritt 
die Flanke zwischen den Clockflanken auf, verlängert sich der Impuls 
entsprechend und der Impulsanfang ist nicht synchron zum Takt.
Ausserdem werden kurze Impulse zwischen den Taktflanken direkt zum 
Ausgang weitergeleitet.
Der Zähler besteht auch nur aus 2 FlipFlops und etwas Logik, wenn der 
Impuls auch 2 Taktperioden lang sein darf, kann zcount(1) als 
Impulsausgang genutzt werden.

Gruß Jörg

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.