You are here

Adding support for three phase shunts...

4 posts / 0 new
Last post
Roger Wolff
Offline
Last seen: 7 months 3 weeks ago
VESC Original
Joined: 2017-05-24 12:27
Posts: 202
Adding support for three phase shunts...

Hi, My hardware has always had three phase shunts. I'm only now getting to the point where I'm starting to enable that in the firmware. 

Now I have arranged for the ADC vector to hold the extra current sample and defined its index. That's just fine. But when I enable HW_HAS_3_SHUNTS and command the motor to run at 1.5A, the motor jolts  as if it gets a 50 or 100A current spike. Doing a "sample when the motor starts" shows a 50 to 100A current spike. 

I have tried setting the motor to brake and turning the rotor by hand. This shows three nice current  waveforms just like I'd expect. 

The main thing is... looking through the code, it seems as if the second and third phase have been swappped...  Sometimes the voltages are swapped, 

 

#ifdef HW_HAS_3_SHUNTS
                float Va = ADC_VOLTS(ADC_IND_SENS1) * ((VIN_R1 + VIN_R2) / VIN_R2);
                float Vb = ADC_VOLTS(ADC_IND_SENS2) * ((VIN_R1 + VIN_R2) / VIN_R2);
                float Vc = ADC_VOLTS(ADC_IND_SENS3) * ((VIN_R1 + VIN_R2) / VIN_R2);
#else
                float Va = ADC_VOLTS(ADC_IND_SENS1) * ((VIN_R1 + VIN_R2) / VIN_R2);
                float Vb = ADC_VOLTS(ADC_IND_SENS3) * ((VIN_R1 + VIN_R2) / VIN_R2);
                float Vc = ADC_VOLTS(ADC_IND_SENS2) * ((VIN_R1 + VIN_R2) / VIN_R2);
#endif

 

and to my surpise... 

#define TIMER_UPDATE_DUTY(duty1, duty2, duty3) \
                TIM1->CR1 |= TIM_CR1_UDIS; \
                TIM1->CCR1 = duty1; \
                TIM1->CCR2 = duty3; \
                TIM1->CCR3 = duty2; \
                TIM1->CR1 &= ~TIM_CR1_UDIS;
 

(apparently when NOT using three shunts!). 

So... Do I suddenly need to swap definitions for channel 2 and three? Or would the FOC (hall sensor?) detection have to be redone? But why would this cause 50A spikes when current measurements correctly indicate that there is 50A running?

 

Why does adding a third channel swap duty2 and duty3 and the BEMF voltages? Things work just fine like this with a calculated "curr2", so why would things change when there suddenly is an extra current sensor???

EDIT: OK, finally got it to work. Somehow, I suspect, on VESC6 phase 2 and 3 got swapped. I don't understand why the firmware cares..... I have now NOT defined "HAS_3_SHUNTS", but a variant that does nothing except in the code that does the real work. 

Benjamin, can I submit a pull request where mcpwm_foc.c starts out with

#ifdef HAS_3_SHUNTS

#ifndef DONTSWAP

#define SWAP_PHASES

#endif
#endif

 

then instead of swapping depending on "HAS_3_SHUNTS" it will depend on the SWAP_PHASES define. And my hardware config will define "DONTSWAP". 

Or better, but a bit more risky.... Add a "SWAP_PHASES" in hw_60.h (And the others that now define HAS_3_SHUNTS) and migrate a few HAS_3_SHUNTS to the new SWAP_PHASES define. 

 

benjamin
Offline
Last seen: 1 week 5 days ago
VESC OriginalVESC Platinum
Joined: 2016-12-26 15:20
Posts: 486

Actually the phases are not swapped in the VESC6. The thing is that the VESC4 has shunts on phase 1 and 3, so there phase 2 and 3 are swapped to make it look like the shunts are on phase 1 and 2. When HAS_3_SHUNTS is set the phases are un-swapped and in the correct order. It would make sense to have an un-swapped version for two shunts, but I don't want to add that to the code without having hardware to test it on first to avoid untested code that night not work.

Roger Wolff
Offline
Last seen: 7 months 3 weeks ago
VESC Original
Joined: 2017-05-24 12:27
Posts: 202

Well.... You've managed to fully confuse me. I clearly see the phase shunts sitting on phase 1 and 3. I've had tons of trouble getting the analog channels to match where the software expects them. There is no reason whatsoever to want the shunts on phase 1 and 2. 

 

In any case, "automatically" swapping two phases when a certain number of shunts is present is a surprise to someone working on the project. So, the "swap phases" is "YES" for the VESC4 and not for the three-shunt/VESC6 version, Fine. 

georpo
Offline
Last seen: 4 years 10 months ago
Joined: 2018-03-13 14:29
Posts: 1

Hello,

Maybe having 2 shunts but defining 3 has to do with the middle high side mosfet (the column without shunt) shorting all the time?

Finally in vesc 4 should the HW_HAS_3_SHUNTS be defined or not?

Thanks!

Giorgos.