Bonjour

J'ai le projet de mettre en place via un FPGA une commande de servomoteur inversée. Le signal de commade et deja généré, je n'ai plus qu'a le traiter.
Sachant que la commande est un signal de période 20ms, ainsi qu'une position médiane de 1,5ms, de plus, sa longueur d'impulsion est de 1ms à 2ms.

Si la durée d'implusion est inférieur a 1,5ms, il faudra faire une différence entre le
temps médiant et le temps de la longueur d'implusion(deltaT).
Et ainsi en sortie obtenir une impulsion de longeur 1,5ms + deltaT..

J'ai esquissé une solution, j'ai mis place des détecteurs de front montant et descendant de l'impulsion,

Lorsqu'un front montant est détecté; une impulsion est envoyée vers un compteur qui s'active.
Et le front descendant; stoperai le comptage.

Pendant se lapse de temps, le compteur ou un chrono, enregistrerai la valeur...

Mais je ne sais pas comment exprimer le reste du montage...
Un peu d'aide serai bienvenue... Merci pour ceux qui s'atarderaont sur mon problème.

voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
 
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.NUMERIC_STD.ALL;
 
entity test is
 port 	(i_clk : in std_logic; -- horloge
         i_reset  : in std_logic; -- init
         i_e  : in std_logic; -- consigne
         o_efm  : out std_logic; -- flag front montant
		 o_efd  : out std_logic; -- flag front descendant
         o_count : out std_logic_vector(15 downto 0); -- compteur ms pour le front montant
         m_count : out std_logic_vector(15 downto 0) -- compteur ms pour le front descendant
 
 
		);
 end test;
 
architecture com of test is
shared variable efm : std_logic;
shared variable efd : std_logic;
shared variable count_d : std_logic_vector(15 downto 0); --front descendant
shared variable count_m : std_logic_vector(15 downto 0); --front montant
 
 
begin
 
------------------------------------------------------------------------------------
 
-- Timer synchronisé sur front montant de e
cntm_ms:process(i_clk, i_e, i_reset)
begin
	if (i_reset='1') then count_m:= "0000000000000000" ;
	elsif (i_clk'event and i_clk='1') then
		if (efm='0') then count_m:=count_m+1;
		else count_m:="0000000000000000";
		end if;
    end if;
	o_count <= count_m;
end process cntm_ms;
 
------------------------------------------------------------------------------------
 
 --Process de détection de front montant sur e
det_fm:process(i_clk, i_e, i_reset)
constant SIZE_O_EFM : integer:=1; -- largeur impulsion o_efm
variable cnt : integer range SIZE_O_EFM+1 downto 0:=0;
begin
	if (i_reset='1') then efm:= '0' ; cnt:=0;
	elsif (i_clk'event and i_clk='1') then
	  	if (i_e='0') then efm:='0'; cnt:=0;
		elsif (i_e='1' and cnt<SIZE_O_EFM) then efm:='1'; cnt:=cnt+1;
		else efm:='0';
		end if;
    end if;
	o_efm <= efm;
end process det_fm;
 
-------------------------------------------------------------------------------------
 
---- Timer synchronisé sur front descendant de e
cntd_ms:process(i_clk, i_e, i_reset)
begin
	if (i_reset='1') then count_d := "0000000000000000" ;
	elsif (i_clk'event and i_clk='1') then
		if (efd='0') then count_d:="0000000000000000" ;
		else count_d:=count_d+1;
		end if;
    end if;
	m_count  <= count_d;
end process cntd_ms;
 
--------------------------------------------------------------------------------------
--Process de détection de front descendant sur e
det_fd:process(i_clk, i_e, i_reset)
constant SIZE_O_EFD : integer:=1; -- largeur impulsion o_efd
variable cnt : integer range SIZE_O_EFD+1 downto 0:=0;
begin
	if (i_reset='1') then efd:= '0' ; cnt:=0;
	elsif (i_clk'event and i_clk='1') then
		if (i_e='1') then efd:='0'; cnt:=0;
		elsif (i_e='0' and cnt<SIZE_O_EFD) then efd:='1'; cnt:=cnt+1;
		else efd:='0';
		end if;
    end if;
	o_efd <= efd;
end process det_fd;
 
end com;