How can I configure the KL26 TPM as a free-running counter using the external clock input pin TPM_CLKIN0?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How can I configure the KL26 TPM as a free-running counter using the external clock input pin TPM_CLKIN0?

1,423件の閲覧回数
kowen
Contributor I

I'm using a Teensy LC with a KL26 and would like to eventually configure the two TPMs as free-running counters clocked by two separate clock inputs. Right now, I'm okay working on just getting one counter going. From reading the reference manual, this seems like it should be possible. Here's what I've configured so far:

SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); //FLL or PLL/2
SIM_SOPT4 = 0; //TPM0 uses TPM_CLKIN0 external clock pin

SIM_SCGC5 |= 0x00000400; //Port B clock gate enabled
SIM_SCGC6 |= 0x01000000; //Enable clock to TPM0
PORTB_PCR16 = 0x00000400; //Alt function 4, pulldown enabled

TPM0_SC = 0x00000010; //CMOD = 10 (TPM_EXTCLK increments count, no prescale)
TPM0_CNT = 0; //Reset counter

Despite the above configuration, I can never get TPM0_CNT to increment by toggling the TPM_CLKIN0 pin. I am able to configure the LPTMR unit as a free-running counter and have successfully used it by itself, but am in need of a second counter to run simultaneously. 

What else do I need to do to successfully use TPM0 as a free-running, externally-clocked counter? Thanks!

ラベル(2)
タグ(3)
0 件の賞賛
返信
5 返答(返信)

1,095件の閲覧回数
mjbcswitzerland
Specialist V


Kyle

You have selected either MCGFLLCLK or MCGPLLCLK as TPM's clock. This is used to synchronise the external input to and should be at least twice the speed of the input used to increment TPM0_CNT.


If you haven't set PLLFLLSEL in SIM_SOPT2 (not visible in the code) it means that the TPM's clock will be the MCGFFLCLK (output from the FLL). Is this what you want? If so, are you sure that the FLL hasn't been disabled?

Regards

Mark

http://www.utasker.com/kinetis/TEENSY_LC.html

0 件の賞賛
返信

1,095件の閲覧回数
kowen
Contributor I

Mark, when I read back the value of SIM_SOPT2, it's 0x050500C0, indicating that both UART0 and TPM are getting MCGPLLCLK/2, if I'm reading that correctly. 

If I change it to 0x060500C0, the serial port is no longer showing up, preventing further debugging. Removing the assignment altogether gives me my serial port back but still shows no sign of the counter incrementing.

I can't seem to find a sufficient block diagram in the reference manual that shows the propagation of the external clocks, TPM_CLKIN0 and TPM_CLKIN1. It seems like a lot has to happen for the external clocks to make their way to the counters. Figure 31-1 shows a single "external clock" going into a "synchronizer", selected by CMOD, but no specifics of the "external clock" or "synchronizer", unfortunately.

0 件の賞賛
返信

1,095件の閲覧回数
mjbcswitzerland
Specialist V

Hi Kyle

 

I tried on the Teensy LC with the TPM clocked from most possible sources (32kHz slow clock, 4MHz fast clock, direct from the 16Mz oscillator and from the PLL at 48MHz). Since this board doesn't normally have and debug capability I checked first in the uTasker simulator:

 

pastedImage_1.png

 

Attached is a binary for the TEENS-LC that is set up with a terminal interface on the USB, which you can load with the Teensy Loader program.

I set up to have TPM0 clocked from the PLL and the input to the counter to be from TPM_CLKIN1 (this is pin 26 (the hole below the top right one in the image above)).

 

If you connect to the CDC with a terminal emulator you can do memory debugging (to check all register content).

1. Hit enter key to get main menu

2. Enter menu 3 (I/O menu)

3. Now you can monitor registers
"md 40038000 l 4" displays the timer registers where the count value can be seen.

 

Each time there is a pulse on the clock input this counter increments as expected.
Every 480 pulse it will reset (due to the overflow value that is set).

 

I didn't notice what was wrong with your code but if you use the memory display command you can compare all of the register settings with those that you have and possibly identify the error.

 

Regards

 

Mark

0 件の賞賛
返信

1,095件の閲覧回数
kowen
Contributor I

Hi Mark, thanks for your help so far. I uploaded the hex file using the loader; the LED blinks at 2 Hz or so, but the serial port doesn't seem to enumerate even after unplugging and replugging. I had this happen before when I was playing with SIM_SOPT2 with other values. Do you have any suggestions in getting the serial port back? 

How was your hex file generated? Without attempting disassembly, can you tell me what some of the pertinent register values are set to? Losing the serial port will be an issue, though...maybe the part of SIM_SOPT2 that controls the USB clock is not configured correctly? Thanks!

0 件の賞賛
返信

1,095件の閲覧回数
mjbcswitzerland
Specialist V

Kyle

The USB works normally on my TEENSY-LC so you probably just need to install the VCOM driver. If you use Win 10 then driver no install is needed but if you use older Windows versions you can use one from this page:
http://www.utasker.com/kinetis/TEENSY_LC.html

Look for:

"The following drivers can be used with this device:
- uTaskerFreescaleMultiVirtualCOMx1-6.inf USB CDC installation file for 32-bit windows (usable for 1..6 USB-CDC composite interfaces).
- uTaskerFreescaleMultiVirtualCOM1-6_64bit.inf USB CDC installation file for 64-bit windows (usable for 1..6 USB-CDC composite interfaces).
See the following for a guide to installing unsigned drivers on Windows 8.1"

Once you get it running you can look at all registers.

I build the uTasker project with GCC to generate the HEX file.

Regards

Mark

0 件の賞賛
返信