IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VHDL Discussion :

Correcteur PID VHDL


Sujet :

VHDL

  1. #1
    Membre actif Avatar de cedd70
    Homme Profil pro
    Ingénieur R&D
    Inscrit en
    Mars 2012
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2012
    Messages : 154
    Points : 263
    Points
    263
    Par défaut Correcteur PID VHDL
    Bonjour,

    Ci-joint le code VHDL d'un correcteur PID en VHDL.
    Il est plus ou moins fonctionnelle, je suis ouvert à tout critique afin de l'améliorer.



    Code VHDL : 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
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
     
    --######################################
    --#	Correcteur PID	V.2.0					     #
    --######################################
    library ieee;
    	use ieee.std_logic_1164.all;
    	use ieee.numeric_std.all;
    	use IEEE.std_logic_signed.all;
     
    entity PID is
     
    	generic
    	(
    		Kp 			: integer range 0 to 32767:=1;
    		Ki 			: integer range 0 to 32767:=1;
    		Kd			: integer range 0 to 32767:=1
    	);
    	port 
    	(
    		horloge_50Mhz,
    		reset			: in std_logic;
    		erreur	   		: in std_logic_vector(31 downto 0 );	-- consigne - erreure => comprise entre -32768 to 32767
    		consigne_fin		: out std_logic:='0';			-- si consigne atteinte passe à 1
    		commande_position 	: out std_logic_vector(31 downto 0 )	-- consigne position comprise entre -32768 to 32767
    	);
     
    end entity;
     
    architecture arch_PID of PID is
    	constant	precision		: integer :=4;
     
    	constant	ecretage_seuille	: integer := 500;		--7000 commande max possible ( sécuritée)
    	constant	valeur_saturation	: integer := 500; 		--6999 si commande max atteinte => valeur max de commande
     
     
    	signal   	commande		: integer range -2147483647 to 2147483647:=0;
    	signal		commande_distance	: integer range -2147483647 to 2147483647:=0;
    	signal 	ecart				: integer range -2147483647 to 2147483647:=0;
    	signal 	Sclk_temp_2		        : std_logic:='1';
     
    	signal 	cpt 			        : integer range -2147483647 to 2147483647:=0;
    	signal 	cpt_int 		        : integer range -2147483647 to 2147483647:=0;
    	signal 	ecart_precedent 	        : integer range -2147483647 to 2147483647:=0;
     
    	begin
     
    	calcul : process(Sclk_temp_2,reset)
    		begin
    			if rising_edge(Sclk_temp_2) then
    				if reset = '0' then
    					commande <= 0;
    				else
    					commande	<= (( (ecart * Kp) + (cpt_int * Ki)+ ((ecart - ecart_precedent) * Kd) ))/4;	--loi de commande PID
    				end if;
    			end if;
    	end process;
     
    	integrateur :	process(Sclk_temp_2)
    		begin
    			if rising_edge(Sclk_temp_2) then
    				if(ecart < precision and ecart > - precision) then
    					cpt <= 0;
    				else
    					--cpt	<=  cpt + ecart;
    					cpt_int	<=  cpt_int + ecart;
    				end if;
    			end if;
    	end process;
     
    	derivateur : process(Sclk_temp_2)
    		begin
    			if rising_edge(Sclk_temp_2) then
    				ecart_precedent <= ecart;
    			end if;
    	end process;
     
    --	limiteur_int : process(cpt)
    --		variable cpt_temp : integer;
    --		begin
    --			cpt_temp := cpt;
    --		
    --			if cpt > 500 then
    --				cpt_temp := 500;
    --			end if;
    --			if cpt < -500 then
    --				cpt_temp := -500;
    --			end if;
    --			cpt_int <= cpt_temp;
    --		end process;
     
     
     
    	commande_1 : process(Sclk_temp_2)
    		variable	tempo	: integer range 0 to 30000000:=0;
    		begin
    		if rising_edge(Sclk_temp_2) then
    				---- Consigne atteinte ----
    			if ecart < precision and ecart > - precision then 
    				if tempo > 20000000 then
    					commande_distance 	<= 0;
    					consigne_fin			<= '1';
    				else
    					tempo	:= tempo + 1 ;
    				end if;
    			--	Ecretage +	----
    			elsif (commande)	> ecretage_seuille  then
    				commande_distance		<= valeur_saturation;
    				consigne_fin			<= '0';
    				tempo						:= 0 ;
    			--	Ecretage -	----
    			elsif (commande) < -ecretage_seuille then
    				commande_distance		<=- valeur_saturation;
    				consigne_fin			<= '0';
    				tempo						:= 0 ;			
    			--	Regulation	 ----
    			else
    				commande_distance		<= commande ;
    				consigne_fin			<= '0';
    				tempo						:= 0 ;
    			end if;	
    		end if;	
    	end process;
     
     
    	horloge_2 : process(horloge_50Mhz)	-- compteur pour l'integrateur et le derivateur
    		variable cpt_2 : natural range 0 to 400000; --30
    		begin
    		if rising_edge(horloge_50Mhz) then
    			cpt_2 := cpt_2 +1;
    			if (cpt_2=0)then
    				Sclk_temp_2<=not(Sclk_temp_2);
    			end if;
    		end if;
    	end process horloge_2;
     
    	ecart				<= 	to_integer(signed(erreur));
    	commande_position		<=  	std_logic_vector(to_signed(commande_distance ,commande_position'length));
    end arch_PID;

  2. #2
    Nouveau membre du Club
    Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Avril 2008
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués

    Informations forums :
    Inscription : Avril 2008
    Messages : 28
    Points : 32
    Points
    32
    Par défaut salut
    Salut

    T'as essayé de placer router?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    commande	<= (( (ecart * Kp) + (cpt_int * Ki)+ ((ecart - ecart_precedent) * Kd) ))/4;	--loi de commande PID
    A 50MHz, je dirais qu'il va avoir du mal à boucler cette opération

  3. #3
    Membre actif Avatar de cedd70
    Homme Profil pro
    Ingénieur R&D
    Inscrit en
    Mars 2012
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2012
    Messages : 154
    Points : 263
    Points
    263
    Par défaut
    Ca marche et il compile,


    Mon correcteur est implémenté dans une grosse structure d'asservissement pour contrôler la trajectoire de deux roues ( doubles asservissements en trajectoires et vitesses ) , mais j'ai des choses bizarre qui apparaisse parfois. Pour ça que je pose monde code si il peut être amélioré.

  4. #4
    Membre expérimenté

    Homme Profil pro
    Collégien
    Inscrit en
    Juillet 2010
    Messages
    545
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Afghanistan

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Juillet 2010
    Messages : 545
    Points : 1 431
    Points
    1 431
    Par défaut
    Bonjour,

    Ça marche c'est bien!!!bravo!!

    Maintenant cela ne respecte pas tout à fait les règles de l'art...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    horloge_2 : process(horloge_50Mhz)    -- compteur pour l'integrateur et le derivateur
            variable cpt_2 : natural range 0 to 400000; --30
            begin
            if rising_edge(horloge_50Mhz) then
                cpt_2 := cpt_2 +1;
                if (cpt_2=0)then
                    Sclk_temp_2<=not(Sclk_temp_2);
                end if;
            end if;
        end process horloge_2
    commande_1 : process(Sclk_temp_2)
    Tu génère une signal de donnée (même pas carré) que tu utilise comme horloge...
    A ne pas faire en générale.Tu as de la chance que ça marche, tu dois être bas en fréquence non?

    Pour diviser une horloge il faut utiliser des primitives du FPGA: PLL,MCMM, BUFR (Xilinx)
    sinon
    Oriente ton code (des if bien placés) pour que l'outil synthétise des Clock Enale.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    commande	<= (( (ecart * Kp) + (cpt_int * Ki)+ ((ecart - ecart_precedent) * Kd) ))/4;	--loi de commande PID
    Comme l'a fait remarqué sgievounet ca doit être chaud au placement routage...encore une fois tu dois vraiment être bas en fréquence.
    Il faut "pipeliner" le code.

    Ensuite ecart,cpt_int sont sur 32 bits Kp,Ki,Kd sont sur 16 bits, je ne connais pas de FPGA avec des multiplieurs 32*16...,les plus gros font 18*25...

    @+

  5. #5
    Membre actif Avatar de cedd70
    Homme Profil pro
    Ingénieur R&D
    Inscrit en
    Mars 2012
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2012
    Messages : 154
    Points : 263
    Points
    263
    Par défaut
    Merci de cette réponse constructive, je vais améliorer mon code en prenant en compte c'est remarques.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 01/07/2003, 15h47
  2. recuperation PID
    Par phoulosof dans le forum POSIX
    Réponses: 2
    Dernier message: 26/08/2002, 13h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo