Intellistep icon indicating copy to clipboard operation
Intellistep copied to clipboard

Driver speed

Open IhorNehrutsa opened this issue 4 years ago • 41 comments

BIGTREETECH declared the Product Parameters as:

Maximum speed: 1000RPM (revolutions per minute) 
Subdivision: 2 4 8 16 32

Stepper motor specifications is:

200 full steps per revolution (1.8° per step)

1000RPM is 1000/60 = 16.6666666667RPS (revolutions per second) When 32 Subdivision is used than MAX frequency of input STEP pulses must be: 16.7 * 200 * 32 = 106880 Hz

I has tested frequency of input STEP pulses with original BIGTREETECH firmware. It is near 50kHz.

I try to check MAX frequency of input STEP pulses in dev branch. I use red LED to see duty cycle of motor step Intellistep\src\hardware\timers.cpp:

// Just a simple stepping function. Interrupt functions can't be instance methods
void stepMotor() {
    digitalWriteFast(LED_PIN, HIGH);
    motor.step();
    digitalWriteFast(LED_PIN, LOW);
}

4kHz input STEP pulses:
P10622-141951

red LED
P10622-142019

5kHz input STEP pulses:
P10622-142502

red LED
P10622-142452

There is no more time to process input STEP pulses. We need faster algorithms.

IhorNehrutsa avatar Jun 22 '21 13:06 IhorNehrutsa

@IhorNehrutsa thanks for doing the testing! Unfortunately, I don't have the equipment to do that kind of testing, so it's great to see how everything is working. Do you have any ideas on how we can speed up the stepping routine?

CAP1Sup avatar Jun 22 '21 14:06 CAP1Sup

Did you disable all of the closed loop interrupts and everything? That could be really hurting the performance

CAP1Sup avatar Jun 22 '21 14:06 CAP1Sup

@IhorNehrutsa since you have an oscilloscope, would it be possible for you to test the frequency of the oscillator on the board? I was unable to find a solid value that was actually accurate for the external (HSE), so I was forced to use the internal oscillator (HSI). The thing is, when you use the internal, it forces you to cut the frequency down by half. This leads to longer compute times and slower overall performance. I think that we could get around 2x more performance by just figuring out that value.

Note: the pin you need is the 5th pin on the left of you have the dot in the top left. That is where the HSE input signal enters the STM32

CAP1Sup avatar Jun 23 '21 04:06 CAP1Sup

HSI and PLL allow to set 64MHz SYSCLK. See STM32Cube image

I measured HSE oscillator. It is 8MHz.

IhorNehrutsa avatar Jun 23 '21 14:06 IhorNehrutsa

Did you disable all of the closed loop interrupts and everything? That could be really hurting the performance

Yes, I switch off correctionTimer in timers.cpp

IhorNehrutsa avatar Jun 24 '21 08:06 IhorNehrutsa

@IhorNehrutsa how are we doing on max update rate now? I'm thinking that it should be higher

CAP1Sup avatar Jun 29 '21 20:06 CAP1Sup

I will mesute it tomorrow in office. My time zone is UTC+3.

IhorNehrutsa avatar Jun 29 '21 21:06 IhorNehrutsa

Not as I expected. It's still 30kHz. WIP

IhorNehrutsa avatar Jun 30 '21 07:06 IhorNehrutsa

with merged https://github.com/CAP1Sup/Intellistep/tree/Stepping-Speed-Improvements 47kHz WIP

IhorNehrutsa avatar Jun 30 '21 08:06 IhorNehrutsa

Measured on master branch https://github.com/CAP1Sup/Intellistep/commit/c014991977ff657ef11a74511b7668306258c99c 48.3kHz

https://github.com/CAP1Sup/Intellistep/pull/50 SINE_MAX a power of 2 to fast division to SINE_MAX 49.3kHz

IhorNehrutsa avatar Jul 02 '21 15:07 IhorNehrutsa

Truly a massive performance gain. Thanks so much Ihor. It was a great help! Can I close this now? I think we meet BTT's performance at this point

CAP1Sup avatar Jul 02 '21 15:07 CAP1Sup

1000RPM is 1000/60 = 16.6666666667RPS (revolutions per second) When 32 Subdivision is used than MAX frequency of input STEP pulses must be: 16.7 * 200 * 32 = 106880 Hz 16.7 * 200 * 16 = 53440 Hz 16.7 * 200 * 8 = 26720 Hz

It is too early, 16 and 32 step subdivisions are still unachievable. :(

IhorNehrutsa avatar Jul 02 '21 16:07 IhorNehrutsa

If I do the calculations the other way, the maximum rate is 7.7 rps at 1/32 microstepping. Now, if you consider that a typical printer pulley is about 10 mm to 15mm in diameter, that would lead to a maximum linear speed of 242 mm/s and 363 mm/s respectively. I really don't think that people are going to be exceeding that. Also, I don't think that there's much more performance to be had unfortunately. Maybe some minor gains, but I don't think that we'll double our current rate

CAP1Sup avatar Jul 02 '21 17:07 CAP1Sup

My target project is not a 3D printer. It is a high-speed tracking/positioning system. 1/8 step is too loud and twitchy.

IhorNehrutsa avatar Jul 02 '21 20:07 IhorNehrutsa

How to force the compiler to save preprocessed files? I can't find it. Thanks.

IhorNehrutsa avatar Jul 02 '21 20:07 IhorNehrutsa

My target project is not a 3D printer. It is a high-speed tracking/positioning system. 1/8 step is too loud and twitchy.

Sorry for assuming that you were 3D printing, I just expected that most people would be using this for a printer. It looks like you were able to find out how to save preprocessed files, which is good because I didn't. We'll have to keep on working on the stepping routine to continue to increase the maximum speed.

CAP1Sup avatar Jul 02 '21 22:07 CAP1Sup

To add to this, I'm running 2mm pitch leadscrews. I need fast, much faster than the stock firmware which runs out of steam at 660rpm.

On Fri, Jul 2, 2021, 15:56 Christian Piper @.***> wrote:

My target project is not a 3D printer. It is a high-speed tracking/positioning system. 1/8 step is too loud and twitchy.

Sorry for assuming that you were 3D printing, I just expected that most people would be using this for a printer. It looks like you were able to find out how to save preprocessed files, which is good because I didn't. We'll have to keep on working on the stepping routine to continue to increase the maximum speed.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CAP1Sup/Intellistep/issues/31#issuecomment-873293083, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6S6SQTLABM5LY4A37T74LTVY7Y7ANCNFSM47DVJETA .

xerootg avatar Jul 02 '21 23:07 xerootg

@IhorNehrutsa now I know that STM32CUBEMX says that 72Mhz is the max for the SYSCLK..... but considering that we need more performance and programming optimizations are getting harder.... I did some testing and was able to increase the SYSCLK to 128MHz while keeping the system stable for functions such as Serial and stepping. Could you give the dev branch a quick test for stepping speed? I'm thinking that the stepping rate should increase to around 75-100kHz.

CAP1Sup avatar Jul 05 '21 16:07 CAP1Sup

53.5kHz

IhorNehrutsa avatar Jul 06 '21 05:07 IhorNehrutsa

Darn! Do you have any idea why the speed really didn't increase? Maybe it's the register setting for setting pins? Also, I got PID somewhat working. I really don't like the library and I think that I'm just going to write the math into the PID class itself. That way, we can use floats to save time and will have much more control over the process

CAP1Sup avatar Jul 06 '21 13:07 CAP1Sup

I measure PLLCLK on MCO https://github.com/CAP1Sup/Intellistep/pull/54

When SystemClock_Config_HSE_8M_SYSCLK_128M() is selected PLLCLK is 128MHz

Stepping rate is 93kHz

Maybe I was inaccurate in the measurements in first time. Maybe MCU started in other CLK way in first time.

IhorNehrutsa avatar Jul 06 '21 14:07 IhorNehrutsa

Getting really close to hitting the desired 100 kHz that you wanted. You can definitely run at 1/16th stepping. I'll look at increasing the GPIO clocks to see if we can squeeze more performance out of the processor

CAP1Sup avatar Jul 06 '21 15:07 CAP1Sup

My bad. 53.5kHz It was at dev branch with the SystemClock_Config_HSE_8M_SYSCLK_72M()

IhorNehrutsa avatar Jul 06 '21 15:07 IhorNehrutsa

55-56kHz Speedup to 55kHz with the SystemClock_Config_HSE_8M_SYSCLK_72M() #55

Now I think we need to focus on the core functionality of Intellistep (PID + SimpleFOC SimpleFOCStudio mode), but keep in mind the speed.

IhorNehrutsa avatar Jul 06 '21 16:07 IhorNehrutsa

96kHz With Merge pull request #55 https://github.com/CAP1Sup/Intellistep/commit/e5d39079f335ffcbe2f240c2e3fa608f9cc17ee5

IhorNehrutsa avatar Jul 06 '21 16:07 IhorNehrutsa

Wow, getting really close to the 101 kHz. Close enough for now. I'll work on PID today, hopefully get it working by tonight

CAP1Sup avatar Jul 06 '21 16:07 CAP1Sup

Revert up to 55kHz #73 with the SystemClock_Config_HSE_8M_SYSCLK_72M()

IhorNehrutsa avatar Jul 13 '21 12:07 IhorNehrutsa

Is it slower with the pow() function?

CAP1Sup avatar Jul 13 '21 12:07 CAP1Sup

Yes, I took 2 days to find it.

IhorNehrutsa avatar Jul 13 '21 12:07 IhorNehrutsa

Sorry about that. I thought that the compiler would optimize it. We'll have to be more careful in the future

CAP1Sup avatar Jul 13 '21 13:07 CAP1Sup