phydoughsbuddy
New member
I recently purchased a Teensy 4.0 and am looking forward to using it in a project I am working on. I had been trying to implement the project on an Arduino, but the 16MHz clock speed created severe limitations. In general, I am attempting to read the pulses from an OMRON E6B2-CWZ6C Rotary Encoder 1024P/R 5-24V and calculate the speed that it is rotating, then use the RPM value for other processes. I am doing the coding on a Windows machine (Windows 10) in an Arduino/Teensyduino(1.48) environment I have already worked out the details of the RPM calculation from my previous work with the Arduino – so, that part is not the issue. The part that I am having problems with is getting the attachInterrupt function to work. The rotary encoder is powered by a 5 volt source, and outputs a 5 volt signal. I am translating that signal to 3.3 volts to be compatible with the Teensy input limitations. I have used an oscilloscope to verify the 5 volt output from the encoder and the 3.3 translated voltage that I am sending to digital pin 2 on the Teensy. I am not receiving any output on pin 4 (motorStep) of the Teensy. It seems like it ought to be fairly straight forward, but nothing I have tried has worked. I have exhausted all the online information that I can find and decided to call out for help. Below is an abbreviated code listing that focuses on the interrupt handling only.
#define encoderA 2 // rotary encoder output A (triggers interrupt) = pin 2
#define encoderB 7 // rotary encoder output B (to determine forward or reverse) = pin 7
#define motorStep 4 // motor step = pin 4
#define motorDirection 5 // motor direction = pin 5
void setup() {
pinMode(encoderA, INPUT_PULLUP);
pinMode(encoderB, INPUT_PULLUP);
pinMode(motorStep, OUTPUT);
pinMode(motorDirection, OUTPUT);
attachInterrupt(digitalPinToInterrupt(encoderA), encoderISR, FALLING); // pin 2
}// end setup
void loop() {
}// end loop
void encoderISR(){
digitalWrite(motorStep, HIGH);
digitalWrite(motorStep, LOW);
}// end encoderISR
#define encoderA 2 // rotary encoder output A (triggers interrupt) = pin 2
#define encoderB 7 // rotary encoder output B (to determine forward or reverse) = pin 7
#define motorStep 4 // motor step = pin 4
#define motorDirection 5 // motor direction = pin 5
void setup() {
pinMode(encoderA, INPUT_PULLUP);
pinMode(encoderB, INPUT_PULLUP);
pinMode(motorStep, OUTPUT);
pinMode(motorDirection, OUTPUT);
attachInterrupt(digitalPinToInterrupt(encoderA), encoderISR, FALLING); // pin 2
}// end setup
void loop() {
}// end loop
void encoderISR(){
digitalWrite(motorStep, HIGH);
digitalWrite(motorStep, LOW);
}// end encoderISR