Teensy 4.1 Interrupt Register

NoExpert

New member
I want realize a non blocking routine to sample an analog signal at a quit high frequency. For that I just want read the flag in the interrupt register by a specific intervall using a timer interrupt.
My problem is, that following the steps at the pjrc website regarding interrupts leading me to an error.

https://www.pjrc.com/teensy/interrupts.html

Following the simplest version of a piece of code which should compile. I use th Arduino IDE with Teensyduino.

#include <avr/io.h>
#include <avr/interrupt.h>

void setup() {
EIMSK |= (1<<5);
EIFR |= (1<<5);
}

void loop(){
//pass
}

Error -> EIMSK was not declared in this scope.

Same for the EIFR.

I checked also the libraries and it seems like that the descriped registeres are only present for the older libraries teensy 3.x.
Does anyone have an idea how to realize the given approach? I dont want a hardware interrupt which runs the ISR at every bounce. I want a defined samplerate as already explained.

Thank in advance!
 
Code:
#include <avr/io.h>
#include <avr/interrupt.h>

void setup() {
EIMSK |= (1<<5);
EIFR |= (1<<5);
}

void loop(){
//pass
}
I believe the code above is for the 8 bit Teensy's.
 
Thanks for you reply. But how to reach the interrupt register of the 4.1 Teensy? I cant found any documentation about that.
 
Sorry, you may need to explain more about what you are doing or wanting to do.

For example you are sampling Analog. Are you using the analog capabilities of the Teensy to do this, or are you using some external ADC chip that is communicating with the Teensy?

If you are using the two built in Analog to Digital converters, you may want to look at the ADC library.
There is a thread on it: https://forum.pjrc.com/threads/25532-ADC-library-update-now-with-support-for-Teensy-3-1
It is included with Teensyduino. Also can get latest at: https://github.com/pedvide/adc

If external, than how is it hooked up?
 
Thanks, I think I got the things a little mixed up. Actually there are two thing I want to do.

1. Reading an encoder attached to two digital pins.
2. Reading a analog piezo sensor attached to a analog input pin.
3. ...may other analog sensors will follow

Problem, I want to sample next to the encoder signal the analog signal at 5kHz to 10kHz. Till now I faced the problem with arduino boards that the encoder, which also may bounce, triggers constantly the ISR attached to a hardware interrupt. This prevented me of acurately sample the analog signal at a precice samplerate. This is why I want realize a non blocking approach as descripted by implementing the sampling via interrupt timers (software interrupts) and thus only reading the interrupt flag. Thus my program is not interrupted as soon as an encoder signal is present. Instead I just read the flag and see if an edge has been applied or not. This allows me to realize a fixed sample rate.
 
You might try to use some built-in hardware support...

For Encoder: not sure if it is a quadrature encoder? if So you might want to look at:
https://github.com/mjs513/Teensy-4.x-Quad-Encoder-Library

For Analog reading, I would switch to ADC library: Several different options on how to go there.
You can setup to start an ADC conversion, and then test later if it is done and get the results...

You can also setup to DMA reads and use a hardware timer to trigger when the conversions happen.
There is an example ADC->adc_timer_dma that does this. There are others that just use DMA, and others that just use timer...
 
Back
Top