I'm attempting to come up with an electronic lead screw for my lathe using a Teensy 4.1. So I am working out some of the critical pieces. My code only implements one case at a time, and there is no way to change things, at the moment. A UI will come later. If the basics don't work then an UI won't matter! Anyways, I am using QuadEncoder, TeensyTimerTool and have added in the touch display that PJRC sells, the ILI9341. I am using an Omron E6B2-CWZ6C rotary encoder, and am directly pulsing a cheapo TB67S109AFTG based full bridge driver for a NEMA-11 stepper. When I work out some of my system better, I will upgrade the stepper driver and use a 4Nm NEMA-24 stepper.
If I use serial output to the TeensyMonitor, everything looks really good, no missing counts at encoder speeds that I care about (< 1200 RPM, with a 4096 count/rev rotary encoder). The stepper motor appears to increment correctly and follow the encoder, no matter the encoder shaft speed, nor direction. This pretty much changes using the tft display. The main loop appears to be missing counts, as many as 9 counts. I don't think the HW encoder is actually missing counts (but I can't prove that yet) but it may be that by the time the tft function has returned, the encoder value has changed by N counts. It's easy to correct for a count or two, but it gets increasingly difficult as the apparent skipped counts increases, say to 9 or 10! It is important for the stepper to keep up with the encoder, and to maintain the proper ratio of steps to encoder counts, or the lathe will create faulty threads of varying pitch.
So, I am wondering if there are more efficient, or at least lower blocking time way to write to the display. I don't mind a frame rate of 2-5 Hz, as it isn't critical to me. But I do mind a lot if the display writes are preventing the rest of my code to operate at speed. Is there some sort of frame buffer mode, or line mode that is a fire and forget process? Does the ILI9341_t3n use DMA by default? It's quite likely I am using the library incorrectly, as I am new to the Teensy landscape.
What is the best way to attach the project? It's not that big, but it is four files. Should I just zip the directory and attach? I will try that. Please advise if there is a better recommended way.
View attachment stepper_n_encoder.zip
With tft enabled
Without writes to tft
Developed in Arduino 1.8.19, Teensy Loader 1.56. Ubuntu 20.04.4 LTS. Picture of mess on my desk!
If I use serial output to the TeensyMonitor, everything looks really good, no missing counts at encoder speeds that I care about (< 1200 RPM, with a 4096 count/rev rotary encoder). The stepper motor appears to increment correctly and follow the encoder, no matter the encoder shaft speed, nor direction. This pretty much changes using the tft display. The main loop appears to be missing counts, as many as 9 counts. I don't think the HW encoder is actually missing counts (but I can't prove that yet) but it may be that by the time the tft function has returned, the encoder value has changed by N counts. It's easy to correct for a count or two, but it gets increasingly difficult as the apparent skipped counts increases, say to 9 or 10! It is important for the stepper to keep up with the encoder, and to maintain the proper ratio of steps to encoder counts, or the lathe will create faulty threads of varying pitch.
So, I am wondering if there are more efficient, or at least lower blocking time way to write to the display. I don't mind a frame rate of 2-5 Hz, as it isn't critical to me. But I do mind a lot if the display writes are preventing the rest of my code to operate at speed. Is there some sort of frame buffer mode, or line mode that is a fire and forget process? Does the ILI9341_t3n use DMA by default? It's quite likely I am using the library incorrectly, as I am new to the Teensy landscape.
What is the best way to attach the project? It's not that big, but it is four files. Should I just zip the directory and attach? I will try that. Please advise if there is a better recommended way.
View attachment stepper_n_encoder.zip
With tft enabled
Code:
Touchscreen started
Touchscreen started
5.1 RPM
14.6 RPM
30.0 RPM
41.0 RPM
Fault! bb = 2
Err cnt : 1
43.2 RPM
Fault! bb = 2
Err cnt : 2
42.5 RPM
Fault! bb = 2
Err cnt : 3
49.1 RPM
Fault! bb = 3
Err cnt : 4
68.1 RPM
Fault! bb = 5
Err cnt : 5
153.1 RPM
Fault! bb = 9
Err cnt : 6
147.9 RPM
Fault! bb = 7
Err cnt : 7
118.7 RPM
Fault! bb = 6
Err cnt : 8
91.6 RPM
Fault! bb = 5
Err cnt : 9
79.1 RPM
Fault! bb = 4
Err cnt : 10
76.2 RPM
Fault! bb = 4
Err cnt : 11
79.8 RPM
Fault! bb = 4
Err cnt : 12
82.8 RPM
Fault! bb = 5
Err cnt : 13
99.6 RPM
Fault! bb = 6
Err cnt : 14
104.7 RPM
Fault! bb = 6
Err cnt : 15
98.1 RPM
Fault! bb = 4
Err cnt : 16
79.8 RPM
Fault! bb = 4
Err cnt : 17
63.7 RPM
Fault! bb = 3
Err cnt : 18
64.5 RPM
Fault! bb = 4
Err cnt : 19
80.6 RPM
Fault! bb = 4
Err cnt : 20
93.8 RPM
Fault! bb = 5
Err cnt : 21
103.3 RPM
Fault! bb = 4
Err cnt : 22
40.3 RPM
10.3 RPM
-0.7 RPM
-0.7 RPM
1.5 RPM
0.7 RPM
2.9 RPM
13.9 RPM
21.2 RPM
Fault! bb = 2
Err cnt : 23
35.9 RPM
Fault! bb = 2
Err cnt : 24
34.4 RPM
Fault! bb = 2
Err cnt : 25
53.5 RPM
Fault! bb = 4
Err cnt : 26
75.4 RPM
Fault! bb = 4
Err cnt : 27
101.1 RPM
Fault! bb = 7
Err cnt : 28
133.3 RPM
Fault! bb = 7
Err cnt : 29
106.9 RPM
Fault! bb = 5
Err cnt : 30
93.0 RPM
Fault! bb = 5
Err cnt : 31
93.8 RPM
Fault! bb = 5
Err cnt : 32
84.2 RPM
Fault! bb = 4
Err cnt : 33
Code:
Touchscreen started
Touchscreen started
0.7 RPM
1.5 RPM
8.1 RPM
18.3 RPM
27.1 RPM
29.3 RPM
33.7 RPM
57.1 RPM
126.7 RPM
153.1 RPM
188.2 RPM
210.9 RPM
186.8 RPM
142.8 RPM
158.9 RPM
189.0 RPM
210.9 RPM
122.3 RPM
1.5 RPM
-0.7 RPM
0.7 RPM
2.2 RPM
21.2 RPM
59.3 RPM
45.4 RPM
45.4 RPM
51.3 RPM
76.2 RPM
175.8 RPM
178.7 RPM
129.6 RPM
122.3 RPM
211.7 RPM
276.1 RPM
467.3 RPM
387.5 RPM
0.7 RPM
-0.7 RPM
0.7 RPM
2.2 RPM
26.4 RPM
41.7 RPM
54.9 RPM
74.0 RPM
134.0 RPM
202.9 RPM
282.0 RPM
367.7 RPM
392.6 RPM
54.2 RPM
-0.7 RPM
0.7 RPM
-0.7 RPM
-8.8 RPM
-30.0 RPM
-38.1 RPM
-15.4 RPM
-41.7 RPM
-87.2 RPM
-145.8 RPM
-358.2 RPM
-338.4 RPM
-457.0 RPM
-484.9 RPM
-16.8 RPM
-1.5 RPM
-16.1 RPM
-50.5 RPM
-155.3 RPM
-261.5 RPM
-344.2 RPM
-571.3 RPM
-189.0 RPM
0.7 RPM
0.7 RPM
0.7 RPM
1.5 RPM
16.1 RPM
41.7 RPM
50.5 RPM
68.1 RPM
71.0 RPM
84.2 RPM
186.0 RPM
329.6 RPM
317.1 RPM
231.4 RPM
8.1 RPM
5.9 RPM
36.6 RPM
79.8 RPM
153.8 RPM
372.1 RPM
356.7 RPM
444.6 RPM
143.6 RPM
-6.6 RPM
-30.8 RPM
-47.6 RPM
-54.9 RPM
-138.4 RPM
-280.5 RPM
-415.3 RPM
-618.9 RPM
-263.7 RPM
-5.9 RPM