[HELP] TOF bit from TPM register don't work on KDS 3 Mac version

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

[HELP] TOF bit from TPM register don't work on KDS 3 Mac version

1,224 Views
mr_max
Contributor IV

Hello,

 

I just downloaded KDS 3 on my Mac but I figure out a strange bug ...

 

My project use a custom delay lib ( bare board lib, no PEx). It work very good on KDS 2 both Win7 and Ubuntu systems and I also used many time with Keil µVision. But when I used my delay lib on KDS 3 Mac version, it's not work. It seems that TOF bit from TPM statut & control register never set ( I check it with EmbSys Registers). I didn't notice any increments on CTN register too, maybe that why interrupt flag bit never set . So my code just stuck into an infinity loop at line 18 or 31.

 

Below the code of my delay lib using TPM0 and FRDM-KL25Z. I also tried with TPM1 and even another Freescale board (FRDM-KL26Z), no change

 

I should tested on KDS 3 Win7 version but I don't have enough time right now. I will do it later

 

What going on ? Compiler bug ?

 

 

#include "MKL25Z4.h" #include "TPM.h"   void TPM_init(void) {     SIM->SCGC6 |= SIM_SCGC6_TPM1_MASK;//TPM0 clock activé     SIM->SOPT2 |= SIM_SOPT2_TPMSRC(0x03);//TPM clock source -> MCGIRCLK     TPM0->SC = TPM_SC_CMOD(0x00);//LPTPM desactivé     TPM0->SC |= TPM_SC_PS(0x02);//Prescaler /4 => 4MHz/4 = 4MHz => T = 1µs }  void TPM0_delai_us(int t) {     TPM0->MOD = TPM_MOD_MOD(t);//t*1µs     TPM0->SC |= TPM_SC_TOF_MASK;//Reset TOF bit     TPM0->SC |= TPM_SC_CMOD(0x01);//LPTPM activé compteur interne     while((TPM0->SC & TPM_SC_TOF_MASK)!=TPM_SC_TOF_MASK);     TPM0->SC |= TPM_SC_TOF_MASK;//clear TOF bit }  void TPM0_delai_ms(int t) {     int i;      TPM0->MOD = TPM_MOD_MOD(1000);//t*1µs     TPM0->SC |= TPM_SC_TOF_MASK;//Reset TOF bit     TPM0->SC |= TPM_SC_CMOD(0x01);//LPTPM activé compteur interne     for(i=0;i<=t;i++)     {         while((TPM0->SC & TPM_SC_TOF_MASK)!=TPM_SC_TOF_MASK);         TPM0->SC |= TPM_SC_TOF_MASK;//clear TOF bit     } } 
Labels (1)
0 Kudos
7 Replies

878 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Maxime ,

After i checked your code , i found there is a error :  SIM->SCGC6 |= SIM_SCGC6_TPM1_MASK;//TPM0 clock activé 
this  enable the TPM1, while bellow you use the TPM0 , so please chang TPM1 to TPM0.

After changed it , I have test your code on win7 KDS 3.0 ,  it can work well . Please see the result :

pastedImage_1.png

.


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

878 Views
mr_max
Contributor IV

Did you tested my code with KDS 3 on Windows ?

0 Kudos

878 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Yes ,  i test on windows 7 KDS 3.0  about kl25 chip.

You said "I didn't notice any increments on CTN register too," , i have show the CNT register is increased above screenshot.

And when you check the register from "EmbSys Registers" , please double click the register or bit you want to checked, or it will not show the updated data .

BR

Alice

0 Kudos

878 Views
mr_max
Contributor IV

Yes I double click to active EmbSys Register (TPMx registers  appear in green) when I tested. Same problem with KL26Z board ...

Capture d’écran 2015-05-20 à 10.52.38.png

0 Kudos

878 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello ,

please try the project of attachment . It create on KL25 .

And the screenshot at above is the result on my side .


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

878 Views
mr_max
Contributor IV

Ok, I just tested your project both on windows and mac and TMP0 count correctly ! The problem wasn't from the compiler or anything else but from a copy and past of  TPM.c . It seems that when I copy/past my TPM lib from my ex linux ubuntu files into a new TPM.c file , create that strange blocking of TMP0, 1, and 2 ... :smileyalert:  Maybe an invisibles characters was there into the code, I don't really know , but everything work fine now for KDS 3 both on Mac Yosemite and Windows 7. 

I wrote TPM lib on Windows 7 then I switched to Ubuntu 14 to go back to Mac. Copy/paste TPM sources files from Windows to Linux work well but it seems not from Linux to other OS ...

I learn something this week,  never use Ubuntu again ! NE-VER !  hahaha :smileysilly: 

Thanks for your help Alice.

Max

0 Kudos

878 Views
mr_max
Contributor IV

Yes you right but like I said, I tested with TPM1 and in my post SIM->SCGC6 register is a copy/past mistake. So in the original code, SIM->SCGC6 register is properly set to  TPM0 clock gate

Problem sill there ....

#include "MKL25Z4.h"

#include "TPM.h"

void TPM_init(void)

{

    SIM->SCGC6 |= SIM_SCGC6_TPM0_MASK;//TPM0 clock activé

    SIM->SOPT2 |= SIM_SOPT2_TPMSRC(0x03);//TPM clock source -> MCGIRCLK

    TPM0->SC = TPM_SC_CMOD(0x00);//LPTPM desactivé

    TPM0->SC |= TPM_SC_PS(0x02);//Prescaler /4 => 4MHz/4 = 4MHz => T = 1µs

}

void TPM0_delai_us(int t)

{

    TPM0->MOD = TPM_MOD_MOD(t);//t*1µs

    TPM0->SC |= TPM_SC_TOF_MASK;//Reset TOF bit

    TPM0->SC |= TPM_SC_CMOD(0x01);//LPTPM activé compteur interne

    while((TPM0->SC & TPM_SC_TOF_MASK)!=TPM_SC_TOF_MASK);

    TPM0->SC |= TPM_SC_TOF_MASK;//clear TOF bit

}

void TPM0_delai_ms(int t)

{

    int i;

    TPM0->MOD = TPM_MOD_MOD(1000);//t*1µs

    TPM0->SC |= TPM_SC_TOF_MASK;//Reset TOF bit

    TPM0->SC |= TPM_SC_CMOD(0x01);//LPTPM activé compteur interne

    for(i=0;i<=t;i++)

    {

        while((TPM0->SC & TPM_SC_TOF_MASK)!=TPM_SC_TOF_MASK);

        TPM0->SC |= TPM_SC_TOF_MASK;//clear TOF bit

    }

}

0 Kudos