Flextimer on K60, capture rising edge

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flextimer on K60, capture rising edge

3,427 Views
Futte
Contributor II

Hi i am trying to capture rising edge with a flextimer. I wont to calculate the time from one rising edge to the next one. I am trying in this way:

void initFlexTimer()

{

  unsigned int irPort;

  //Port initialisering

  definePort();

  fnDebugMsg("IR\n");

  irPort = _READ_PORT_MASK(C, PORTC_BIT6);

  fnDebugDec(irPort, 0);

  //Enable the Clock to the FTM0 Module

  SIM_SCGC6 |= SIM_SCGC6_FTM0;

  FTM0_SC |= FTM_SC_PS_1; // clock prescaler / 1

  //turn off FTM write protection;

  FTM0_MODE |= FTM_MODE_WPDIS;

  FTM0_MODE |= FTM_MODE_FTMEN;

  FTM0_SC = 0x0;

  FTM0_SC = 0; //Make sure its Off!

  FTM0_CNT = 0; //Reset counter, make sure we are starting at 0

  FTM0_MOD = (FTM_CSC_ELSA | FTM_CSC_ELSB);  //Set the overflow rate

  //FTM0_MOD = IRQ_RISING_EDGE;

  FTM0_SC |= FTM_SC_TOIE; //Enable the interrupt mask.

  FTM0_SC |= FTM_SC_CLKS_SYS; //Select the System Clock

  fnDebugMsg("Timer is running, with value: ");

  //fnDebugDec(FTM0_CNT, 0);

  fnDebugDec(FTM0_MOD, 0);

}

I dosen´t seems to work, i just geth the value 12 the hole time. Someone now whats maybe is wrong ?

27 Replies

1,767 Views
SergeMaslenniko
Contributor II

Hi Futte,

it makes no sense, I guess... because you reset it below

  FTM0_SC |= FTM_SC_PS_1; // clock prescaler / 1

...

  FTM0_SC = 0x0;

-------------------------------------------


Do you switch on Counter Clock Source?

it's written in K60P144M100SF2RM_2.pdf:

The CLKS[1:0] bits in the SC register select one of three possible clock sources for the

FTM counter or disable the FTM counter. After any MCU reset, CLKS[1:0] = 0:0 so no

clock source is selected.

The CLKS[1:0] bits may be read or written at any time. Disabling the FTM counter by

writing 0:0 to the CLKS[1:0] bits does not affect the FTM counter value or other

registers.


0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

That seems to be working.

void FlexTimerCapturingInitial();

    void TaskFreq(uint_32 data)

    {

dev::tProperties *Properties = (dev::tProperties*)data;

unsigned short FtmResult[10];
unsigned short FtmResultIndex = 0;;

memset(FtmResult, 0, sizeof(FtmResult));

FlexTimerCapturingInitial();

FTM_MemMapPtr FtmMmp = FTM0_BASE_PTR;

mcu::registers::ftm::tCSC* Csc0 = (mcu::registers::ftm::tCSC*)&FtmMmp->CONTROLS[0].CnSC;
//mcu::registers::ftm::tCSC* Csc1 = (mcu::registers::ftm::tCSC*)&FtmMmp->CONTROLS[1].CnSC;

mcu::registers::ftm::tCNT* Cnt = (mcu::registers::ftm::tCNT*)&FtmMmp->CNT;

mcu::registers::ftm::tCV* Cv0 = (mcu::registers::ftm::tCV*)&FtmMmp->CONTROLS[0].CnV;
//mcu::registers::ftm::tCV* Cv1 = (mcu::registers::ftm::tCV*)&FtmMmp->CONTROLS[1].CnV;

memset(FtmResult, 0, sizeof(FtmResult));

for (;;)
{
Cnt->Fields.CNT = 0;
Csc0->Fields.CHF = 0;
while(!Csc0->Fields.CHF);

FtmResult[FtmResultIndex++] = Cv0->Fields.VAL;

if (FtmResultIndex >= sizeof(FtmResult) / 2)
{
printf(">>");
for (int i = 0; i < FtmResultIndex; ++i)
printf(" %04x ", FtmResult[i]);
printf("\n");
_time_delay(1000);

memset(FtmResult, 0, sizeof(FtmResult));
FtmResultIndex = 0;
}

//if (Csc0->Fields.CHF)//This bit is set when the counter value is captured into CnV
//{
//    printf("Ch1: %04x ",Cv0->Fields.VAL);
//}

//if (Csc1->Fields.CHF)//This bit is set when the counter value is captured into CnV
//{
//    printf("Ch2: %04x ",Cv1->Fields.VAL);
//}

//printf("\xd");

//_time_delay(1000);
}

//_task_abort(TaskPort);
//_task_destroy(TaskPort);

//_time_delay(1000); // 1 s

//_task_restart(_task_get_id(), &data, 0);

    }

    void FlexTimerCapturingInitial()

    {

PORT_MemMapPtr PCtlMmp = (PORT_MemMapPtr)PORTC_BASE_PTR;
SIM_MemMapPtr SimMmp = SIM_BASE_PTR;
FTM_MemMapPtr FtmMmp = FTM0_BASE_PTR;

PCtlMmp->PCR[1] = PORT_PCR_MUX(4);
PCtlMmp->PCR[2] = PORT_PCR_MUX(4);

//Enable clock to FlexTimer module
mcu::registers::sim::tSCGC6* SimScgc6 = (mcu::registers::sim::tSCGC6*)&SimMmp->SCGC6;
SimScgc6->Fields.FTM0 = 1;//Enable clock to FlexTimer module

mcu::registers::sim::tSOPT4* SimSopt4 = (mcu::registers::sim::tSOPT4*)&SimMmp->SOPT4;//It seems to be in order.

//Captured frequencies are from 100 Hz up to 1600 Hz.
//The FTM has a 16-bit counter.

mcu::registers::ftm::tSC* SC = (mcu::registers::ftm::tSC*)&FtmMmp->SC;
mcu::registers::ftm::tMODE* Mode = (mcu::registers::ftm::tMODE*)&FtmMmp->MODE;

//SC->Fields.TOIE = 0;//Disable Timer Overflow Interrupts (Default)
//SC->Fields.CPWMS = 0;//FTM counter operates in up counting mode (Default)

//Mode->Fields.WPDIS = 1;//Write Protection Disable (Default)

//mcu::registers::ftm::tCOMBINE* Combine = (mcu::registers::ftm::tCOMBINE*)&FtmMmp->COMBINE;//It seems to be in order.

mcu::registers::ftm::tCNTIN* Cntin = (mcu::registers::ftm::tCNTIN*)&FtmMmp->CNTIN;
Cntin->Fields.INIT = 0x0000;//It is expected that the input capture mode be used only with CNTIN = 0x0000;

mcu::registers::ftm::tMOD* Mod = (mcu::registers::ftm::tMOD*)&FtmMmp->MOD;
Mod->Fields.MOD = 0xFFFF;

mcu::registers::ftm::tCSC* Csc0 = (mcu::registers::ftm::tCSC*)&FtmMmp->CONTROLS[0].CnSC;

//  Csc0->Fields.DMA = 1;
//Csc0->Fields.CHIE = 0;//Interrupts are disabled (Default)
//Csc0->Fields.MSA = 0; (Default)
//Csc0->Fields.MSB = 0; (Default)
Csc0->Fields.ELSA = 1;//Capture on Rising Edge
//Csc0->Fields.ELSB = 0;//Do not capture on Falling Edge (Default)

mcu::registers::ftm::tCSC* Csc1 = (mcu::registers::ftm::tCSC*)&FtmMmp->CONTROLS[1].CnSC;

//Csc1->Fields.DMA = 1;
//Csc1->Fields.CHIE = 0;//Interrupts are disabled (Default)
Csc1->Fields.ELSA = 1;//Capture on Rising Edge
//Csc1->Fields.ELSB = 0;//Do not capture on Falling Edge (Default)

///////////////////////////////////////////////////////////////////////////////////////////

Mode->Fields.FTMEN = 1;//FTM Enable. All registers including the FTM-specific registers (second set of registers) are available for use with no restrictions.

SC->Fields.CLKS = 0x01;//System Clock 100 Mhz
SC->Fields.PS = 0x07;//divide by 128 -> 781250 Hz = 0xBEBC2
// 781250 / 100 (min freq of DUT) = 7812.50 and that is less than 0xFFFF, so it's good! :smileyhappy:

    }

The result is:

>> 00fc  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 01ba  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 0010  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 00ce  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 018b  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 0248  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 009f  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 015c  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 021a  0267  0267  0267  0267  0267  0267  0267  0267  0267

>> 006f  0267  0267  0267  0267  0267  0267  0267  0267  0267

Values in the first column are not valid because measurements start some time later previous rising edges, but the others are good.



0 Kudos

1,767 Views
Futte
Contributor II

Hmm i tryit again but it still not working. Have you tryit on K60 and in CodeWarrior?

Can you meybe send the file?

0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

I compile it with IAR for K60 (rev. 4N30D).

Remove everything that is not needed, like dev::tProperties *Properties = (dev::tProperties*)data; and so on.

Actually it works in polled mode so the task priority is to be rather high.

Acute files are attached.

1,767 Views
Futte
Contributor II

Hi Serge

I dont geth it if i take away all thing like dev::tProperties *Properties = (dev::tProperties*)data i will not power up my flextimer

I am so confussed about this timer so i think i maybe sound to stupid now :smileywink:

Where are you making the initialisation off this:

void FlexTimerCapturingInitial();

I have now tryit to do my program in this way:

volatile unsigned char startPulse = 0;

extern void ftm1_isr(void)
{
unsigned char pulseWidth = 0;
unsigned char stopPulse = FTM1_C0V;

//Clear channel interrupt flag(CHF)
FTM1_C0SC &= ~0x80;

pulseWidth = stopPulse - startPulse;

if(pulseWidth> 1)
{
  fnDebugDec(pulseWidth++, 0);
 
}
}


void setupFTM1()
{
SIM_SCGC6 |= SIM_SCGC6_FTM1; /* Enable clock for FTM2 */
//Flex timer1 input filter configuration
FTM1_FILTER = 0x07;

//Flex timer configuration
FTM1_SC = 0x0C; // TOF=0 TOIE=0 CPWMS=0 CLKS=01 (system clock) PS=100 (divide by 16)
FTM1_MOD = 0xFFFF;// modulo to max
FTM1_C0SC = 0x44;  // CHF=0 CHIE=1 MSB=0 MSA=0 ELSB=0 ELSA=1 DMA=0

//Interrupt-
fnEnterInterrupt(irq_FTM0_ID, PRIORITY_EMAC, ftm1_isr);
 
PORTC_PCR6|= (0|PORT_ISF|PORT_MUX_ALT4);



}


extern void fnMyTestTask(TTASKTABLE *ptrTaskTable)
{
SIM_SCGC5 |= (SIM_SCGC5_PORTA |
         SIM_SCGC5_PORTB |
         SIM_SCGC5_PORTC |
         SIM_SCGC5_PORTD |
         SIM_SCGC5_PORTE);
setupFTM1();
}

But when i debug i am ending whit my mux and program is ending. I think this is my problem. I am using uTasker as operating system for this small projekt.

I have maket a small program for ir and that is working with some LED.

I think my initialization for IR input to the timer maybe is wrong ?

0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

I guess you don't need power up the FTM.

according to AN4381 it's needed to make some steps:

1. enable the clock for FTM1

SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;

2. enable the counter

FTM1_MODE |= FTM_MODE_FTMEN_MASK;

3. and the like... for input capturing it'll be different

//enable the counter to run in the BDM mode

FTM1_CONF |= FTM_CONF_BDMMODE(3);

//load the Modulo register and counter initial value

FTM1_MOD = 4095;

FTM1_CNTIN = 0;

//configuring FTM for quadrature mode

FTM1_QDCTRL |= FTM_QDCTRL_QUADEN_MASK;

// start the timer clock, source is the external clock

FTM1_SC |= FTM_SC_CLKS(3);

//configuring the input pins:

PORTA_PCR8 = PORT_PCR_MUX(6); // FTM1 CH0

PORTA_PCR9 = PORT_PCR_MUX(6); // FTM1 CH1


--------------------------------------------------------------------------------------


void FlexTimerCapturingInitial()

    {

        PORT_MemMapPtr PCtlMmp = (PORT_MemMapPtr)PORTC_BASE_PTR;

        SIM_MemMapPtr SimMmp = SIM_BASE_PTR;

        FTM_MemMapPtr FtmMmp = FTM0_BASE_PTR;

1. ports are FTM-inputs

        PCtlMmp->PCR[1] = PORT_PCR_MUX(4);

        PCtlMmp->PCR[2] = PORT_PCR_MUX(4);

2.        //Enable clock to FlexTimer module

        mcu::registers::sim::tSCGC6* SimScgc6 = (mcu::registers::sim::tSCGC6*)&SimMmp->SCGC6;

        SimScgc6->Fields.FTM0 = 1;//Enable clock to FlexTimer module

        mcu::registers::sim::tSOPT4* SimSopt4 = (mcu::registers::sim::tSOPT4*)&SimMmp->SOPT4;//It seems to be in order.

        mcu::registers::ftm::tSC* SC = (mcu::registers::ftm::tSC*)&FtmMmp->SC;

        mcu::registers::ftm::tMODE* Mode = (mcu::registers::ftm::tMODE*)&FtmMmp->MODE;

        mcu::registers::ftm::tCNTIN* Cntin = (mcu::registers::ftm::tCNTIN*)&FtmMmp->CNTIN;

        Cntin->Fields.INIT = 0x0000;//It is expected that the input capture mode be used only with CNTIN = 0x0000;

        mcu::registers::ftm::tMOD* Mod = (mcu::registers::ftm::tMOD*)&FtmMmp->MOD;

        Mod->Fields.MOD = 0xFFFF;

        mcu::registers::ftm::tCSC* Csc0 = (mcu::registers::ftm::tCSC*)&FtmMmp->CONTROLS[0].CnSC;

        Csc0->Fields.ELSA = 1;//Capture on Rising Edge

        ///////////////////////////////////////////////////////////////////////////////////////////

Switching on the FTM

        Mode->Fields.FTMEN = 1;//FTM Enable. All registers including the FTM-specific registers (second set of registers) are available for use with no restrictions.

Clock + prescaler

        SC->Fields.CLKS = 0x01;//System Clock 100 Mhz

        SC->Fields.PS = 0x07;//divide by 128 -> 781250 Hz = 0xBEBC2

        // 781250 / 100 (min freq of DUT) = 7812.50 and that is less than 0xFFFF, so it's good! :smileyhappy:

    }


0 Kudos

1,767 Views
Futte
Contributor II

Hi Serge

Thanks

I think my problem is that i newer geth anything in to my timer. I can make a initialization of the input from my ir, but newer geth in to go into my timer :smileysad:

are you now how to do that ?

0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

why do you decide to initialize something in IR?

Write your code here, please.

0 Kudos

1,767 Views
Futte
Contributor II

Becource i not elsa can se how to detect anything. I am comming from a AVR32 (STK500) and that is not that difficoult to use timers. I think my brain just getting confussed

my code is

volatile unsigned char startPulse = 0;

extern void ftm1_isr(void)
{
unsigned char pulseWidth = 0;
unsigned char stopPulse = FTM1_C0V;

//Clear channel interrupt flag(CHF)
FTM1_C0SC &= ~0x80;

pulseWidth = stopPulse - startPulse;

if(pulseWidth> 1)
{
  fnDebugDec(pulseWidth++, 0);
 
}
}


void setupFTM1()
{
SIM_SCGC6 |= SIM_SCGC6_FTM1; /* Enable clock for FTM2 */

//Enable the counter
FTM1_MODE |= FTM_MODE_FTMEN;



//Enable the counter to run in the BDM mode
FTM1_CONF |= FTM_CONF_BDMMODE_3;

//Load the module register and counter initial value
FTM1_MODE = 4095;

FTM1_CNTIN = 0;

//Configure FTM for quadrature mode
FTM1_C0SC |= FTM_CSC_ELSA;

//Start the timer clock, source is the external clock
FTM1_SC |= FTM_SC_CLKS_EXT;

PORTA_PCR8 = PORT_MUX_ALT6; // FTM1 CH0
PORTA_PCR9 = PORT_MUX_ALT6; // FTM1 CH1


fnDebugDec(FTM1_C0SC, 0);


}


extern void fnMyTestTask(TTASKTABLE *ptrTaskTable)
{

setupFTM1();
fnConfigure_Timer();


}

I am using Codewarrior and as operating system i have uTasker

0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

parhapse you confuse FTM1_MODE = 4095; with Modulo FTM1_MOD - modulo?

The Modulo register contains the modulo value for the FTM counter.

Why do you need quadrature mode if you just want to capture rising edges?

//Configure FTM for quadrature mode

FTM1_C0SC |= FTM_CSC_ELSA;

And as for the ISR.

I guess you don't need to do so many calculations in ISR.

FMT1_CNT = 0; - reset counter

FMT1_CnSC.CHF = 0;

if(FMT1_SC.TOF)

{

    ----invalid value, try again...

}

else

{

    short FtmResult = CnV.VAL; // that is your valid result.

}


0 Kudos

1,767 Views
Futte
Contributor II

So i dont need to configure this FTM1_MODE = 4095?

0 Kudos

1,767 Views
Futte
Contributor II

I have maket the changes according to what you are writing but i newer capture anything:

void setupFTM1()
{
SIM_SCGC6 |= SIM_SCGC6_FTM1; /* Enable clock for FTM2 */

//Enable the counter
FTM1_MODE |= FTM_MODE_FTMEN;



//Enable the counter to run in the BDM mode
FTM1_CONF |= FTM_CONF_BDMMODE_3;

//Load the module register and counter initial value
// FTM1_MODE = 4095;

//Reset counter
FTM1_CNTIN = 0;

//Configure FTM for quadrature mode
FTM1_C0SC |= FTM_CSC_ELSA;
FTM1_C0SC |= FTM_CSC_CHF;

//Start the timer clock, source is the external clock
FTM1_SC |= FTM_SC_CLKS_EXT;

PORTA_PCR8 = PORT_MUX_ALT6; // FTM1 CH0
PORTA_PCR9 = PORT_MUX_ALT6; // FTM1 CH1
fnDebugHex(PORT_MUX_ALT6, 8);

if(FTM_SC_TOF )
{
fnDebugMsg("Invalid value");
}
else
{
    short FtmResult = FTM1_C0V; // that is your valid result
    fnDebugDec(FtmResult, 0);
}

}


extern void fnMyTestTask(TTASKTABLE *ptrTaskTable)
{
char ir = 0;
fnPinConfiguration();

fnDebugMsg("Timer start:");

setupFTM1();



}

its just writing out invalid value, even if i put a controller in front of it and try to capture the ir value :smileysad:

0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

FTM1_C0SC |= FTM_CSC_CHF;

CHF

Channel Flag

Set by hardware when an event occurs on the channel. CHF is cleared by reading the CSC register while

CHnF is set and then writing a 0 to the CHF bit. Writing a 1 to CHF has no effect.

If another event occurs between the read and write operations, the write operation has no effect;

therefore, CHF remains set indicating an event has occurred. In this case a CHF interrupt request is not

lost due to the clearing sequence for a previous CHF.

0 No channel event has occurred.

1 A channel event has occurred.


As for FTMx_MOD

Read please those clauses of K60P144M100SF2RM.pdf, especially clause 39.4.3 "Counter".


0 Kudos

1,767 Views
Futte
Contributor II

Hi Serge

I have tryit to read the paper and change my code:

void FlexTimerCaptureInitial()

{

  //Enable flextimer 0 clock

  SIM_SCGC6 |= SIM_SCGC6_FTM0; /* Enable clock for FTM0 */

  // PORTC_PCR6 |= PORT_MUX_ALT3;

  PORTC_PCR3 |= PA_18_FTM_CLKIN0;  // FTM0_CH2

  PORTC_PCR3 |= PA_19_FTM_CLKIN1;

  //enable the counter to run in the BDM mode

  FTM0_CONF |=FTM_CONF_BDMMODE_3;

  FTM0_SC |= FTM_SC_CLKS_EXT;

  FTM_CSC_ELSA;

  //FTM0_C0SC |= FTM_CSC_CHF;

  fnDebugDec(FTM_CSC_ELSA, 0);

  FTM0_C0SC |= (0|FTM_CSC_ELSA | FTM_CSC_CHF);

// fnDebugDec(FTM0_C0SC, 0);

  FTM0_MODE |= FTM_MODE_FTMEN;

  FTM0_SC |= FTM_SC_PS_1;

  FTM0_SC |= FTM_SC_PS_128;

  //Reset counter

  FTM0_CNT = 0;

  //FTM0_CSC_CHF  = 0;

  

  if(FTM_SC_TOF)

  {

    fnDebugMsg("Invalid value");

  }

  else

  {

     fnDebugMsg("Its works");

  }

}

i call the funktion from my task:

extern void fnMyTestTask(TTASKTABLE *ptrTaskTable)

{

  _CONFIG_PORT_INPUT(C, (PORTC_BIT6 | PORTC_BIT6), PORT_PS_UP_ENABLE);

  FlexTimerCaptureInitial();

}

but it seems that i newer detect any signal ? so the counter just writting  fnDebugMsg("Invalid value");

0 Kudos

1,767 Views
Futte
Contributor II

Hi Serge

Finally o goth some result

The result you goth:  00fc  0267  0267  0267  0267  0267  0267  0267  0267  0267 is that the time between rising edge ?

0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

yes

0 Kudos

1,767 Views
Futte
Contributor II

Hi i am getting som resoult out but i think thay look funny

I am getting this out

25-03-2013 15:39:03.924 [RX] - 0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
0<CR><LF>
8192<CR><LF>

25-03-2013 15:39:04.586 [RX] - 0<CR><LF>
0<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>
8192<CR><LF>

from my code

void ftm0_isr(void)
{
unsigned short FtmResult[10];
unsigned short FtmResultIndex = 0;
uint16_t pulseWidth = 0;
int i = 0;
// save current interrupt count/time
 
//uint16_t stopPulse = FTM0_C0V;
 
FTM0_CNT = 0;
// clear channel interrupt flag (CHF)   
FTM0_C0SC &= ~0x80;
 
FtmResult[FtmResultIndex++] = FTM0_C0V;
 

   fnDebugDec(FtmResult[FtmResultIndex++], 0);
   fnDebugMsg("\r\n");
   fnDelayLoop(1000);
   FtmResultIndex = 0;
 

 

 

}


void TaskFeq(uint32_t data)
{



initFTMCapture();


// memset(FtmResult, 0, sizeof(FtmResult));
 
}

static void initFTMCapture()
{

PORTC_PCR1 = PORT_MUX_ALT4;//s. 266
PORTC_PCR2 = PORT_MUX_ALT4;//s. 266

//Enable clock
POWER_UP(6, SIM_SCGC6_FTM0);

SIM_SOPT4 |= (uint32_t)0x01000000UL;//FTM0CLKS = 1

// FLEX Timer0 configuration  
FTM0_SC |= (FTM_SC_PS_128| FTM_SC_CLKS_SYS);    // TOF=0 TOIE=0 CPWMS=0 CLKS=01 (system clock)  (divide by 16) 

FTM0_C0SC = 0;        /* Clear channel status and control register */
FTM0_C1SC = 0;        /* Clear channel status and control register */

// modulo to max
FTM0_MOD = 0xffff;

// CHF=0 CHIE=1 MSB=0 MSA=0 ELSB=0 ELSA=1 DMA=0
FTM0_C0SC |= (0|FTM_CSC_ELSA | FTM_CSC_CHIE);

FTM0_CONF |= FTM_CONF_BDMMODE_3;



// FTM0_SC |= (FTM_SC_PS_16 | (((uint32_t)(((uint32_t)(0x01))<<3))&0x18u));

fnEnterInterrupt(irq_FTM0_ID, PRIORITY_EMAC, ftm0_isr);


}

Can you see what is wrong :smileyhappy:

0 Kudos

1,767 Views
SergeMaslenniko
Contributor II

Hi Futte,

Set

Mode->Fields.FTMEN = 1;//FTM Enable.

and try to use internal clock, something like this:

SC->Fields.CLKS = 0x01;//System Clock 100 Mhz
SC->Fields.PS = 0x07;//divide by 128 -> 781250 Hz = 0xBEBC2

And set all of these at the very end of the function initFTMCapture

And one more thing - check with your debugger if the program uses your interrupt handler or not.

0 Kudos

1,767 Views
Futte
Contributor II

HI Serge

Thanks. I tryit to put

FTM0_MODE |= FTM_MODE_FTMEN;

FTM0_SC |= FTM_SC_CLKS_SYS;//Intern clock

FTM0_SC |= FTM_SC_PS_128;

in the end of my program, and direct before my interrupt handler, but i still geth som strenge result:

26-03-2013 11:33:24.405 [RX] - 0<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

8192<CR><LF>

and if i leth the button from the ir controller(television controller) be down i geth

26-03-2013 11:33:06.139 [RX] - 0<CR><LF>
8192<CR><LF>

26-03-2013 11:33:06.247 [RX] - 0<CR><LF>
8192<CR><LF>

26-03-2013 11:33:06.354 [RX] - 0<CR><LF>
8192<CR><LF>

i can not see that 8192 should be the time distance between to rising edge :smileysad:

0 Kudos

1,767 Views
Futte
Contributor II

i have tryit to change the preescale and also outcomment the first SC so i only have the clock in the end, but even that i change the preescale i am not changing the value :smileysad:

0 Kudos