]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/commitdiff
Added computation of of phase voltages for delta motor connection. There are now...
authorMartin Prudek <prudemar@fel.cvut.cz>
Thu, 14 May 2015 19:52:10 +0000 (21:52 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Thu, 14 May 2015 19:52:10 +0000 (21:52 +0200)
pmsm-control/test_sw/main_pmsm.c

index 4c51f5103cdc7a0cdc5e10bda1b9fcca6c434879..7f666621db489e1e7e7812289c701685c4b01718 100644 (file)
@@ -69,6 +69,24 @@ int clk_init()
 inline void clk_disable(){
        termClock(0);
 }
+/*
+ * \brief
+ * Count minimum value of three numbers.
+ * Input values must be in range <-2^28;2^28>.
+ */
+int32_t min(int32_t x, int32_t y, int32_t z){
+        int32_t diff,sign;
+
+        diff=x-y; /*rozdil*/
+        sign=(*((uint32_t*)&diff))>>31; /*znamenko -> detekuje, ze y je vetsi*/
+        x=y+sign*diff; /*ulozime mensi cislo, pokud sign>0, pak diff<0 */
+
+        diff=x-z; /*rozdil*/
+        sign=(*((uint32_t*)&diff))>>31; /*znamenko -> detekuje, ze z je vetsi*/
+        x=z+sign*diff; /*ulozime mensi cislo, pokud sign>0, pak diff<0 */
+
+        return x;
+}
 
 /**
  * \brief Signal handler pro Ctrl+C
@@ -100,6 +118,34 @@ void alphabeta2pwm3(int32_t * pwma, int32_t * pwmb, int32_t *pwmc,int32_t alpha,
        *pwmb=-alpha/2+beta*887/1024;
        *pwmc=-alpha/2-beta*887/1024;
 }
+/*
+ * \brief
+ * Preocita napeti na jednotlivych civkach na napeti,
+ *     ktera budou privedena na svorky motoru.
+ *     Tedy na A(yel)-pwm1, B(red)-pwm2, C(blk)-pwm3
+ */
+void compPhases(int32_t * pwm1, int32_t * pwm2, int32_t *pwm3, int32_t ua , int32_t ub){
+       int32_t u1,u2,u3;
+       int32_t t;
+
+       /*vypocte napeti tak, aby odpovidaly rozdily*/
+       u1=ua+ub;
+       u2=ua;
+       u3=0;
+
+       /*najde zaporne napeti*/
+       t=min(u1,u2,u3);
+
+       /*dorovna zaporna napeti napeti na nulu*/
+       u1-=t;
+       u2-=t;
+       u3-=t;
+
+       *pwm1=u1;
+       *pwm2=u2;
+       *pwm3=u3;
+
+}
 void inv_trans_comm(int duty){
        uint32_t pos;
        int32_t sin, cos;
@@ -121,11 +167,34 @@ void inv_trans_comm(int duty){
        if (pwmc<0) pwmc=0;
 
 
-       rps.pwm1=(uint16_t)pwma;
-       rps.pwm3=(uint16_t)pwmb;
-       rps.pwm2=(uint16_t)pwmc;
+       rps.t_pwm1=(uint16_t)pwma;
+       rps.t_pwm3=(uint16_t)pwmb;
+       rps.t_pwm2=(uint16_t)pwmc;
 }
 
+void inv_trans_comm_2(int duty){
+       uint32_t pos;
+       int32_t sin, cos;
+       int32_t alpha, beta;
+       int32_t pwma,pwmb,pwmc;
+       int32_t pwm1,pwm2,pwm3;
+       pos=rps.index_dist;
+       /*melo by byt urceno co nejpresneji, aby faze 'a' splyvala s osou 'alpha'*/
+       pos+=460;
+       /*use it as cyclic 32-bit logic*/
+       pos*=4294967;
+       pxmc_sincos_fixed_inline(&sin, &cos, pos, 16);
+       dq2alphabeta(&alpha, &beta,0,duty, sin, cos);
+       alpha>>=16;
+       beta>>=16;
+       alphabeta2pwm3(&pwma,&pwmb, &pwmc,alpha,beta);
+
+       compPhases(&pwm1,&pwm2, &pwm3,pwma,pwmb);
+
+       rps.pwm1=(uint16_t)pwm1;
+       rps.pwm2=(uint16_t)pwm2;
+       rps.pwm3=(uint16_t)pwm3;
+}
 void prepare_tx(uint8_t * tx){
 
        /*Data format:
@@ -478,6 +547,7 @@ void * read_data(void* param){
                                /*simple_ind_dist_commutator(rps.duty);*/
                                /*sin_commutator(rps.duty);*/
                                inv_trans_comm(rps.duty);
+                               inv_trans_comm_2(rps.duty);
                        }else if(!rps.index_ok && rps.commutate){
                                simple_hall_commutator(rps.duty);
                        }