In my code the DMA interrupt seems to be triggering all the time even though I had it on a rising edge input capture (which is only triggered once, confirmed by measuring with a scope.
Some of the relevant codes are:
The same number keeps getting printed even though it should only occur once. Do I have to use dma.clearComplete() or something similar?
Thanks.
Some of the relevant codes are:
Code:
#include <DMAchannel.h>
FASTRUN void INT_ISR() {
// check timer overflow
if ((FTM1_SC & FTM_SC_TOF) != 0) { //read the timer overflow flag (TOF in FTM1_SC)
FTM1_SC &= ~FTM_SC_TOF; //if set, clear overflow flag
ftmCounterOVF++; //increment overflow counter
}
if ((FTM1_C1SC & FTM_CSC_CHF) != 0) { //look for CH1 event flag
FTM1_C1SC &= ~FTM_CSC_CHF; //clear CH1 event flag
}
timerOvfBuffer= ftmCounterOVF;
timerCounterBuffer = ftmCounterVal;
Serial.print(timerOvfBuffer);
Serial.print(" ");
Serial.println(timerCounterBuffer);
}
void setup() {
// configure FTM1
FTM1_MODE = 0x05; //set write-protect disable (WPDIS) bit to modify other registers
FTM1_SC = 0x00; //set status/control to zero = disable all internal clock sources
FTM1_MOD = 0xFFFF; // overflow when maximum value reached
FTM1_C1SC = 0x45; // CHF=0, CHIE=1 (has to be enabled for DMA), MSB=0, MSA=0, ELSB=0 ELSA=1 (input capture - rising edge), 0, DMA=1
// configure pins
PORTB_PCR0 |= 0x600; //MUX = alternative function 6 on PTB0 (FTM1_QD_PHA)
PORTA_PCR13 |= 0x700; //MUX = alternative function 7 on PTA13 (FTM1_QD_PHB)
PORTB_PCR1 |= 0x300; //MUX = alternative function 3 on PTB1 (FTM1_CH1)
// set to quadrature mode
FTM1_QDCTRL = 0x0F; // count up on rising edge when PHB is high, see pg. 1186
// reset counter values
ftmCounterOVF = 0;
FTM1_CNT = 0x0000; //reset count to zero
// configure DMA channel to move timer value
dma.source(*(uint32_t*)&(FTM1_C1V));
dma.destination(*(uint16_t*)&(ftmCounterVal));
dma.transferSize(2);
dma.transferCount(1);
dma.interruptAtCompletion();
dma.attachInterrupt(INT_ISR);
dma.triggerAtHardwareEvent(DMAMUX_SOURCE_FTM1_CH1);
dma.enable();
}
The same number keeps getting printed even though it should only occur once. Do I have to use dma.clearComplete() or something similar?
Thanks.