Timer Emulation using PIT and GPIO

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

Timer Emulation using PIT and GPIO

1,661 Views
shauldorf
Contributor V

For educational purpose I'm trying to rewrite Application Note

AN4419 - Using DMA and GPIO to emulate time functionality on Kinetis (2012).

I use MCUXpresso 10.2 and KSDK FRDM-K64F_2.4.2

My configuration is empty board files (~20 MHz sys and bus clock)

In original implementation the GPIO PCR is configured as

PORTD->PCR[0] |= PORT_PCR_MUX(1) | PORT_PCR_IRQC(1);

My solution it is working only when PCR is

PORTD->PCR[0] |= PORT_PCR_MUX(1) | PORT_PCR_IRQC(3);

I believe that something is wrong with my DMA TCD setup but I can't fined what is wrong.

I'm attaching project zip file.

0 Kudos
8 Replies

1,402 Views
jared1
Contributor I

shauldorf‌ Did you ever get this working? I'm working on implementing this on the FRDM-k28F and was hoping for pointers.

0 Kudos

1,402 Views
shauldorf
Contributor V

Hi;

Yes it is working exactly as I described in my question.

I am using PORTD IRQ configuration 0x3 in AN4419 it is 0x1.

You can find there my zip main.c file

Shaul

0 Kudos

1,402 Views
mjbcswitzerland
Specialist V

Hi

I don't know what is in the source code but the application note's code is incorrect.

PORTD_PCR7|=(0|PORT_PCR_MUX(1)|PORT_PCR_IRQC(0x1));
enables DMA trigger on a single edge whereby the description says it is needed on both edges.

Therefore probably a Typo in the code part of the document.

Note that the PIT DMA output method is integrated into the PIT driver in the uTasker project. The user interface just sets the PIT_OUTPUT_DMA_TRIG flag and the port(s) to be toggled and the rest is automated (generates 2 complimentary square wave outputs):
      PIT_SETUP pit_setup;                                       // PIT interrupt configuration parameters
    pit_setup.int_type = PIT_INTERRUPT;
    pit_setup.mode = PIT_PERIODIC;
    pit_setup.count_delay = PIT_US_DELAY(500);                 // 500us period (1kHz)
    pit_setup.mode = (PIT_PERIODIC | PIT_OUTPUT_DMA_TRIG);     // periodic with DMA trigger to control a port toggle
    pit_setup.ulPortBits = (PORTA_BIT1 | PORTA_BIT23);         // toggle PTA1 and PTA23 on each PIT trigger
    pit_setup.ucPortRef = PORTA;
    pit_setup.ucPIT = 1;                                        // use PIT1 (this will use DMA channel 1, 0 would use DMA channel 0, etc.)
    pit_setup.int_handler = 0;                                  // no interrupt due to DMA

    _CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, (PORTA_BIT1 | PORTA_BIT23), (PORTA_BIT1), (PORT_SRE_SLOW | PORT_DSE_HIGH)); // prepare port outputs for complimentary square wave
    fnConfigureInterrupt((void *)&pit_setup);                   // configure PIT


This is however foreseen more for emergencies where other timers are not already available since the DMA transfer (when high frequencies are generated) can have a bus loading effect that is then noticeable due to sharing with other high speed peripherals (eg. it makes USB unreliable at above around 2MHz on KL parts), plus there is some jitter on the output.

Note also that the complete operation is simulated in the uTasker project so that it (including PIT and DMA) can be inspected in the simulation.

Regards

Mark

0 Kudos

1,402 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Shaul,

   I checked the AN4419, please check this description:

pastedImage_1.png

So, it seems, it should work with both edge.

If you just can work with 3, DMA request on either edge, rising edge can't work, I suggest you also enable the pin internal pull up.PORTX_PCRn[PE]=1, .PORTX_PCRn[PS]=1, then try  it again.


Have a great day,
Kerry

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

0 Kudos

1,402 Views
shauldorf
Contributor V

Hi Kerry

In AN4419 page #8 you can see that configuration is rising edge.

AN4419 -PCR[ ] config..png

Triggering on dual edge will produce double frequency compared to rising edge .

My IO port PTD0 (J2_6) is an output port so pullup doesn’t solve the problem because it is used for the input pad.

In my attached demo today I found a problem that after power up it also doesn’t work until to run option with DMA  of 8 bit(byte) width. It is in attached (BarePIT_GPIO_ByteOpt_AN4419.zip).

Then you can run my first zip project (Bare_PIT_GPIO_AN4419.zip) that is 32 bit DMA.

This is that at power up TCD registers are undefined. 

So I think that there is something wrong with my DMA TCD, the first BarePIT_GPIO_ByteOpt_AN4419 pre-configs well.

In second run of Bare_PIT_GPIO_AN4419 it uses the previous setup and every thing is OK.

 

But this doesn’t solve the original question  dual/single edge triggering .

 

Regards

Shaul

0 Kudos

1,401 Views
shauldorf
Contributor V

Sorry I forgot to send Byte DMA zip file,:smileycry:

0 Kudos

1,401 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Shaul,

    Thanks for your updated information.

    Could you tell me, your attached BarePIT_GPIO_ByteOpt_AN4419 is created by yourself or from the nxp official AN4419SW?

   If not, I will help you to try to get the official according code at first.


Have a great day,
Kerry

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

0 Kudos

1,401 Views
shauldorf
Contributor V

Hi;

It is my project created in MCUXpresso IDE and SDK 2.4.2 for K64F configured as empty board (with modification to allow UART debug console).

AN4419SW was used as reference it is an old AN (2012) implemented on • TWR-K40X256

I guess TCD configuration was done differently (using API).

Shaul

0 Kudos