How to Generate accurate Nano seconds Pulse using FRDM-MCXA156

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

How to Generate accurate Nano seconds Pulse using FRDM-MCXA156

584 Views
Puneeth1
Contributor I

HI , 

I need to generate a pulse signal on an NXP microcontroller.
Could you please advise:

  1. Which peripheral should be used (GPIO, Timer, PWM, etc.)?

  2. What is the recommended design approach?

  3. Which method or driver is best for accurate pulse generation?

My requirements are:

TCLK Clock Period  1  μs
TBIT Bit Period 8  μs
TRESET Reset Time 25 μs

Attached the Device spec , in which clearly mention the CLk and data line .

I will be using below line for clk and data.

Labels (1)
0 Kudos
Reply
3 Replies

539 Views
carlos_o
NXP TechSupport
NXP TechSupport

Hi @Puneeth1 

Thanks for your post,

What you want to accomplish could be done in several ways. 

With the SDK for the FRDM-MCXA156 that could be downloaded from MCUXpresso SDK Builder 

You could review the different driver examples.

Due to the signal you want to reproduce is not periodical I would recommend using gpio with lptmr, please review that examples.

Note that your specific implementation needs to be done by your end. 

0 Kudos
Reply

518 Views
Puneeth1
Contributor I

Hi Carlos,

Thanks for the quick response.

Since the timing is very tight, each clock pulse is 1 µs (500 ns ON and 500 ns OFF). I initially tried using an ISR, but the ISR latency itself takes longer than the pulse period, which causes the pulse to become distorted. The board clock runs at 96 MHz, so each MCU clock cycle is about 10.41 ns. Even a single instruction or conditional check introduces enough delay to further distort the pulse.

I tested using a CTimer match with the pin mapped directly, and that works; however, it does not allow control of all the GPIOs that need to be driven. I then tried using CTimer with DMA to control the GPIOs, which does work.

However, when the matchValue is set to 48, the DMA interrupt occurs later than 500 ns. When the matchValue is set to 7, the timing is closer to the expected 490/510/500 ns range. I am not sure why the CTimer is not triggering the interrupt at the exact expected time when DMA is linked.

I am attaching the code for reference. Do you have any ideas or suggestions other than this approach? Please let me know.

Thanks.

0 Kudos
Reply

486 Views
carlos_o
NXP TechSupport
NXP TechSupport

Hi @Puneeth1 

The CPU clock could run up to 150MHz in overdrive mode, you could try this change to see if you could accomplish your time requirement. 

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2290266%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHow%20to%20Generate%20accurate%20Nano%20seconds%20Pulse%20using%20FRDM-MCXA156%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290266%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHI%20%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20generate%20a%20pulse%20signal%20on%20an%20NXP%20microcontroller.%3CBR%20%2F%3ECould%20you%20please%20advise%3A%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3EWhich%20peripheral%20should%20be%20used%20(GPIO%2C%20Timer%2C%20PWM%2C%20etc.)%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EWhat%20is%20the%20recommended%20design%20approach%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EWhich%20method%20or%20driver%20is%20best%20for%20accurate%20pulse%20generation%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EMy%20requirements%20are%3A%3C%2FP%3E%3CP%3ETCLK%20Clock%20Period%26nbsp%3B%201%26nbsp%3B%20%CE%BCs%3CBR%20%2F%3ETBIT%20Bit%20Period%208%26nbsp%3B%20%CE%BCs%3CBR%20%2F%3ETRESET%20Reset%20Time%2025%20%CE%BCs%3C%2FP%3E%3CP%3EAttached%20the%20Device%20spec%20%2C%20in%20which%20clearly%20mention%20the%20CLk%20and%20data%20line%20.%3C%2FP%3E%3CP%3EI%20will%20be%20using%20below%20line%20for%20clk%20and%20data.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2290266%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EDevelopment%20Board%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2290556%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20Generate%20accurate%20Nano%20seconds%20Pulse%20using%20FRDM-MCXA156%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290556%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Carlos%2C%3C%2FP%3E%3CP%3EThanks%20for%20the%20quick%20response.%3C%2FP%3E%3CP%3ESince%20the%20timing%20is%20very%20tight%2C%20each%20clock%20pulse%20is%201%20%C2%B5s%20(500%20ns%20ON%20and%20500%20ns%20OFF).%20I%20initially%20tried%20using%20an%20ISR%2C%20but%20the%20ISR%20latency%20itself%20takes%20longer%20than%20the%20pulse%20period%2C%20which%20causes%20the%20pulse%20to%20become%20distorted.%20The%20board%20clock%20runs%20at%2096%20MHz%2C%20so%20each%20MCU%20clock%20cycle%20is%20about%2010.41%20ns.%20Even%20a%20single%20instruction%20or%20conditional%20check%20introduces%20enough%20delay%20to%20further%20distort%20the%20pulse.%3C%2FP%3E%3CP%3EI%20tested%20using%20a%20CTimer%20match%20with%20the%20pin%20mapped%20directly%2C%20and%20that%20works%3B%20however%2C%20it%20does%20not%20allow%20control%20of%20all%20the%20GPIOs%20that%20need%20to%20be%20driven.%20I%20then%20tried%20using%20CTimer%20with%20DMA%20to%20control%20the%20GPIOs%2C%20which%20does%20work.%3C%2FP%3E%3CP%3EHowever%2C%20when%20the%20matchValue%20is%20set%20to%2048%2C%20the%20DMA%20interrupt%20occurs%20later%20than%20500%20ns.%20When%20the%20matchValue%20is%20set%20to%207%2C%20the%20timing%20is%20closer%20to%20the%20expected%20490%2F510%2F500%20ns%20range.%20I%20am%20not%20sure%20why%20the%20CTimer%20is%20not%20triggering%20the%20interrupt%20at%20the%20exact%20expected%20time%20when%20DMA%20is%20linked.%3C%2FP%3E%3CP%3EI%20am%20attaching%20the%20code%20for%20reference.%20Do%20you%20have%20any%20ideas%20or%20suggestions%20other%20than%20this%20approach%3F%20Please%20let%20me%20know.%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2290469%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20Generate%20accurate%20Nano%20seconds%20Pulse%20using%20FRDM-MCXA156%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290469%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F257874%22%20target%3D%22_blank%22%3E%40Puneeth1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20for%20your%20post%2C%3C%2FP%3E%0A%3CP%3EWhat%20you%20want%20to%20accomplish%20could%20be%20done%20in%20several%20ways.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20the%20SDK%20for%20the%20FRDM-MCXA156%20that%20could%20be%20downloaded%20from%20%3CA%20href%3D%22https%3A%2F%2Fmcuxpresso.nxp.com%2Fdashboard%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EMCUXpresso%20SDK%20Builder%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20could%20review%20the%20different%20driver%20examples.%3C%2FP%3E%0A%3CP%3EDue%20to%20the%20signal%20you%20want%20to%20reproduce%20is%20not%20periodical%20I%20would%20recommend%20using%20gpio%20with%20lptmr%2C%20please%20review%20that%20examples.%3C%2FP%3E%0A%3CP%3ENote%20that%20your%20specific%20implementation%20needs%20to%20be%20done%20by%20your%20end.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2291115%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20Generate%20accurate%20Nano%20seconds%20Pulse%20using%20FRDM-MCXA156%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291115%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F257874%22%20target%3D%22_blank%22%3E%40Puneeth1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20CPU%20clock%20could%20run%20up%20to%20150MHz%20in%20overdrive%20mode%2C%20you%20could%20try%20this%20change%20to%20see%20if%20you%20could%20accomplish%20your%20time%20requirement.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E