[BUG]: Micros bugs out below ~370 microseconds #28
Replies: 19 comments
-
Increased bus speed to 10MHz, now it bugs out at lower than ~110 microseconds. |
Beta Was this translation helpful? Give feedback.
-
Hi Stipena, First of all, I noticed in your program that you only work with a series of IF statements. I could imagine that in some cases this leads to unwanted side effects and would advise you to use a combination of IF, ELSE IF and ELSE statements. I assume that you suspect that the command During a read access to the sensor the command What you could try is to use the function I hope that this information helps you a little bit and if you have new insights I would be glad if you pass them on. Best regards |
Beta Was this translation helpful? Give feedback.
-
I have now built a small performance test for the library. For this I didn't use an Aruino Uno but a Teensy 4.1.
However, you have to keep in mind that the Teensy 4.1 is a board with 32-bit ARM Cortex M7 with 600 MHz CPU clock and this chip also has an FPU for floating point operations. The code of the performance test is available in this separate repository. |
Beta Was this translation helpful? Give feedback.
-
Yes, motor turns between 10 and 350 degrees. Yes, going with angleReadRaw made it work faster but not much. However, I changed from Arduino Uno to Micro, reduced the code to read angle at intervals and spin stepper continuously and reduce step interval after it made 12800 steps. It works well up to certain point. If you try to read angle to frequently then it bugs out (stops responding to some step interval changes). Somewhere around 500us reading interval it doesn't work perfectly but kinda ok. But for me it would be nice to read angle at every step. |
Beta Was this translation helpful? Give feedback.
-
I hope that a board with a higher CPU clock frequency will solve your problems! |
Beta Was this translation helpful? Give feedback.
-
Ohh looks like sprintf is not working as expected again... 🙈 I have adjusted the formatting pattern... Now the results should be displayed also with the Arduino Uno / Nano. |
Beta Was this translation helpful? Give feedback.
-
Micro 100 000Hz - 287us, 8 000 000Hz - 35us Can you add Teensy connection to description? I'm afraid to fry something, since there is if I'm correct 3 SPI buses. And Teensy CS pin would go to CSn on AS5047P? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the effort and your results!
Sure, which version of the Teensy Board are you using? The version 3.6 ? |
Beta Was this translation helpful? Give feedback.
-
To connect the AS5047P sensor to Teensy 3.6 board follow this pin mapping:
Please note that the sensor can no longer be operated with 5V, but must be operated with 3.3V, otherwise there is a risk of damaging the Teensy Board! |
Beta Was this translation helpful? Give feedback.
-
Regarding the actual problem it can be summarized that the expected delay when reading measured values is massively dependent on the used SPI frequency. |
Beta Was this translation helpful? Give feedback.
-
Thanks! From Arduino forum, some suggest to try timer/interrupts. So far had no time to learn them as it is a bit hard (I'm not that great at math or programming). |
Beta Was this translation helpful? Give feedback.
-
Made setup on Teensy 3.6 with 28MHz bus speed, issue still persists :/ |
Beta Was this translation helpful? Give feedback.
-
I am still in the process of replacing the Meanwhile I have the feeling that there is another problem in your software besides the delay in reading the readings from the sensor. Or that there is an interference between the other libraries used in your software. |
Beta Was this translation helpful? Give feedback.
-
I give you latest code to have Idea what is happening
With this code stepper should increase speed by 1us, but I literally can hear from stepper that it doesn't do that. Only changes sound every 3rd, 4th or 5th increase. Point at which it changes speed, seems depend on |
Beta Was this translation helpful? Give feedback.
-
I have written the following program. It reads the AS5047P sensor and at the same time generates a pulse sequence to control the stepper motor driver. I have an A4988 chip but unfortunately no suitable stepper motor on which I could test the software. Therefore I looked at the generated signal with a logic analyzer. The attached picture shows the signal for a step interval length of 12 microseconds. |
Beta Was this translation helpful? Give feedback.
-
Had to tweak it to work:
Now it runs back and forth, instead of spinning continuously. |
Beta Was this translation helpful? Give feedback.
-
Can confirm, FastAccelStepper library works fine parallel with AS5047P library. On Arduino Nano achieves speeds of 25000steps/s. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
If state machine method is used with "Micros" to control steps for stepper motor, bug happens when step on and off intervals is set to lower than ~370 microseconds. Changing interval to 350 microseconds, motor suddenly starts spinning ~50-70% faster. If setting interval to 50 microseconds, motor speed is the same as it were set to 350.
To Reproduce
Arduino UNO R3, A4988 stepper driver, Bipolar stepper motor, AS5047P-TS_EK_AB encoder.
Windows 10 x64, Arduino IDE 1.8.12
Expected behavior
Motor should spin full speed. Full speed should be reached at 43 microseconds step interval.
Additional context

In schematics there is LCD Keypad Shield, but it isn't reason of the problem since I tried code without it and had same issue.
Tried to use int instead of float to store angle position, it maybe lowered the threshold from ~370 to ~360 microseconds.
Beta Was this translation helpful? Give feedback.
All reactions