Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perhaps a small bug + some questions. #127

Open
mstrens opened this issue Jan 11, 2025 · 0 comments
Open

Perhaps a small bug + some questions. #127

mstrens opened this issue Jan 11, 2025 · 0 comments

Comments

@mstrens
Copy link

mstrens commented Jan 11, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant