Open-loop intetgrator drift has been fixed using a low pass filter with w_cutoff=200. Electromagnetic torque and flux-linkage reference can be now calculated.
Print functions and variables have been adapted to debug the DTC algorithm.
First attempt to move the motor with no PID controller and just the DTC code. The motor does rotate but vibration and noise is present.
The DTC inverter block was disabled, now the PID controller is generating again the signals for debugging the flux-linkage and torque estimators functions.
Flux linkage angle is not  taken from the actual measures but from the hall sensor angle instead. This is inteanded to find out wheter or not the calculated psi_angle is numerically wrong. PID is still driving the motor.
Torque direction fixed. It was positive when it had to be negative because both differntial amplifiers had the inputs inverted. Now the torque is negative whe the motor spins clock-wise as it should. Up to now the DTC code has been used to estimate data, such as the flux-linkage, when the motor is spinning with the PID controller just to debug.
This src is intended to continue the DTC debbuging. The src_test_DTC was used for testing the DTC estimations with the PID controller.
DTC_timer_init function sets the pwm in edge_aligned instead of center_aligned. This allows to duplicate the speed and have an actual value of the voltage every cycle.
DTC output voltage vector were disabled for testing the open loop starting.
DTC somehow working (high current values ~10A). Motor starting is done by an open loop sinusoidal wave and still the hall sensor for corroborating the speed value.
Saving before modifying the code for limiting the current by software.
DTC is working, but it is not stable yet. Having a PID based on Hallsensor speed, with a Kp of 0.01, and hysteresis bands of 0.05% for the flux and 0.8 for the torque, a constant speed of 219.18 is obtained. The torque bounces from positive to negative values, and the flux linkage is controlled quite good.
Limitation for maximum current has been added. When any phases surpases 15 A the motor is suddenly stopped by setting the duty cycles to 0. Also, the startup function has been disabled in order to let the DTC to start the machine.
Debugging DTC. When DTC  torque reference is inverted the torque still bounces between positive and negative. Apart from that, It has been enabled a print option that prints most of the important variables (currents, voltages, flux-linkages, torques, frequencies and so on).
Flux-linkage of the permanent magnet was miscalculated. It still neede to be divided by PI. Now the values are psi_F=0.0016 for the Motordrive, and 0.0014 for the ntmprovedrive. Also, the hysteresys bands must be relative to 100%, but some of them were related to 1 instead. Now all of them are in the 100% scale.
Simple DTC cannot be used because it requires at least 40kHz just to operate properly. Otherwise the torque value gets unstable, oscillating between positive and negative values. The solution for such a problem is to complement DTC with SVM (space vector modulation) for generating the correct space voltage vector required for driving the motor. Thus, src_full_DTC will be left as it is and a new src_DTC-SVM will be created instead.
New src has been created for the DTC-SVM code.
Prototype functions and functions for the SVM libraries have been created. They have not been checked yet.
SVM functions have been check and corrected. Duty cycles are now properly selected. Next step will be rotating the motor with DTC and SVM together.
Connecting SVM to DTC.