Help with hardware interrupts on 3.2

stereodan

Active member
I'm trying to write my own multiplexing code for the Tlc5940 for Teensy while looking at previous attempts by others on Arduino/AVR and need help converting some interrupts to ARM. I think I'm close, but I don't have any experience with interrupts and am a little out of my depth.

The basic gist is that I'm trying to call an intrrupt every time the BLANK pin pulses, to load in data and enable to the next row of LEDs.

I know this calls an interrupt *after* the pulse on an Arduino.

Code:
ISR(TIMER1_OVF_vect)
{
    Tlc5940_interrupt();
}

And this is the equivalent on Teensy:

Code:
void ftm1_isr(void)
{
    uint32_t sc = FTM1_SC;
    if (sc & 0x80) FTM1_SC = sc & 0x7F;
    Tlc5940_interrupt();
}

Now, this is what I'm trying to do: calling an interrupt *during* the pulse, I gather it's the rising edge. This is for on an Arduino:
Code:
ISR(TIMER1_COMPA_vect)
{
	Tlc5940_interrupt();
}

So what is the equivalent of this on a Teensy?

What's happening inside void ftm1_isr: I gather it's checking the overflow flag and then clears it?

I think I have to identify which flag I should care about (FTM1_CnSC maybe?) and then identify what mask I should use, and how to compare and reset it? Am I close?
 
Last edited:
Which Teensy are you using?

I believe all of them work with the Tlc5940 library. Support for Teensy 4.0 & 4.1 was added fairly recently, so make sure you have version 1.57 installed.
 
Hi Paul! Just the man I want to ask. Sorry if I wasn't clear enough, I'm trying to add support for multiplexing; I have the rows connected so they can be enabled individually, and I want to trigger a row change on every XLAT/BLANK clock pulse. A few other people had success with this years ago on Arduino and now I'm trying to replicate their success on Teensy. It seems interrupts are the only way to do this. I'm on Teensy 3.2.
 
Have you tried the easiest, but not necessarily most efficient way, of just connecting a wire from XLAT/BLANK to another pin and then use attachInterrupt() on that pin?
 
Yea, I was investigating attachInterrupt. Seems like it might work, but I would sure like to solve the “right” way to do it. It feels like I’m close! but maybe not.

Can you verify my understanding of those couple lines of code inside the ftm1_isr(void) function? sc & 0x80 is the overflow flag, and sc & 0x7F resets it. So I need to find the bit that represents the rising edge flag and do the same with it? Tell me if I’m barking up the wrong tree.
 
Every time I write code for those timers (and must admit, it's been quite a while) I keep the reference manual open on my screen right next to the code window. With some registers you write a 1 bit, others you write 0 bit... it's different across various chips, so best to just check the docs as you go though the code. That specific register is documented on page 780-781.

I still think you should try to easy way before the best way....
 
Thanks! In regards to that easier method, is there a reason I have to tie it to a separate pin and attach the interrupt to that one, instead of using attachInterrupt on the XLAT or BLANK output pin directly?
 
Back
Top