This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BLDC_sensorless code problem in DRV8312-C2-KIT

I hvae run the bldc_sensorless for the seven levels follow by the DRV8312-C2-KIT,and everything is ok,but when I what to get to know the detail how it works,I found some difficults in the code。

first of all:

1.we use the “pu” to let speed,pid control in  -1~1.and we can formulate the pu in to r/min by:

     v.Speed = _IQdiv(v.SpeedScaler,v.EventPeriod);    
     v.SpeedRpm = _IQmpy(v.BaseRpm,v.Speed);      

  But I was confuse by the definition,such as

  speed1.BaseRpm = 120*(BASE_FREQ/POLES);
  speed1.SpeedScaler = (Uint32)(ISR_FREQUENCY/(1*BASE_FREQ*0.001));

  how it comes from?What does it mean?

What I know only  is:

// Define the base quantites            基值   用于设置标幺话的基值用

#define BASE_VOLTAGE    66.32      // Base peak phase voltage (volt), maximum measurable DC Bus/sqrt(3)
#define BASE_CURRENT    5             // Base peak phase current (amp) , maximum measurable peak current
#define BASE_FREQ       200            // Base electrical frequency (Hz)
#define MAX_RPM         3000            // max RMP

// Define the ISR frequency (kHz)
#define ISR_FREQUENCY 40
#define PWM_FREQUENCY 20

 

2.Something about PID:

    pid1_idc.param.Kp = _IQ(3.176*BASE_CURRENT/BASE_VOLTAGE);
    pid1_idc.param.Kr = _IQ(1.0);
    pid1_idc.param.Ki = _IQ(T/0.0005);

   In the code  we just use PI control ,3.176*BASE_CURRENT/BASE_VOLTAGE,what does it means?how can I adjust by my self?Is this have some matter with “pu”?

 

3.please help me to point out where I error:

   the source code in BLDC_sensorless  to let the PID to control PWM is :(1061)

   pwm1.DutyFunc = (int16)_IQtoQ15(pid1_spd.term.Out);   // controlled Speed duty-cycle 

  the code just use the pid.out to control the PWM ,but what I think is:

   pwm1.DutyFunc = pwm1.DutyFunc + (int16)_IQtoQ15(pid1_spd.term.Out);  

 

4.   cmtn1.Va =  _IQ15toIQ((AdcResult.ADCRESULT4<<3)-BemfA_offset);
      cmtn1.Vb =  _IQ15toIQ((AdcResult.ADCRESULT5<<3)-BemfB_offset); 
      cmtn1.Vc =  _IQ15toIQ((AdcResult.ADCRESULT6<<3)-BemfC_offset);

      I know that  AdcResult.ADCRESULTx is the result we want in ADC. It can be 0~0xfff,am I right?but why ADCRESULTx shifts 3 can turn out tobe IQ15?I think it is IQ3....

5.Someting about ADC sample

   As in F2803XILEG_VDC_BLDC.h  discrible, I guess the ADC sample frequency in every channel   is 10K / Channel.

   In my view about round-robin means that all the DAC sample is trigger by SOC0,but once to trigger a channel to sample.Once at a time ,all the channel is trigger on EPWM1A.So SOC0 interrupt have the same fequency with PWM,but every channel's sample fequency is PWM's / Channel ,am I right?

