Hi.
I am trying to build a motor driver for my school project and I am a bit new and inexperienced about this issue. I have a couple of questions regarding both the control side and the embedded side. If experienced people can give me answers about my problems, I would be grateful! My questions:
-
I have developed a model. Position control with FOC. My PWM carrier frequency is 10khz and the sample time of my model is 10e-5 sec. I have checked the frequency response of all 3 loops. After the check the bode plot, I have seen that my bandwidth according to -3dB is 500Hz for the Current loop, 150 Hz for Speed Loop, and 14 Hz for the position loop. I have developed an LPF for all these bandwidths. With these bandwidths and Low Pass Filters, I have observed pretty good current waveforms, Back EMF waveforms, and also speed and positions. But When I check the other industrial applications, the people said that for example, the current loop control freq is 24khz, speed is 4 Khz and Position is 2Khz for their application. It seems too much for me. What is the problem with that? Am I right about that, I mean the bandwidth which I get from bode plots are representing the control loop frequency of my loops?
-
As I said before, my sample time in the model is 10e-5 sec, ie. 100 kHz. When I put my model into F2837xD MCU, all my loops and models time step must be 10 Khz. Isn’t it?
-
Also I have encountered a few videos about FOC with F2837xD in Matlab and they are looking a bit different from my model. I have designed all my loops and blocks on my own, I mean I didn’t use any block related to F2837xD. After all these steps, I have built my model as C codes and get into F2837xD MCU. But all after this, I have seen a few videos and documents about my application. Some people are using DMC(Digital Motor Control) and FCL(Fast Current Loop) Libraries. I don’t even use them in my application. Are these libraries required for me? I am asking this because I have tried to run my code in F2837xD and the code interrupted instantaneously after a few sec of start and I have gotten many errors related to “division”. As I said, I am running all codes with 10-5 sample time and 10kHz carrier freq in my MCU. After that, I have reduced my sample time and It seems running, at least not interrupting.
As I said, I am a bit new about this application, If you can help me with my questions I would be grateful! Thank you!
Welcome @HuseyinK to simplefoc! This seems quite advanced for a school project. I wish I’d gone to your school!
I don’t have experience of models, but we can help you transition to silicon. PWM of 10khz will be fine although you may hear noise at this frequency. This would be easy to sort out later.
Current sensing is being worked on as we speak but not yet in the library. We are typically using magnetic sensors or encoders to get positional feedback.
From our libraries perspective it sound like you are interested in closed loop angle control i.e. you’d probably set motor.controller = ControlType::angle;
This has a PID (typically just P) outer loop for angle/position and a PID (typically P and I) loop doing velocity. We might also have a low pass filter on the velocity loop to filter out noise.
100K samples a second. What are you sampling? Lets say you were sampling angular position from a magnetic sensor attached to your motor. That sounds way to high - I find sampling nearer 1K better as otherwise you have to work really hard to filter out noise/quantization.
Our main loop needs to run at about 1000+ loops a second to work smoothly. This can be done on a puny Arduino Uno (16Mhz). A more powerful mcu (e.g. esp32 running at 240Mhz) could do 10K+ loops a second. Your TI F2837xD looks pretty powerful - I don’t think anyone has tried running it on one of those before. Common choices are atmega328p (Uno), stm32 (e.g f1 or f4), esp32 or teensy.
So your “division” error, is that you running simplefoc on your F2837xD? What is the rest of your hardware setup like? e.g. 3 phase driver, motor, position sensor?
I wonder whether your use case is ‘slow angular/position control’. Some applications are running motors at 30K+ rpm and when you consider one shaft rotation might have 7 or 14 electrical rotations (due to pole pairs) you can see why you might need those faster frequencies for some applications.
Hey @HuseyinK
Nice project. Yeah going from Matlab to the real world is in many cases complicated experience 
Let me go through the questions:
-
When you’ve found that your bode diagram shows you that the bandwidth of your current control loop is 500Hz, in my opinion this is a bit low ( I would expect it to be a around 1-5 kHz) then you know your more or less time constant of the system. In order cont control it smoothly you will need to go few times faster than that. There is one more thing that is important for industrial applications.
When you do cascade control first current then velocity then position for example then you want each inner loop to be much faster than the outer one. You basically want to be able to consider it instantaneous. That means that when the velocity control loop set the target current or torque in one sample time of the velocity control loop the current control loop will already achieve this value.
This gives you the freedom to design the current/velocity/position control loop separately and tune them without considering the system as a whole.
That is not the case if you use a state space controller.
-
and 3. I have never worked with the F2837xD but 10kHz can be pretty intense for the mcu, that depends of what are you actually calculating in the real time. What we can tell you from our point of view is that for the code to run at such high frequencies you need to do some serious optimization on it. What Matlab generated c code will not do.
I would suggest you to do this in incremental steps.
You can start with pure sinusoidal modulation or just a simple current control. And once when you have it you can go to the motion control.
Good luck!
Antun
Can you build a video about the video process of driving DRV8305