From: Martin Prudek Date: Sat, 18 Apr 2015 13:30:27 +0000 (+0200) Subject: Added counter-clockwise simple hall comutator. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/fpga/rpi-motor-control.git/commitdiff_plain/d3fd9876cb9ee9c46bdf3a2acf81e11c27ffd54c Added counter-clockwise simple hall comutator. --- diff --git a/pmsm-control/test_sw/main_pmsm.c b/pmsm-control/test_sw/main_pmsm.c index 65c6200..2757542 100644 --- a/pmsm-control/test_sw/main_pmsm.c +++ b/pmsm-control/test_sw/main_pmsm.c @@ -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: