You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I continue trying to implement OSF on TSDZ8 controller.
So, I try to understand OSF code.
I noticed a possible issue in motor.c file and I have a question.
First the possible bug.
There is some assembler code bur also the equivalent c code.
I will refer to the c code because it is easier to follow.
// calculate motor phase current ADC value and update ui8_g_foc_angle if (ui8_g_duty_cycle > 0) { ui8_adc_motor_phase_current = (uint16_t)((uint16_t)((uint16_t)ui8_adc_battery_current_filtered << 8)) / ui8_g_duty_cycle; if (ui8_foc_flag) { ui8_adc_foc_angle_current = (ui8_adc_battery_current_filtered >> 1) + (ui8_adc_motor_phase_current >> 1); ui8_foc_flag = (uint16_t)(ui8_adc_foc_angle_current * ui8_foc_angle_multiplier) / 256; if (ui8_foc_flag > 13) ui8_foc_flag = 13; ui8_foc_angle_accumulated = ui8_foc_angle_accumulated - (ui8_foc_angle_accumulated >> 4) + ui8_foc_flag; ui8_g_foc_angle = ui8_foc_angle_accumulated >> 4; ui8_foc_flag = 0; }
When ui8_g_duty_cycle is small, it could be that (uint16_t)((uint16_t)((uint16_t)ui8_adc_battery_current_filtered << 8)) / ui8_g_duty_cycle exceeds 255.
So ui8_adc_motor_phase_current should be an uint16_t and not an uint_8.
I understand that the risk is low because when ui8_g_duty_cycle is low, the current is also low but at startup, it could be different.
Second : my question.
I understand the principle that the stator phase must get some more advance when the current/power increases.
Still I do not understand the way (ui8_foc_flag) it is just based on ui8_adc_motor_phase_current,
I presume that ui8_adc_battery_current_filtered is the average current on one PWM period (52 usec).
ui8_adc_motor_phase_current is then the max current in one phase during this cycle (when PWM allows the current to from Vcc to grnd).
Why taking then average of those 2 currents to calculate ui8_adc_foc_angle_current?
How is the right value for ui8_foc_angle_multiplier found/calculated?
I continue trying to implement OSF on TSDZ8 controller.
So, I try to understand OSF code.
I noticed a possible issue in motor.c file and I have a question.
First the possible bug.
There is some assembler code bur also the equivalent c code.
I will refer to the c code because it is easier to follow.
// calculate motor phase current ADC value and update ui8_g_foc_angle if (ui8_g_duty_cycle > 0) { ui8_adc_motor_phase_current = (uint16_t)((uint16_t)((uint16_t)ui8_adc_battery_current_filtered << 8)) / ui8_g_duty_cycle; if (ui8_foc_flag) { ui8_adc_foc_angle_current = (ui8_adc_battery_current_filtered >> 1) + (ui8_adc_motor_phase_current >> 1); ui8_foc_flag = (uint16_t)(ui8_adc_foc_angle_current * ui8_foc_angle_multiplier) / 256; if (ui8_foc_flag > 13) ui8_foc_flag = 13; ui8_foc_angle_accumulated = ui8_foc_angle_accumulated - (ui8_foc_angle_accumulated >> 4) + ui8_foc_flag; ui8_g_foc_angle = ui8_foc_angle_accumulated >> 4; ui8_foc_flag = 0; }
When ui8_g_duty_cycle is small, it could be that (uint16_t)((uint16_t)((uint16_t)ui8_adc_battery_current_filtered << 8)) / ui8_g_duty_cycle exceeds 255.
So ui8_adc_motor_phase_current should be an uint16_t and not an uint_8.
I understand that the risk is low because when ui8_g_duty_cycle is low, the current is also low but at startup, it could be different.
Second : my question.
I understand the principle that the stator phase must get some more advance when the current/power increases.
Still I do not understand the way (ui8_foc_flag) it is just based on ui8_adc_motor_phase_current,
I presume that ui8_adc_battery_current_filtered is the average current on one PWM period (52 usec).
ui8_adc_motor_phase_current is then the max current in one phase during this cycle (when PWM allows the current to from Vcc to grnd).
Why taking then average of those 2 currents to calculate ui8_adc_foc_angle_current?
How is the right value for ui8_foc_angle_multiplier found/calculated?
I noticed that this link uses a much more complex code to calculate the g_foc_angle (in motor.c line 1143).
https://github.com/OpenSourceEBike/TSDZ2-Smart-EBike/blob/master/src/motor.c
Thanks in advance for your comments.
The text was updated successfully, but these errors were encountered: