]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blobdiff - pmsm-control/test_sw/cmd_proc.c
Moved monitor printoutand added better init for rpi_state.
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / cmd_proc.c
index 72260b5b9975b5269f4cfd1f85ef65a3fe937936..936ec7b60a43df30288ed05243da0bdaa693795d 100644 (file)
@@ -72,3 +72,52 @@ void poll_cmd(struct rpi_state* state){
        }
        return ;
 }
+
+/*
+ * tiskne potrebna data
+ */
+void printData(struct rpi_state* state){
+       struct rpi_in data_p;
+       struct rpi_state s;     /*state*/
+       float cur0, cur1, cur2;
+       int i;
+       /* copy the data */
+       sem_wait(&state->thd_par_sem);
+       data_p = *state->spi_dat;
+       s=*state;
+       sem_post(&state->thd_par_sem);
+
+       if (data_p.adc_m_count){
+               cur0=data_p.ch0/data_p.adc_m_count;
+               cur1=data_p.ch1/data_p.adc_m_count;
+               cur2=data_p.ch2/data_p.adc_m_count;
+       }
+       for (i = 0; i < 16; i++) {
+                       if (!(i % 6))
+                               puts("");
+                       printf("%.2X ", data_p.debug_rx[i]);
+       }
+       puts("");
+       printf("\npozice=%d\n",(int32_t)data_p.pozice);
+       printf("chtena pozice=%d\n",s.desired_pos);
+       printf("transfer count=%u\n",s.tf_count);
+       printf("raw_pozice=%u\n",data_p.pozice_raw);
+       printf("raw_pozice last12=%u\n",(data_p.pozice_raw&0x0FFF));
+       printf("index position=%u\n",data_p.index_position);
+       printf("hal1=%d, hal2=%d, hal3=%d\n",data_p.hal1,data_p.hal2,data_p.hal3);
+       printf("en1=%d, en2=%d, en3=%d (Last sent)\n",!!(0x40&s.test),!!(0x20&s.test),!!(0x10&s.test));
+       printf("shdn1=%d, shdn2=%d, shdn3=%d (L.s.)\n",!!(0x08&s.test),!!(0x04&s.test),!!(0x02&s.test));
+       printf("PWM1=%u(L.s.)\n",s.pwm1);
+       printf("PWM2=%u(L.s.)\n",s.pwm2);
+       printf("PWM3=%u(L.s.)\n",s.pwm3);
+       printf("distance to index=%u\n",s.index_dist);
+       printf("T_PWM1=%u T_PWM2=%u T_PWM3=%u\n",s.t_pwm1,s.t_pwm2, s.t_pwm3);
+       printf("Pocet namerenych proudu=%u\n",data_p.adc_m_count);
+       printf("(pwm1) (ch1)=%d (avg=%4.0f) (%2.2f%%)\n",data_p.ch1,cur1,diff_p(cur1));
+       printf("(pwm2) (ch2)=%d (avg=%4.0f)(%2.2f%%)\n",data_p.ch2,cur2,diff_p(cur2));
+       printf("(pwm3) (ch0)=%d (avg=%4.0f)(%2.2f%%)\n",data_p.ch0,cur0,diff_p(cur0));
+       printf("soucet prumeru=%5.0f (%2.2f%%)\n",cur0+cur1+cur2,diff_s(cur0+cur1+cur2));
+       printf("duty=%d\n",s.duty);
+       if (s.index_ok) printf("index ok\n");
+       if (s.commutate) printf("commutation in progress\n");
+}