Rennie Johnson
Member
I have recently migrated our film scanner core circuit board from Teensy 3.6 to 4.1 w/native ethernet. We use dual Teensy processors: One for Transport/Encoder/Triggering operations, and one for LED lamp house color balance/Exposure timing and digital camera I/O operations. The board in a standard configuration looks like this:
We have completed our bench testing with great success. The power and accuracy of the T4.1 is unbelievable! But our initial production alpha testing has presented a potentially serious issue. In the transition to T4.1, our encoder input accuracy has dropped down to approximately 14KHz without losing counts. I used my own c-based encoder interrupt routine, and have just replaced it with Stoffregen's assembly language optimized library, which brings my accuracy up to about 16.5 Khz. We need to run film at native 24 frames per second with 2000 quadrature pulses per frame for audio clock triggering at 48KHz. With the T3.6, we were able to achieve this and then some.
After extensive evaulation, I believe I have isolated the problem to the Teensy native ethernet library server object, which appears to be using significantly more processor resources that our prior T3.6 with Wiznet WIZ811MJ and WIZ812MJ (W5100).
To demonstrate the issue independent of my script, I used the Stoffregen Encoder Library 'BASIC' sketch to test with:
Test #1. 'BASIC' Encoder library as written:
With or without the use of ENCODER_USE_INTERRUPTS or ENCODER_OPTIMIZE_INTERRUPTS, I got an impressive 350KHz accuracy, at which time my servo motor stalled on the load it was connected to. So the accuracy is probably far greater than what I was able to measure. I verify the Teensy encoder input accuracy by sending the same encoder A/B channel outputs simultaneously to the Teensy and to my Galil Servo Motion Controller, which has encoder accuracy up to 12MHz. Each output is buffered by separate logic IC's. The motion controller receives 5v TTL, and the teensy channels run through a voltage divider circuit for LVTTL compatibility.
Test #2. Addition of Native Ethernet Server Object:
I added minimal code to initialize an Ethernet server object. With no connection to a socket, the performance is the same as in my full processor script, which is about 16.5Khz accuracy with Paul's Encoder library as written. A simple call to Ethernet.Begin() brings the encoder performance down to this slow rate.
My ethernet bandwidth requirement is quite minimal. It handles basic setting of internal variables, logic states, LCD display, etc. The protocol is text-based, and packets never contain more than 10 characters, send or return.
QUESTION #1: What am I doing wrong?
QUESTION # 2: Is there any way I can modify the ethernet libary to either slow down the engine to allow more resources to the Encoder interrupt routine, or possibly rescind its interrupt priority (Does it even use interrupts?) to a lower level so the Encoder interrupt routines always complete?
SETUP:
Windows 10 Pro For Workstations (Gen 2, March 2021)
*Arduino 1.8.13
*Teensyduino 1.53
Motherboard: Asrock 621A WS w/Intel(R) I210 ethernet port. Locked at 100/100 send and return.
*(Curious Note: If I install current Arduino 1.8.19 and Teensyduino 1.58, my sketch compiles and loads, but the ethernet does not function when running.)
I appreciate any and all help on this problem.
We have completed our bench testing with great success. The power and accuracy of the T4.1 is unbelievable! But our initial production alpha testing has presented a potentially serious issue. In the transition to T4.1, our encoder input accuracy has dropped down to approximately 14KHz without losing counts. I used my own c-based encoder interrupt routine, and have just replaced it with Stoffregen's assembly language optimized library, which brings my accuracy up to about 16.5 Khz. We need to run film at native 24 frames per second with 2000 quadrature pulses per frame for audio clock triggering at 48KHz. With the T3.6, we were able to achieve this and then some.
After extensive evaulation, I believe I have isolated the problem to the Teensy native ethernet library server object, which appears to be using significantly more processor resources that our prior T3.6 with Wiznet WIZ811MJ and WIZ812MJ (W5100).
To demonstrate the issue independent of my script, I used the Stoffregen Encoder Library 'BASIC' sketch to test with:
Test #1. 'BASIC' Encoder library as written:
With or without the use of ENCODER_USE_INTERRUPTS or ENCODER_OPTIMIZE_INTERRUPTS, I got an impressive 350KHz accuracy, at which time my servo motor stalled on the load it was connected to. So the accuracy is probably far greater than what I was able to measure. I verify the Teensy encoder input accuracy by sending the same encoder A/B channel outputs simultaneously to the Teensy and to my Galil Servo Motion Controller, which has encoder accuracy up to 12MHz. Each output is buffered by separate logic IC's. The motion controller receives 5v TTL, and the teensy channels run through a voltage divider circuit for LVTTL compatibility.
Test #2. Addition of Native Ethernet Server Object:
Code:
/* Encoder Library - Basic Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/
#define ENCODER_USE_INTERRUPTS
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
#include <NativeEthernet.h>
// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(4, 3);
EthernetServer* server;
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF};
IPAddress ip(198,0,0,5);
// avoid using pins with LEDs attached
void setup() {
server = new EthernetServer(12345);
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}
long oldPosition = -999;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}
My ethernet bandwidth requirement is quite minimal. It handles basic setting of internal variables, logic states, LCD display, etc. The protocol is text-based, and packets never contain more than 10 characters, send or return.
QUESTION #1: What am I doing wrong?
QUESTION # 2: Is there any way I can modify the ethernet libary to either slow down the engine to allow more resources to the Encoder interrupt routine, or possibly rescind its interrupt priority (Does it even use interrupts?) to a lower level so the Encoder interrupt routines always complete?
SETUP:
Windows 10 Pro For Workstations (Gen 2, March 2021)
*Arduino 1.8.13
*Teensyduino 1.53
Motherboard: Asrock 621A WS w/Intel(R) I210 ethernet port. Locked at 100/100 send and return.
*(Curious Note: If I install current Arduino 1.8.19 and Teensyduino 1.58, my sketch compiles and loads, but the ethernet does not function when running.)
I appreciate any and all help on this problem.