stancecoke said:
OK, I think I have to learn how the I/O Pins of the Mosfets are set/reset, to unterstand why the timing with interrupts is that critical....
The timings are critical to put the voltage on the motor phase wires:
- with the correct wave shape ("Sinewave" or Space Vector Modulation (SVM))
- with correct synchronization with hall sensors signals (here the important the is phase B current wave form synchronized with hall sensors, for doing FOC. But phase B current timing = f( voltage motor phase B timming) ).
The wave form values are stored on the ui8_svm_table [SVM_TABLE_LEN] wich is a 256 bytes array (sinewave or SVM wave defined on BLDC_SPWM_Lookup_tables.ods file). This values need to be put as duty_cycle of PWM. And they need to be scaled based on the throttle value (as on current firmware, not considering things like future speed or torque control to be developed), like if throttle value will be from 1% to 100% and will multiply to each ui8_svm_table[] value.
Then are the timings, that need to be calculated in a way that duty_cyle is updated on correct time, and no more than every 64us.
Every 64us PWM cycle, next new value of duty_cycle of PWM must be calculated to apply on the next cycle. If this calculation don't happens between each cycle and at some random time, the synchronization of phase B current with hall sensors signals will be lost and motor will work without the most efficiency possible (loss of energy, controller getting hotter) and motor making noise.
What you need to learn about the timings are the PWM schemes and about FOC:
- https://opensourceebikefirmware.bitbucket.io/Motor_control--PWM_schemes--So,_Which_PWM_Technique_is_Best_(Part_1).html
- https://endless-sphere.com/forums/viewtopic.php?f=30&t=87870&p=1297642&hilit=shane+colton#p1297642
- https://eggelectricunicycle.bitbucket.io/FOC--Shane_Colton_documentation_and_firmware.html
But try to just have an overview and let that part of PWM and FOC with me. If you prefer you can focus on the PAS and torque sensors.
After having the motor working with simplified FOC, next things that need to be done:
- phase B max current control (I did this before on the EGG electric unicycle)
- over current protection (I did this before on the EGG electric unicycle)
- speed control loop AND phase B max current control; for throttle control: https://opensourceebikefirmware.bitbucket.io/Motor_control--Throttle_Control_Modes.html (new to me)
- UART / LCD (I did this before)
- bluetooh hardware module (I did this before on the EGG electric unicycle)
- Android app for bluetooth control (I did this before on the EGG electric unicycle)
- regen (kind of new to me)
- generic motor controller for Arduino, accepting control commands by UART
- etc etc
