Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

PI algoritm implementation in atmega 32 control by RS-232 (loopback) virtual model in labview

Hi everyone!

I have a problem as follows.In labview virtual device model created using a mathematical equation.This virtual device model is controlled by atmega with implemented PI controller. In labview I can change settings Kp and Ki. The settings are sent through RS232 to atmega  with PI algoritm implemented.After calculating the error value is transmitted back to labview. The crux of the matter. After add and  setting Ki  project crashing (for example, generates graphs setpoint value = 0). The question is - there is in the code correct  implementation setting Ki due to transfer it to rs232? I wonder how is the reception of the two values from the atmega, or you can send / receive one value after another, whether it should be set to some "flag, break in transmission" before reading the other variable (reveice Kp...stop..wait for Ki.. receive Ki...).

Translate of the names at diagram:

ilosc iteracji (how many iterations)

Wartosc zadana temperatury (setpoint final value temperature of the math model)

Czas probkowania (sampling time)

Sygnal (signal from Atmega PI after the calculation) - generates graphs setpoint value = 0 if I add Ki

atmega code fragment:

//---value received from labview Kp---------------
int Kp;
Kp = (int)USART0_Receive();
USART0_Transmit(Kp);

//---value received from labview Ki---------------
int Ki;
Ki = (int)USART0_Receive();
USART0_Transmit(Ki);i

int setpointvalue = (int)USART0_Receive();// value received from labview

 

 

 

0 Kudos
Message 1 of 4
(4,811 Views)

First, do a diagram cleanup on that VI. It is a mess with the wires going every which direction. Second, I don't understand how your micro will understand which parameter is being sent. There is no synchronization so the values are going to be received randomly. Typically, you would prefix the value with something so that the micro will understand which parameter is being received.

0 Kudos
Message 2 of 4
(4,773 Views)

Thank you for your support!

You are absolutely right about the random receive.

I changed and cleanup diagram and code.

Now if z receive Kp, if w receive Ki but I think my code in c is  not correct

unsigned char SSA;
SSA = USART0_Receive();
if(SSA == 'N'){
while(1)
{
unsigned char SSA1;
SSA1 = USART0_Receive();
if(SSA1 =='z'){

union unia
{
   char bajty[4];
   float liczba;
}
unia1;
//---receive Kp---------------
int Kp;
Kp = (int)USART0_Receive();
USART0_Transmit(Kp);
//---receive setpoint
while(2)
{
unsigned char SSA2;
SSA2 = USART0_Receive();
if(SSA2 =='w'){

union unia
{
   char bajty[4];
   float liczba;
}
unia2;


//---receive Ki---------------
int Ki;
Ki = (int)USART0_Receive();
USART0_Transmit(Ki);
//---receive setpoint

int WartZadana = (int)USART0_Receive();//receive final setpoint of temperature 

 

0 Kudos
Message 3 of 4
(4,767 Views)

Hi,

 

I am afraid I still don't understand how can we help you?

Do you think the error is in C? 

Implementing RS 232 on atmega is a common application and there are lots of examples that you can find by googling it.

 

I would start from one of those examples and than test and debug if you successfuly receive the data sent and than implement the PI controller.

 

Best regards,

IR

 

 

0 Kudos
Message 4 of 4
(4,683 Views)