Thanks for help

  • I think over the problem, and know the answer about quenstion 4.

    That the adc have 12 bit ,we want cmtn1.Vx is in 0~1, so we hope the value out of AdcResult.ADCRESULTx  can among in 0~1,The way to do it is make the AdcResult.ADCRESULTx  as IQ12,then shift 3 to make AdcResult.ADCRESULTx  as IQ15,then to calculate.At last to turn it into IQ24.

    So,the error is I misunderstand AdcResult.ADCRESULTx as IQ0.

  • 1. this is slight confusing because we don't just take the standard speed(rpm) = 120 * f / p   (120 for three phase electrical, frequency, poles)

    instead we say BaseRPM = 120 * f / p which essentially sets a maximum speed for our 1pu

    then we find speed by multiplying this by a %.  This % is the calculated event time divided by ( ISR Freq / Base Freq)

     

    2. These are some rule of thumb starting point settings for PI gains. You can and should adjust yourself. They are not in global Q value

    3. The code is correct. The output of the PI controller is the duty cycle value expected by the PWM controller, except it is in global Q and the PWM is expecting Q15.  Why do you think you need to add it to the previous PID output value? Eventually you would just keep increasing it until the PWM unit saturated with 100% (+ overflow)

    4. you figured that one out. Q12 to Q15

    5. the ePWM1A event at timer = 0 is setting the SOCA event. Every channel listed with SOCA is sampled with that frequency, so 20 KHz.  I'm not really sure what your question is asking.

     

  • Hi Chris

    Thanks for your helpbut I want to discuss more detail with you

    For the question oneas we know we set the max r/min is 3000.

    3000 r/min can be change into the expression 50r/s then we put it into electronic round per second.We have 8 pole that is 4 pair pole ,so the electronic round per second is 200 electronic round /sec. So the  max  electronic round /sec is 200. we make base freq is 200,

    when the motor is running, the electronic round per sec is above 200! In the code we  calculate how many implus we get by Isr Interrupt during one electronic round .

    SO ISR Freq / Base Freq means  motor running at 3000r/min 200 times Isr interrupt should be get in one electronic round (every time we get into Isr we +1 for the implus ),we make ISR Freq /Base Freq  as scaler.It is the min implus we get,other speed under 3000r/min should get more implus than 200.

    In code we use  DELAY_30DEG_MACRO(v) in com_trig.h file to calculate how many implus by Isr Interrupt per electronic round need in current speed.The value msut be bigger than 200,so,we use v.Speed = _IQdiv(v.SpeedScaler,v.EventPeriod)  ,(the code is in speed_pr.h), to make the value among 0 to 1.If we want to know the really speed ,that is 3000*v.Speed.Max is 3000m/sec.

    am I right?

    for the question three,I know I was wrong,but show you a picture in CCS:

     I set the speed is Ref=0.3 when the motor is running stably ,the Fbk is also nearly 0.3,but why pid.out is not zero?I know it must not be zero ,it controls pwm.But just for pid block, when the system is stably.pid.out should be zero! Am I right?

    Here is my simulation in Matlab:

     system in and system out,this is not important

    Here is the problem :when the system is stably,pid out is nearly zero

    where is my error?I misunderstand~~~

     

    For the question five:

    As your discrible,you mean the ePWM1A event trigger all the SOCx by write register AdcRegs.ADCSOCxCTL.bit. Every channel listed with SOCA  is begin to sample,but the order is from SOC0 to SOC7?This is my first to deal with 28035, epwm is quite different from 2808’s block. I will read the datasheet more careful.

    Thank you ~~~~

  • When Feedback = Reference that does not mean that PI output = 0

    If the output = you will get 0 PWM duty cycle.

    The output of the PI controller is the value needed to KEEP the Error (Ref-feedback) = 0

    Set your reference = 0, and after steady state when fdbck = 0 check the PI output.

     

    Regarding the ADC, perhaps we are speaking about different things. I answered that the sampling frequency (when you are sampling each channel) is the same. It is. Every channel gets sampled on every CMPx event of every timer UP event, every time the Timer runs (assuming that's how you have it set-up).  But perhaps you are asking about the the sampling time of each channel?  Or the conversion speed?

     

  • HI,

       Thanks for explain so careful, I understand now: the output of PI controller is the value needed to keep the error equal zero.And I found out the error in my simulation by Matlab. 

       YES,I am asking about the sampling time of the event and the sampling time of each channel! Regarding the ADC,I just only concern on sampling frequency in every channel.

        As I know in 2812,I can set the max channel I need to sample and the sequence to sample.when the EVA is trigger,the needed channels is sampled in sequence.

       And I am a little confuse ablut round-robin.

       The code in kit :

     /******* CHANNEL SELECT *******/               \
     /*SOCA7个通道都有用上!*/                           \
                            \
     AdcRegs.ADCSOC0CTL.bit.CHSEL  = 0; /*Dummy meas. avoid 1st sample issue Rev0 Picollo*/ \
     AdcRegs.ADCSOC0CTL.bit.TRIGSEL  = 5;              \
     AdcRegs.ADCSOC0CTL.bit.ACQPS  = 6; /*采样窗口总共有7个时钟周期*/       \
                            \
     AdcRegs.ADCSOC1CTL.bit.CHSEL  = 1;    /* ChSelect: ADC A1-> Phase U Current*/        \
     AdcRegs.ADCSOC1CTL.bit.TRIGSEL  = 5; /* Set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1*/\
     AdcRegs.ADCSOC1CTL.bit.ACQPS  = 6; /* Set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)*/\
                            \
     AdcRegs.ADCSOC2CTL.bit.CHSEL  = 9; /* ChSelect: ADC B1-> Phase V Current*/    \
     AdcRegs.ADCSOC2CTL.bit.TRIGSEL  = 5;              \
     AdcRegs.ADCSOC2CTL.bit.ACQPS  = 6;              \
                            \
     AdcRegs.ADCSOC3CTL.bit.CHSEL  = 10; /* ChSelect: ADC B2-> DC Bus Voltage*/     \
     AdcRegs.ADCSOC3CTL.bit.TRIGSEL  = 5;              \
     AdcRegs.ADCSOC3CTL.bit.ACQPS  = 6;              \
                            \
     AdcRegs.ADCSOC4CTL.bit.CHSEL  = 15; /* ChSelect: ADC B7-> V Phase A */     \
     AdcRegs.ADCSOC4CTL.bit.TRIGSEL  = 5;              \
     AdcRegs.ADCSOC4CTL.bit.ACQPS  = 6;               \
                            \
     AdcRegs.ADCSOC5CTL.bit.CHSEL  = 7; /* ChSelect: ADC A7-> V Phase B */     \
     AdcRegs.ADCSOC5CTL.bit.TRIGSEL  = 5;              \
     AdcRegs.ADCSOC5CTL.bit.ACQPS  = 6;              \
                            \
     AdcRegs.ADCSOC6CTL.bit.CHSEL  = 12; /* ChSelect: ADC B4-> V Phase C */     \
     AdcRegs.ADCSOC6CTL.bit.TRIGSEL  = 5;              \
     AdcRegs.ADCSOC6CTL.bit.ACQPS  = 6;              \
                            \
     AdcRegs.ADCSOC7CTL.bit.CHSEL  = 2;    /* ChSelect: ADC A2-> Low Side DC Bus Return Cur.*/ \
     AdcRegs.ADCSOC7CTL.bit.TRIGSEL  = 5;              \
     AdcRegs.ADCSOC7CTL.bit.ACQPS  = 6;              \

     Does the code means every time the event is trigger,SOC0-SOC7 is sampling in sequence?
     

  • Yes, you'll notice they all have TRIGSEL = 5, and in round robin it's sampling one after the other. We're just taking all of the samples then deciding which ones to use based on the commutation state.