Teensy 3.2 TSI Interrupt

Status
Not open for further replies.
Greetings everyone,
for quite some time now I found myself at an impasse regarding the TSI module of the MK20DX256 (aka Teensy 3.2). I try to implement a simple continous capacitance measurement by utilizing the end-of-scan interrupt of the TSI module. However I can not seem to convince the MCU to execute the interrupt correctly. I also had a view into the NXP MCUXpresso SDK and could not find any special tricks that I might have missed. Therefore I turn to the community in hopes of enlightenment. I attach a minimal code example that in my opinion should be sufficient, since most parameters of the TSI module are fine in their default setting or just tune the measurement itself and not the functionality. I will be grateful for any possible insights.
Best regards,
Chrono.

Code:
void tsi0_isr()
{
  # toggle the led
  GPIOC_PTOR |= (1 << 5);
  # reset the end-of-scan flag
  TSI0_GENCS |= TSI_GENCS_EOSF;
}

void setup() 
{
  # configure the led as output
  PORTC_PCR5 |= PORT_PCR_MUX(1);
  GPIOC_PDDR |= (1 << 5);
  # enable the tsi clock and the interrupt
  SIM_SCGC5 |= SIM_SCGC5_TSI;
  NVIC_ENABLE_IRQ(IRQ_TSI);
  # reset the tsi module
  TSI0_GENCS = 0;
  # enable tsi_in 9 (pin 0 on the teensy board) as touch electrode 
  TSI0_PEN = (1 << 9);
  # enable the general tsi interrupt, the eond-of-scan interrupt and configure for periodic measurement
  TSI0_GENCS |= TSI_GENCS_TSIIE | TSI_GENCS_ESOR | TSI_GENCS_STM;
  # enable the module
  TSI0_GENCS |= TSI_GENCS_TSIEN;
}

void loop()
{
}
 
A frustrating puzzle.

The following code works. It doesn't use the periodic measurement mode, but it accomplishes the same effect in the same number of instructions.

-- rec --

Code:
void tsi0_isr()
{
  # toggle the led
  GPIOC_PTOR |= (1 << 5);
  # reset the end-of-scan flag, trigger next scan
  TSI0_GENCS |= TSI_GENCS_EOSF | TSI_GENCS_SWTS;
}
TSI_GENCS_STM
void setup() 
{
  # configure the led as output
  PORTC_PCR5 |= PORT_PCR_MUX(1);
  GPIOC_PDDR |= (1 << 5);
  # enable the tsi clock and the interrupt
  SIM_SCGC5 |= SIM_SCGC5_TSI;
  NVIC_ENABLE_IRQ(IRQ_TSI);
  # reset the tsi module
  TSI0_GENCS = 0;
  # enable tsi_in 9 (pin 0 on the teensy board) as touch electrode 
  TSI0_PEN = (1 << 9);
  # enable the general tsi interrupt, and the end-of-scan interrupt
  TSI0_GENCS |= TSI_GENCS_TSIIE | TSI_GENCS_ESOR;
  # enable the module, trigger scan
  TSI0_GENCS |= TSI_GENCS_TSIEN | TSI_GENCS_SWTS;
}

void loop()
{
}
 
I will have to test it, but I am inclined to believe that it works. If it does, that is really interesting. It implies that something is not as it should be in the interrupt logic. The reason I actually wanted to use the interrupt is because I am afraid of starting scans too early or reading data at the wrong time. The errata for the mk20dx128 implies that there are a few timing issues in this module. If the interrupt does not reset properly it makes me however wonder if your solution is not just bruteforcing a "reset" of the scan and the internal logic might still be in an illdefined state.

Still thank you a lot for the interesting solution!
Greets,
Chrono.
 
Status
Not open for further replies.
Back
Top