From 25e4be86876f738bf5ceae5764a1d0fe42272aef Mon Sep 17 00:00:00 2001 From: Martin Prudek Date: Sun, 10 May 2015 21:59:24 +0200 Subject: [PATCH] Moved monitor printoutand added better init for rpi_state. --- pmsm-control/test_sw/cmd_proc.c | 49 +++++++++++++++++++++++ pmsm-control/test_sw/cmd_proc.h | 5 +++ pmsm-control/test_sw/main_pmsm.c | 65 +++++++------------------------ pmsm-control/test_sw/pmsm_state.h | 4 +- 4 files changed, 72 insertions(+), 51 deletions(-) diff --git a/pmsm-control/test_sw/cmd_proc.c b/pmsm-control/test_sw/cmd_proc.c index 72260b5..936ec7b 100644 --- a/pmsm-control/test_sw/cmd_proc.c +++ b/pmsm-control/test_sw/cmd_proc.c @@ -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"); +} diff --git a/pmsm-control/test_sw/cmd_proc.h b/pmsm-control/test_sw/cmd_proc.h index 52d6627..6a5b113 100644 --- a/pmsm-control/test_sw/cmd_proc.h +++ b/pmsm-control/test_sw/cmd_proc.h @@ -1,3 +1,8 @@ #include "pmsm_state.h" +#include "rp_spi.h" void poll_cmd(struct rpi_state* state); +/* + * tiskne potrebna data + */ +void printData(struct rpi_state* state); diff --git a/pmsm-control/test_sw/main_pmsm.c b/pmsm-control/test_sw/main_pmsm.c index 20e6417..50e32e1 100644 --- a/pmsm-control/test_sw/main_pmsm.c +++ b/pmsm-control/test_sw/main_pmsm.c @@ -41,7 +41,19 @@ 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. @@ -89,54 +101,7 @@ float diff_p(float value){ 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: @@ -202,7 +167,7 @@ void prepare_tx(uint8_t * tx){ */ void * pos_monitor(void* param){ while(1){ - printData(); + printData(&rps); usleep(1000000); /*1 Hz*/ } return (void*)0; diff --git a/pmsm-control/test_sw/pmsm_state.h b/pmsm-control/test_sw/pmsm_state.h index 5f63acf..7c631f1 100644 --- a/pmsm-control/test_sw/pmsm_state.h +++ b/pmsm-control/test_sw/pmsm_state.h @@ -4,8 +4,10 @@ #include #include +struct rpi_in; struct rpi_state{ + struct rpi_in* spi_dat; 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 */ -}rps; +}; #endif /*PMSM_STATE*/ -- 2.39.2