]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/commitdiff
Moved monitor printoutand added better init for rpi_state.
authorMartin Prudek <prudemar@fel.cvut.cz>
Sun, 10 May 2015 19:59:24 +0000 (21:59 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Sun, 10 May 2015 19:59:24 +0000 (21:59 +0200)
pmsm-control/test_sw/cmd_proc.c
pmsm-control/test_sw/cmd_proc.h
pmsm-control/test_sw/main_pmsm.c
pmsm-control/test_sw/pmsm_state.h

index 72260b5b9975b5269f4cfd1f85ef65a3fe937936..936ec7b60a43df30288ed05243da0bdaa693795d 100644 (file)
@@ -72,3 +72,52 @@ void poll_cmd(struct rpi_state* state){
        }
        return ;
 }
        }
        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");
+}
index 52d6627113769c943b03536dd4f655c590b5d469..6a5b1136bfaff2eef0c792f61a0fe65f6502a254 100644 (file)
@@ -1,3 +1,8 @@
 #include "pmsm_state.h"
 #include "pmsm_state.h"
+#include "rp_spi.h"
 
 void poll_cmd(struct rpi_state* state);
 
 void poll_cmd(struct rpi_state* state);
+/*
+ * tiskne potrebna data
+ */
+void printData(struct rpi_state* state);
index 20e64177e20c07597f6f9d517d7f0d550c1d00da..50e32e19ce6e4f0e2d418ac99930f3bed7fab087 100644 (file)
 
 
 struct rpi_in data;
 
 
 struct rpi_in data;
-
+struct rpi_state rps={
+       .spi_dat=&data,
+       .thd_par_sem=NULL,
+       .test=0,
+       .pwm1=0,.pwm2=0, .pwm3=0,
+       .pwm1=0, .t_pwm2=0, .t_pwm3=0,
+       .commutate=0,
+       .duty=0,                        /* duty cycle of pwm */
+       .index_dist=0,          /* distance to index position */
+       .index_ok=0,
+       .tf_count=0,            /*number of transfer*/
+       .desired_pos=0          /* desired position */
+};
 
 /**
  * \brief Initilizes GPCLK.
 
 /**
  * \brief Initilizes GPCLK.
@@ -89,54 +101,7 @@ float diff_p(float value){
 float diff_s(float value){
        return ((float)value-PRUM_SOUC)*100/PRUM_SOUC;
 }
 float diff_s(float value){
        return ((float)value-PRUM_SOUC)*100/PRUM_SOUC;
 }
-/*
- * tiskne potrebna data
- */
-void printData(){
-       struct rpi_in data_p;
-       struct rpi_state s;     /*state*/
-       float cur0, cur1, cur2;
-       int i;
-       /* copy the data */
-       sem_wait(&rps.thd_par_sem);
-       data_p = data;
-       s=rps;
-       sem_post(&rps.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");
-}
+
 void prepare_tx(uint8_t * tx){
 
        /*Data format:
 void prepare_tx(uint8_t * tx){
 
        /*Data format:
@@ -202,7 +167,7 @@ void prepare_tx(uint8_t * tx){
  */
 void * pos_monitor(void* param){
        while(1){
  */
 void * pos_monitor(void* param){
        while(1){
-               printData();
+               printData(&rps);
                usleep(1000000);        /*1 Hz*/
        }
        return (void*)0;
                usleep(1000000);        /*1 Hz*/
        }
        return (void*)0;
index 5f63acff8f958a678f4f8e069544edd3c39774ea..7c631f1c22e42d13dc454ec1014b9ccf0b2d2b6c 100644 (file)
@@ -4,8 +4,10 @@
 #include <stdint.h>
 #include <semaphore.h>
 
 #include <stdint.h>
 #include <semaphore.h>
 
+struct rpi_in;
 
 struct rpi_state{
 
 struct rpi_state{
+       struct rpi_in* spi_dat;
        sem_t thd_par_sem;
        uint8_t test;
        uint16_t pwm1, pwm2, pwm3;
        sem_t thd_par_sem;
        uint8_t test;
        uint16_t pwm1, pwm2, pwm3;
@@ -16,6 +18,6 @@ struct rpi_state{
        unsigned char index_ok;
        uint32_t tf_count;              /*number of transfer*/
        int desired_pos;                /* desired position */
        unsigned char index_ok;
        uint32_t tf_count;              /*number of transfer*/
        int desired_pos;                /* desired position */
-}rps;
+};
 
 #endif /*PMSM_STATE*/
 
 #endif /*PMSM_STATE*/