-
Notifications
You must be signed in to change notification settings - Fork 131
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
Possibly two off-by-one errors in motor controller? #109
Comments
Forgot a quick note: |
For the first point maybe you are right. As there is an offset I found experimentally, I guess it solves that shift by 1 unit: // This value should be near 0. For 2, you are probably right and I do some errors on calculations :-) I suggest you do a pull request. Thank you. |
Thanks for the response :) |
@Frans-Willem I'd love to use your fix also! |
@geeksville All motor related stuff I've done so far is in this branch: So far I've converted the hard-coded SVPWM table to one generated by a python script, fixed the off-by-ones described in this issue, and bumped the PWM up to 9 bits. I've checked the assembly output, and believe the generated code will be faster than the 18.0 implementation, but I have not yet been able to verify this with a scope. Note however that I have not had the time to re-check MOTOR_ROTOR_ANGLE_OFFSET as described by @casainho, and I won't be able to until early September. |
Really nice that piece of code for 9 bits PWM!! I am always learning, so good opportunities. |
I've been studying the motor controller code, and I found two instances where the code is off-by-one from what I would have expected. This could mean that either I'm misunderstanding something, or there are indeed off-by-one errors in there.
The first one is in the svm_table. I've written code to generate that I believe should have been in the table, and I noticed that the current values are offset by one index, as can be seen from the following graph:
The code used to generate the table & plot the results can be found here.
("Calculated" is the output of the python code, "Current" is what's currently in motor.c. Not related to electrical current ;))
Again, it's also possible the error is in my python code, and I'm open to feedback on the way I try to generate this table.
I suspect an error was made where the table was generated using indices ranging from 1 to 256, instead of 0 to 255 (as the code is using it).
The second one is in motor.c on line 610: The comments state it's rotating by 90 degrees (in the 360-degree total rotation world), which should coincide with 64 'binary'-degrees (in the 256 total rotation world), but instead 63 is subtracted.
I suspect that there might've been an error in calculating this value, where 255 was used instead of 256. e.g. (90/360)*255=63.75, rounded down to 63, instead of t(90/360)*256=64...
Would someone be able to verify these findings ?
The text was updated successfully, but these errors were encountered: