IR/alternate pin musings

Status
Not open for further replies.

jrraines

Well-known member
I have been playing a bit with IR remotes. I have the adafruit2.8"TFT touch breakout already connected to the teensy and an IR receiver on pin 3. The TFT uses port D pins 0-7 for its data bus connection. Pin 5 on the Teensy is D7 and pin 5 is also the one pin used for sending IR in the IR library.

Thinking through how I might proceed with the pin 5 conflict:
I could try just connecting the IR LED to pin 5 as well, figure that what came out would be 'noise' to the controlled device. I suspect that the current draw to run the LED would foul up data going to the TFT--that the TFT would always see a 0 on that line. Haven't tried it.

I could use a transistor between pin 5 and the IR LED. that seems more likely to work, the IR signal and the IR noise would be 'louder'. Maybe less likely to draw so much current into the IR circuit that the TFT stopped working. Might try that.

I could try to change which teensy pin is used to drive the IR led. That would involve more software, more digging into the innards of the teensy code and learning about the MK20DX128 on the teensy. That appeals to me more since my software background is stronger than my almost nonexistent hardware background. So I spent some time looking at what I have, to try to understand what would be involved. In IRremoteInt.h there is
#elif defined(IR_USE_TIMER_CMT)
#define TIMER_RESET ({ \
uint8_t tmp = CMT_MSC; \
CMT_CMD2 = 30; \
})
#define TIMER_ENABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_DSE|PORT_PCR_SRE
#define TIMER_DISABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_DSE|PORT_PCR_SRE
#define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_CMT)
#define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_CMT)
#define TIMER_INTR_NAME cmt_isr
#ifdef ISR
#undef ISR
#endif
#define ISR(f) void f(void)
#if F_BUS == 48000000
#define CMT_PPS_VAL 5
#else
#define CMT_PPS_VAL 2
#endif
#define TIMER_CONFIG_KHZ(val) ({ \
SIM_SCGC4 |= SIM_SCGC4_CMT; \
SIM_SOPT2 |= SIM_SOPT2_PTD7PAD; \
CMT_PPS = CMT_PPS_VAL; \
CMT_CGH1 = 2667 / val; \
CMT_CGL1 = 5333 / val; \
CMT_CMD1 = 0; \
CMT_CMD2 = 30; \
CMT_CMD3 = 0; \
CMT_CMD4 = 0; \
CMT_OC = 0x60; \
CMT_MSC = 0x01; \
})
#define TIMER_CONFIG_NORMAL() ({ \
SIM_SCGC4 |= SIM_SCGC4_CMT; \
CMT_PPS = CMT_PPS_VAL; \
CMT_CGH1 = 1; \
CMT_CGL1 = 1; \
CMT_CMD1 = 0; \
CMT_CMD2 = 30; \
CMT_CMD3 = 0; \
CMT_CMD4 = 19; \
CMT_OC = 0; \
CMT_MSC = 0x03; \
})
#define TIMER_PWM_PIN 5
the last line is just used in the .cpp file twice for a single pinMode and a single digitalWrite for initialization. The other parameters seem to set up the timing and higher current output on the clock that drives pin 5, but none of them seem to choose a primary or alternate pin to attach pin 5/D7 to that CMT output.

My sense looking at diagrams like the color card that comes with the teensy 3 has been that only certain pins can be attached to each function. In this case I might hope to attach a pin not in the D0-7 range to CMT.

I spent some time with "K20 Sub-Family Reference Manual, Rev. 2, Feb 2012". I'm not sure I figured out the best term to search on; crossbar, peripheral bridge and AIPS were about the best I found. In table 3-18 on p 78 I see that CMT is source number 47, which might be useful information. table 4-2 on page 137 shows Port A-E multiplexing control on slots 73-77. I don't see information about how one would use those possible tidbits. My sense is that there may be another datasheet/manual specific to the MK20DX128 that I don't have. I would appreciate any insights or tips.

I did add some samsung IR code stuff to the IR library, seems to receive OK, can't really test without a way to send!
 
Thinking through how I might proceed with the pin 5 conflict:
....
I could use a transistor between pin 5 and the IR LED. that seems more likely to work, the IR signal and the IR noise would be 'louder'. Maybe less likely to draw so much current into the IR circuit that the TFT stopped working. Might try that.

If you're going to use hardware, which is probably the easiest way, a logic gate might be best. Then you could use one of the other unused pins to enable the signal to drive the LED when you want to transmit, and disable the path to the LED when you want to draw on the display.

I could try to change which teensy pin is used to drive the IR led.

This probably isn't feasible. The IRremote library uses the special carrier modulator timer, which only drives that particular pin.

That would involve more software, more digging into the innards of the teensy code and learning about the MK20DX128 on the teensy. That appeals to me more since my software background is stronger than my almost nonexistent hardware background.

You might be able to modify the display code to drive a different pin.

I did add some samsung IR code stuff to the IR library, seems to receive OK, can't really test without a way to send!

I hope you'll post the code, or even submit a pull request to the IRremote github. Ken recently gave me access to maintain that code (he's too busy to maintain it). Soon I plan to merge Teensy 3.0's code and some of the other stuff from pending pull requests.
 
Status
Not open for further replies.
Back
Top