]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/commitdiff
Added counter-clockwise simple hall comutator.
authorMartin Prudek <prudemar@fel.cvut.cz>
Sat, 18 Apr 2015 13:30:27 +0000 (15:30 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Sat, 18 Apr 2015 13:30:27 +0000 (15:30 +0200)
pmsm-control/test_sw/main_pmsm.c

index 65c62007655b88a85efa5dd33e788bd5e1bdff9f..2757542293094b9e9b244e5a123750a8033fbbf4 100644 (file)
@@ -37,7 +37,7 @@ struct rpi_in data;
 uint8_t test;
 uint16_t pwm1, pwm2, pwm3;
 char commutate;
-uint16_t simple_hall_duty;
+int simple_hall_duty;
 
 
 /**
@@ -117,7 +117,7 @@ void printData(struct rpi_in data){
        printf("(pwm2) (ch2)=%d (avg=%4.0f)(%2.2f%%)\n",data.ch2,cur2,diff_p(cur2));
        printf("(pwm3) (ch0)=%d (avg=%4.0f)(%2.2f%%)\n",data.ch0,cur0,diff_p(cur0));
        printf("soucet prumeru=%5.0f (%2.2f%%)\n",cur0+cur1+cur2,diff_s(cur0+cur1+cur2));
-       printf("duty=%u\n",simple_hall_duty);
+       printf("duty=%d\n",simple_hall_duty);
        if (commutate) printf("commutation in progress\n");
 }
 void prepare_tx(uint8_t * tx){
@@ -192,24 +192,43 @@ void * pos_monitor(void* param){
 /*
  * \brief
  * Test function to be placed in controll loop.
- * Clockwise rotation with PWM with 64 out of 2048 duty cycle.
+ * Switches PWM's at point where they produce same force
  */
-inline void simple_hall_commutator(struct rpi_in data){
-       /* pwm3 */
-       if (data.hal2 && !data.hal3){
-               pwm1=0;
-               pwm2=0;
-               pwm3=simple_hall_duty;
-       /* pwm1 */
-       }else if (data.hal1 && !data.hal2){
-               pwm1=simple_hall_duty;
-               pwm2=0;
-               pwm3=0;
-       /* pwm2 */
-       }else if (!data.hal1 && data.hal3){
-               pwm1=0;
-               pwm2=simple_hall_duty;
-               pwm3=0;
+inline void simple_hall_commutator(struct rpi_in data, int duty){
+       if (duty>=0){ /* clockwise - so that position increase */
+               /* pwm3 */
+               if (data.hal2 && !data.hal3){
+                       pwm1=0;
+                       pwm2=0;
+                       pwm3=duty;
+                       /* pwm1 */
+               }else if (data.hal1 && !data.hal2){
+                       pwm1=duty;
+                       pwm2=0;
+                       pwm3=0;
+                       /* pwm2 */
+               }else if (!data.hal1 && data.hal3){
+                       pwm1=0;
+                       pwm2=duty;
+                       pwm3=0;
+               }
+       }else{  /*counter-clockwise - position decrease */
+               /* pwm3 */
+               if (!data.hal2 && data.hal3){
+                       pwm1=0;
+                       pwm2=0;
+                       pwm3=-duty;
+                       /* pwm1 */
+               }else if (!data.hal1 && data.hal2){
+                       pwm1=-duty;
+                       pwm2=0;
+                       pwm3=0;
+                       /* pwm2 */
+               }else if (data.hal1 && !data.hal3){
+                       pwm1=0;
+                       pwm2=-duty;
+                       pwm3=0;
+               }
        }
 }
 /**
@@ -226,7 +245,7 @@ void * read_data(void* param){
                        data = spi_read(tx);
                        substractOffset(&data,&pocatek);
                        if (commutate){
-                               simple_hall_commutator(data);
+                               simple_hall_commutator(data,simple_hall_duty);
                        }
                        usleep(1000);                           /*1kHz*/
                }
@@ -304,8 +323,8 @@ int main(){
                        pwm3&=commutate*0xFFFF;
                        break;
                case 6:
-                       scanf("%u",&tmp);
-                       simple_hall_duty=tmp&0xFFF;
+                       scanf("%d",&tmp);
+                       simple_hall_duty=tmp;
                        break;
 
                default: