UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor ituumitcelik
Visitor
6,560 Views
Registered: ‎02-05-2011

PID controller

 

Hello,
I am trying to write a PID controller with a state machine. It is working but I think it is not working properly. 
I think there are  signed unsigned number or type conversion problem. Please, could you fixed it for me?
Is there any problem? When I tried the following algorithm in microblaze in C language, the PID module working properly. 
With best regeards,
entity PIDModule is
    Port ( ADC_DATA : in  STD_LOGIC_VECTOR (15 downto 0); --16 bit unsigned PID input
           DAC_DATA : out  STD_LOGIC_VECTOR (15 downto 0); --16 bit unsigned PID output 
           CLK1 : in STD_LOGIC;
 );
end PIDModule;
architecture Behavioral of PIDModule is
    type statetypes is (Reset,
                              CalculateNewError,
                              CalculatePID,
                              DivideKg,
                              Write2DAC,                              
                              SOverload,
                              ConvDac
                              );                              
    
    signal state,next_state : statetypes := Reset;     
    signal Kp : integer := 10;
    signal Kd : integer :=20;
    signal Ki : integer :=1;
    signal Kg : integer := 256;
    signal Output : integer := 1;
    
    signal SetVal : integer := 33259; 
    signal sAdc : integer := 0 ;
    signal Error: integer := 0;
    signal p,i,d : integer := 0;
    signal DacDataCarrier : std_logic_vector (15 downto 0);
    signal AdcDataCarrier : std_logic_vector (15 downto 0);
    
begin
PROCESS 
      variable Output_Old : integer := 0;   
      variable Error_Old : integer := 0;
     BEGIN  
          IF CLK1'EVENT AND CLK1='1' THEN  
 state <= next_state;
          END IF;
         case state is
                 when Reset =>
                        sAdc <= conv_integer(ADC_DATA);  --Get the input for PID
                        next_state <= CalculateNewError;
                        Error_Old := Error;  --Capture old error
                        Output_Old := Output;    --Capture old PID output
                    when CalculateNewError =>  --
                       next_state <= CalculatePID;
                       Error <= (SetVal-sAdc); --Calculate Error
                    
                    when CalculatePID =>
                        next_state <= DivideKg;
                        p <= Kp*(Error);              --Calculate PID 
                        i <= Ki*(Error+Error_Old);
                        d <= Kd *(Error-Error_Old);                     
                    when DivideKg =>
                        next_state <= SOverload;
                        Output <=  Output_Old+(p+i+d)/2048; --Calculate new output 
                       
                    when SOverload =>
                        next_state <=ConvDac;
                        if Output > 65535 then
                            Output <= 65535 ;
                        end if;     
                        if Output < 1 then 
                            Output <= 1;
                        end if;
                        
                    when ConvDac =>         
  --Send the output to port
                        DacDataCarrier <= conv_std_logic_vector(Output ,16);
                        next_state <=Write2DAC;
                        
                    when Write2DAC =>
                        next_state <= Reset;
                        DAC_DATA <= DacDataCarrier;
                end case;
            END IF;
                        
      END PROCESS;
end Behavioral;

 

0 Kudos
5 Replies
Newbie akschauhan
Newbie
6,274 Views
Registered: ‎06-29-2011

Re: PID controller

hello

i m working on pid controller implementation with microblaze.plz send me the code in c .

0 Kudos
Newbie joseoliva
Newbie
6,198 Views
Registered: ‎08-06-2011

Re: PID controller

did you fix your problem?

I'm stuck in something similar, but on verilog code.

tnx

0 Kudos
Highlighted
Newbie techie1
Newbie
5,888 Views
Registered: ‎04-09-2012

Re: PID controller

1. Syntax error: last port in entity declaration must have no ";"

Here's how it should look:

 

entity PIDModule is
   Port ( ADC_DATA : in  STD_LOGIC_VECTOR (15 downto 0); --16 bit unsigned PID input

             DAC_DATA : out  STD_LOGIC_VECTOR (15 downto 0); --16 bit unsigned PID output
             CLK1 : in STD_LOGIC
 );

 

 

2. Extra "END IF;" (with no corresponding "IF") found before "END PROCESS;"

 

After making these changes, how is the new behavior?

 

Tags (1)
0 Kudos
Contributor
Contributor
5,873 Views
Registered: ‎01-13-2012

Re:needed help in PID controller

hello

iam needed to implementation pid controller in microblaze ,how can  do ?and needed the idea

thank you....................

Tags (2)
0 Kudos
Contributor
Contributor
5,797 Views
Registered: ‎01-13-2012

Re: PID controller

hello

 

iam needed to implementation pid controller in microblaze  in sparatan 3e,how can  do ?and needed the idea

,send code in c

thank you....................

0 Kudos