Hello everyone,

I've been working lately on a simple implementation of the FOC functionality (learning purposes) using a VESC 4.12 and a Hoverboard BLDC motor.

Problem: ADC values read are always positive (uint32_t) while the phase currents (ia, ib) can have both signs. How can I tell which sign a current has? I tried to refer to the VESC open-source firmware and found inside mcpwm_foc.c something like this:

if (tim->CCR1 > tim->CCR2 && tim->CCR1 > tim->CCR3) {

ADC_curr_norm_value[0 + norm_curr_ofs] = -(ADC_curr_norm_value[1 + norm_curr_ofs] + ADC_curr_norm_value[2 + norm_curr_ofs]);

} else if (tim->CCR2 > tim->CCR1 && tim->CCR2 > tim->CCR3) {

ADC_curr_norm_value[1 + norm_curr_ofs] = -(ADC_curr_norm_value[0 + norm_curr_ofs] + ADC_curr_norm_value[2 + norm_curr_ofs]);

} else if (tim->CCR3 > tim->CCR1 && tim->CCR3 > tim->CCR2) {

ADC_curr_norm_value[2 + norm_curr_ofs] = -(ADC_curr_norm_value[0 + norm_curr_ofs] + ADC_curr_norm_value[1 + norm_curr_ofs]);

}

But can't really get it how this is done. Can someone give me a hint here, or at least where I should look to be able to implement this, please?

Thanks in advance!