how to set the signal in DAC range.?

19 Feb 2013

good morning

if any function contain more than two and three variable and resultant floating value is maybe large,(but unknown) if i want to shown it on the dac than what should i do ? i just want convert it into the dac range 0- 3.3 volts.

19 Feb 2013

The DAC output will always be between 0 and 3.3V To get linear behaviour in that range, the value you give to analogout must be between 0.0 and 1.0. That is the responsability of your program. I take it you are still working on PID control. When your control is in a steady state, the output should be somewhere in this range. When a large error occurs your float may go outside that range. This is not a problem, the dac will drive the actuator to the limit and with time the error will decrease. Meanwhile however the integrator will have integrated the large error and may contain an unrealistically high correction value (known as integrator wind-up). So your program will also have to limit the values of the integrator (to something in the order of the nominal output range). Then, with proper settings of your control parameters, and a closed loop, the system finds an equilibrium and all values will be in-range. Note that you have to take into account all parameters in the loop (including the sensors and actuators). Also note that it is not guaranteed that you will always find a stable solution for your PID control, it all depends on the process you want to control.

20 Feb 2013

you are absolutely Right Ad van ..

i am still working on the integration and pid controller. actually i am using some quantity which actually get me from ending of third integration loop then i feedback in the first equation ,this way i processed my signal. As you told i am facing the problem of overflow again same as i faced in the integration.

my system is closed loop but for testing pupose i split into small part and then i run individually that's reason of this problem ? what do you think?

My complete algorithm is contain many variables, interlinked function, two or three integrator and one pi ...so it's become little complex handle this all in properly it is become difficult for me.

i am really not understand what should i do to control this problem, because every time i have facing same problem.

20 Feb 2013

one another question arise here ,

is there any function or library in mbed that can give me 16 bit of msb. ??

OR any function that can be stored me convert 32 bit data into the 12 bit data by proper averaging or through any other method ???

ok other way let me check

is there any other way through the pwm register ??

if set pwm register and connect the lowpass filter at the ending of that and then we take out put of the particular variable.

20 Feb 2013

Why don't you publish your design on your notebook page, along with your code. It would make it easier to help you.

21 Feb 2013

#include "mbed.h"
#include"math.h"
AnalogIn I(p17);
AnalogIn I1(p19); 
//PwmOut H1(p21);
//DigitalOut L1(p22);
//DigitalOut H2(p23);
//DigitalOut L2(p24);
//DigitalOut H3(p25);
//DigitalOut L3(p26);
DigitalOut r(LED1); 
AnalogOut aout(p18);


main()
{
int i;
float Ia,Ib,Ic,Ibeta,Wr;
static float psi_dr_e[100], psi_dr_s[100],psi_qr_s[100],psi_qs_s[100],psi_ds_s[100],psi_r[100];
static float Te[100],psi_qs_sf,psi_ds_sf;
//static float Tref[200],Iqs_ref[200],Ids_ref[200],Ia_ref[200],Ib_ref[200],Ic_ref[200],er_a[200],er_b[200],er_c[200];
float  sum_psi_ds_s=0,sum_psi_qs_s=0,sum_Te=0;
while(1)
{
     Ia=(I-0.5);
     Ib=(I1-0.5);
     //Ic[i]=-Ia[i]-Ib[i];
     Ibeta = (0.5774*Ia)+(2*0.5774*Ib);
          
          sum_psi_ds_s -= psi_ds_s[i];
          psi_ds_s[i]=(((Ia*11.36)+(Wr*psi_ds_sf)) - (psi_qs_sf*15.15));
          sum_psi_ds_s += psi_ds_s[i];
          psi_ds_sf=sum_psi_ds_s;
          
          sum_psi_qs_s -=psi_qs_s[i];
          psi_qs_s[i]=((Ibeta*11.36) - ((Wr*psi_qs_sf) + (15.15 * psi_ds_sf)));
          sum_psi_qs_s += psi_qs_s[i];
          psi_qs_sf=sum_psi_qs_s;
           
          sum_Te -=Te[i];
          Te[i]= 3*(psi_ds_sf*Ia - psi_qs_sf*Ibeta);
          sum_Te +=Te[i];
          Wr= sum_Te;
         
          Er=Wref-0.5*Wr;//gain=0.5// error genration
          Er_kp=10*Er;
          Er_ki=10*Er;
     
         y=y+ 0.0001 * Er_ki; // error tuning
     
       if( y>=10)y=10;//saturation limit
          
          
     Tref=Er_kp+y;
     if(Tref>=100)Tref=100;
     
     Iqs_ref=Tref/(psi_r+0.001);
     Ids_ref=1.33;
     
     //**********refrances current genration*************************
     
    // Ia_ref=1.33*cos(theta)+Iqs_ref*sin(theta);
         
    // Ib_ref= Ids_ref *(sin(theta)*1.732 - cos(theta))+ Iqs_ref *(sin(theta)+1.732*cos(theta));
     
    // Ic_ref= -Ia_ref-Ib_ref;
     
     //**********************eror***********************************
     
     er_a=Ia_ref-Ia;
     er_b=Ib_ref-Ib;
     er_c=Ic_ref-Ic;
     
     //*************pulse genration **********************************
     
     if(er_a[i]>=0.1)
     {L1=0;wait_us(10);H1=1;x=1;s=0;}
     else if(er_a[i]<=-0.1)
     {H1=0;wait_us(10);L1=1;x=0;s=1;}
     else if(er_a[i]<-0.1 && er_a[i]>0.1)
     {H1=x;L1=s;}
     
     if(er_b[i]>=0.1)
     {L2=0; wait_us(5);H2=1; v=1;w=0;}
     else if(er_b[i]<=-0.1)
     {H2=0;wait_us(10);L2=1;v=0;w=1;}
     else if(er_b[i]<-0.1&& er_b[i]>0.1)
     {H2=v;L2=w;}
     
     if(er_c>=0.1)
     {L3=0;wait_us(10);H3=1;u=1;z=0;}
     else if(er_c<=-0.1)
     {H3=0;wait_us(10);L3=1;u=0;z=1;}
     else if(er_c<-0.1&& er_c>0.1)
     {H3=u;L3=z;}
 
 
        aout=sum_psi_ds_s/10000; 
          i++;
          if (i>=100) i = 0;r=1; 
         
          
         }
 }        
 }         

as shown in above this program i tried to run and i want to show the integrate signal sum_psi_ds_s,psi_qs_s,Te at dac but in that condition DAC become out of control.

i have tried to show signal on dac with dividing the respective function with some large value, but it was not working . if we divided that function, which we want see on dac then it value become in range of the dac but in this case also overflow is continue..

21 Feb 2013

Please make it a habit to initialise automatic variables, i and Wr are not initialised upon first use. It is very difficult for me to tell why your program is not working, mainly because I don't know what it is supposed to do. Maybe you can submit a few lines and a few formulas to explain what it is that you are trying to compute. It appears that sum_psi_ds_s is the running sum over a window of 100 values of (((Ia*11.36)+(Wr*psi_ds_sf)) - (psi_qs_sf*15.15)) in which Ia is derived from an input value and the other variables are non constant values. I have no way of knowing if this is really what you want to compute. Also there is no way of knowing if this program, which you apparently run as open-loop, would be perfectly ok when running closed-loop. If you want adequate help you must really tell us more on the whole system and the math behind it.

21 Feb 2013

Ad van der Weiden wrote:

Please make it a habit to initialise automatic variables, i and Wr are not initialised upon first use. It is very difficult for me to tell why your program is not working, mainly because I don't know what it is supposed to do. Maybe you can submit a few lines and a few formulas to explain what it is that you are trying to compute. It appears that sum_psi_ds_s is the running sum over a window of 100 values of (((Ia*11.36)+(Wr*psi_ds_sf)) - (psi_qs_sf*15.15)) in which Ia is derived from an input value and the other variables are non constant values. I have no way of knowing if this is really what you want to compute. Also there is no way of knowing if this program, which you apparently run as open-loop, would be perfectly ok when running closed-loop. If you want adequate help you must really tell us more on the whole system and the math behind it.

i am trying on the below program . i have also edited above text and tried to add below onces which actually i tryed to get out psi_ds_sf but some how i didnot upload this below one that 's why i include here...

#include "mbed.h"
#include"math.h"
AnalogIn I(p17);
AnalogIn I1(p19); 
//PwmOut H1(p21);
//DigitalOut L1(p22);
//DigitalOut H2(p23);
//DigitalOut L2(p24);
//DigitalOut H3(p25);
//DigitalOut L3(p26);
DigitalOut r(LED1); 
AnalogOut aout(p18);


main()
{
int i;
float Ia,Ib,Ic,Ibeta,Wr;
static float psi_dr_e[100], psi_dr_s[100],psi_qr_s[100],psi_qs_s[100],psi_ds_s[100],psi_r[100];
static float Te[100],psi_qs_sf,psi_ds_sf;
//static float Tref[200],Iqs_ref[200],Ids_ref[200],Ia_ref[200],Ib_ref[200],Ic_ref[200],er_a[200],er_b[200],er_c[200];
float  sum_psi_ds_s=0,sum_psi_qs_s=0,sum_Te=0,y=0,z=0,v=0;
while(1)
{
     Ia=4096*(I-0.5);
     Ib=4096*(I1-0.5);
     //Ic[i]=-Ia[i]-Ib[i];
     Ibeta = (0.5774*Ia)+(2*0.5774*Ib);
          
          sum_psi_ds_s -= psi_ds_s[i];
          psi_ds_s[i]=((((Ia*11.36)+(100*psi_ds_sf)) - (psi_qs_sf*15.15)));   //wr=100;assume
          sum_psi_ds_s += psi_ds_s[i];  
          psi_ds_sf=sum_psi_ds_s;
          y=psi_ds_sf;
          sum_psi_qs_s -=psi_qs_s[i];
          psi_qs_s[i]=((Ibeta*11.36) - ((100*psi_qs_sf) + (15.15 * psi_ds_sf)));
          sum_psi_qs_s += psi_qs_s[i];
          psi_qs_sf=sum_psi_qs_s;
           
          if(i==100)i=0;
          
          
          //if(>=100000)psi_ds_sf=0;
          aout= (psi_qs_sf+0.5);         
          
         }
         }

ok fine

i explain you

i am sensing two current I and I1 from pin 17and 19.

then i got the Ibeta that is current of the perpendicular axis of the I or Ia (nothing but Ia= I-0.5),Ibeta is resultant of Ia and Ib(=I1-0.5) on the perpendicular axis of the Ia,

now psi_ds_s[i] is flux of star of Induction motor now it's value get through other last equation in this program and it direct axis component of flux. we resolve every quantity into the direct and quadrature axis component ourr aim to contrl each individually without affecting other component.

psi_ds_s[i]= integration of (((Ia*11.36)+(Wr*psi_ds_sf)) - (psi_qs_sf*15.15));

here wr is speed of rotor which we get from the further equation;;it is in radian/sec. with use of integration formula i integrate it.as you can show in program.

same for

psi_qs_s[i]=integration of((Ibeta*11.36) - ((Wr*psi_qs_sf) + (15.15 * psi_ds_sf)));

here, other are constant 11.36,15.15 etc.

Te[i]= 3*(psi_ds_sf*Ia - psi_qs_sf*Ibeta);

it is equation of torque.

and Wr = integration of the Te[i];

which i used in the my first equation.

now i choose one reffarances speed suppose it 140 rad/sec it compare with Error W= Wref.-Wr.

then i get error which is i paased through one transfer function of y=y+ 0.0001 * Er_ki; error tunin

from that i get references torque Teref with use of i get the Ids component of current .

Iqs_ref=Tref/(psi_r+0.001);

Ids_ref=1.33; Ids_ref is always constant value.

HERE I NEED THETA FOR CALCULATING THE iDS_REF AND IQS_REF FOR THAT SOME EQUATION REQURIED WHICH I DO;NT SHOW AND NOT ALSO USED IN PROGRAM(COMMENTED PART) .

FURTHER ALL PART S I DIDN'T RUN STILL WHICH GIVE ME THE PULSE ON PWM PIN TO SWITCH THE INVERTER TO DRIVE MOTOR.

AND MY INVERTER IS SWITCHED THAT WAY SO,THAT MY ERROR BECOME MINIMUM IN EVERY CONDITION.

MY TASK TO DRIVE THE MOTOR AT THE REFERENCES SPEED. THIS ALORIDHAM PERFACTLY RAN IN MATLAB SIMULATION.

21 Feb 2013

So your problem is converting matlab to C. I don't know matlab and I have very little time but if you post your matlab code I can try to see where it goes wrong. What I understand from your code is: you have 2 integrators (summators) psi_ds_sf and psi_qs_sf, each has 3 inputs. psi_ds_sf depends on Ia, Wr and itself (positive) and on the second integrator (negative); psi_qs_sf depends on Ibeta, Wr and itself (negative) and on the first integrator (positive). Your first loop does not seem stable because of the positive feedback from itself, whether this can be compensated by the negative feedback from the second integrator I don't know. Try for yourself manually with e.g. Ia=0, Ibeta=1, you will see that it quickly spirals out of control. For instance with Wr>1, you will never get a stable response. I think your problem is in the conversion of units.

21 Feb 2013

no no ad van

i am not converting the mtlab code to the mbed code

i have simulate the same logic with use of matlab model file. i formed model of this Alagoridham .

whatever you understand is almost correct but i did not understand what u exactly want to say its reason is that in intergration or summation we add one instant of signal then remove the older one in this case stability is automatically maintained.

i think if the value remove from the sum variable at starting is not exactly remove from that why 's sum is increased & increased and goes out the range,

other reason as you told to insability, as per theory i have use this equation for psi_ds_s or psi_qs_s . so how can make it regulated? is ther any other way do you see?