25MHz pin toggle - LPC178x

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

25MHz pin toggle - LPC178x

3,785 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Sat Sep 24 09:18:21 MST 2011
I want to generate a 25MHz frequency on a pin, from what I read this may be doable as follows

Set PCLK to 100MHz
Set timer match to 1
Set timer prescale to 0
Set timer MAT pin to toggle

Is that correct?


______
Rob
0 Kudos
Reply
13 Replies

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Thu Sep 29 05:55:32 MST 2011
XMOS isn't a replacement for a general-purpose MCU like the LPC17xx etc. ... it's just a useful compliment if you need a lot of high-speed raw IO cheaper than an FPGA and without the same steep learning curve (Verilog/VHDL, etc.).  I've only played with them briefly myself, but they sound perfect for reliably generating high-speed timing signals without spending $30 on an FPGA and learning the tools that go with it.  Under $10 and a few days effort tops.

It's not going to replace your main MCU, though, and neither is an FPGA (unless you have a LOT of time on your hands).
0 Kudos
Reply

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Thu Sep 29 02:07:27 MST 2011
I've looked at XMOS a few times but still don't quite get it. There doesn't appear to be any peripheral devices, do you bit bang everything?

I can see it being good for my trigger state machine, or something simple and fast, but not suitable for a main processor because of the limited memory.

Can you use assembler?

If I use external hardware I should be able to get 50MHz, but let's stay with the original brief of 25MHz.

The fastest loop I can think of (outside using ASM) is something like this

while (1) output_pin = 1;

On an AVR that will toggle the pin every time and the loop will take maybe 2-3 cycles. But obviously absolutely nothing else can happen including interrupts.

With hardware timers such as on the LPC I'm reasonably happy I can get 25MHz but with all the other stuff that needs doing and the indeterminate DMA timing I've now decided that external hardware is the way to go.

Essentially I need to do two things

a) 19-bit synchronous counter for external RAM address
b) 24-bit magnitude/equality comparator and state machine for triggering

The counter would be a no-brainer with a CPLD/FPGA.

The trigger comparator and state machine will be a challenge with any technology if high speed is required. With hardware of course the comparison and state machine stuff will be lightning fast but my brain hurts just thinking about the FPGA design.

On the other hand I can see it would not be too difficult in software.

Presently I'm considering dedicating an LPC111x to this job. At 50MHz I reckon I can do the job in 1uS or less, in which case I just state in the manual that when using complex triggers the trigger state has to be stable for at least 1uS.

Now using the XMOS I get 2x the raw speed plus multiple threads as well. So can one thread look at the 24 bits and do the magnitude comparison on 12 of them. Another thread looks at the other 12 bits and does an equality comparison. They both set flags on common memory.

A third thread reads these flags and starts a timer when both are true.

If the timer times out and the flags are still both true we have trigger event. 

With 2x the clock and 2 threads at the sharp end maybe I can detect an event with 250nS resolution which is 4x what I could do with an LPC111x.

Is it worth learning a new processor architecture for that?

Probably not if that's all I get, but if the XMOS can replace all the other hardware MUXes, counters etc and save me from using CPLD/FPGAs then maybe.

Can you point me to some proper documentation, I can find nothing that resembles a normal data sheet on the XMOS site.

______
Rob
0 Kudos
Reply

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Wed Sep 28 13:25:28 MST 2011
If you're going to do something off board have a look at XMOS.  The learning curve isn't as steep as with an FPGA (you can program in C, etc.) but you keep a lot of the advantages of parallel processing within reason.  You are limited to 100MHz per thread, 4 threads per core ... though they have a higher speed version with 125/500MHz as well.  But you should have no problem generating 25MHz output with that, and can use another thread to integrate with the LPC via any common bus like SPI that's easy to do in SW.

Significantly less troublesome and cheaper than an FPGA for something like what you want.
0 Kudos
Reply

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Tue Sep 27 15:39:00 MST 2011
Thanks for your help guys.

I think what I want to do is right on the edge so I'm researching into taking it all off-chip with an FPGA and external RAM.

If I do this everything is more straightforward, I can go to 50MHz, and I can get 512k words or more of storage. This would add about $20 to the cost but that would be worth it I think to get the extra capabilities.

So now I have two new (to me) technologies to learn, LPC and FPGA.

______
Rob
0 Kudos
Reply

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Sep 27 09:18:57 MST 2011
No, it doesn't :) We are talking about 100MHz already :mad:

BTW: If it would be possible to use match values like 4 to [B][COLOR=Red]toggle[/COLOR][/B] a signal, that would be 100MHz / 2 / 4 = 12.5 MHz  :eek:
0 Kudos
Reply

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TommyBurger on Tue Sep 27 09:08:23 MST 2011
It might help to route 100 MHz to the timer. Then your match value is 4. Look at the peripheral clock registers PCLKSEL. LPC17xx errata says to set these registers before setting up the CCLK.
0 Kudos
Reply

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Sep 26 06:21:32 MST 2011
So pll_clk is 100MHz.

CLKOUT pin = pll_clk /4 = 25MHz.

pclk = pll_clk /4 = 25MHz as well

The two signals will be synchronized because they are both derived from the same source, so far so good.

But they have a high chance of being out of phase because you can't write to PCLKSEL and CLKOUTCFG at the same time. This could be made pretty deterministic with some tight ASM code though.

I'm not even sure that's a bad thing because I don't know exactly then the DMA will do the read anyway.

I guess there will never be a way to know if the external latch and the DMA read are synched. Maybe it doesn't matter.
______
Rob
0 Kudos
Reply

3,639 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Sep 26 06:07:08 MST 2011

Quote: graynomad
Yes I thought of that and as I'm not using USB I could route the USB clock to that pin. With a 10MHz XTAL there is a valid combination of M and P to get 25MHz.



Just use main clock and  clkout divider (CLKOUTDIV=3) =  100MHz /4 :eek:
0 Kudos
Reply

3,637 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Sep 26 05:49:46 MST 2011
Sorry for not responding, I thought I'd selected to get an email notification but obviously not.


Quote:
What about using CLKOUT?


Yes I thought of that and as I'm not using USB I could route the USB clock to that pin. With a 10MHz XTAL there is a valid combination of M and P to get 25MHz.



Quote:
You can use a timer as well, but because 25MHz output only allows 4 ticks you probably want to make sure there are no interrupts that might throw your timing off,


Surely interrupts won't affect the timer outputs.



Quote:
If all you need is a 25MHz output there are far cheaper ways to get it than dedicating a $10 MCU to that task.


Very true, but see below.


Quote:
Should this 25Mhz be generated continously ?
And what else should your application do at the same time? Any interrupt routine ?


For a given period that may vary from uS to seconds. I can if necessary cease all other activity and in fact will have to sit in a very tight ASM loop, if possible tight enough to fit into the 40nS cycle time (probably not likely but maybe).



Quote:
So setting a match register to 1 is a very optimistic wish


That's one thing that worries me. However before being reset the timer is supposed to stay at the match value for one PCLK cycle. The match value is 1 so we should get two counter values (0 and 1) ie PCLK/2 or 50MHz.

Following from that, with a MAT pin set to toggle we should get the timer freq (50MHz) /2 or 25MHz.

I've attached a pic that shows how I think it should work.


Going back to basics I'll tell you what I'm trying to do.

In a nutshell I want to sample 16 pins as fast as possible and store the values in RAM, at least at 20MHz but 25 would be better. This is a logic analyzer and storage scope application.

The above match event is supposed to do two things

a) Request a DMA transfer from the port to RAM
b) Provide a clock pulse for external latches.

I think the two events should be synchronized otherwise I'd just use an external oscillator for the latches.

Does anyone have a better method?

I'm new to LPCs and am prepared to be told that I'm dreaming and this can't be done :)


______
Rob
0 Kudos
Reply

3,637 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Sep 24 15:14:45 MST 2011
Oops, forgotten to mention: No, it's not possible :mad:

Although you calculation seems to be correct, don't forget that a timer needs a few clock cycles to work.

So setting a match register to 1 is a very optimistic wish :), but will not generate the calculated signal.

In fact you will end somewhere at a few MHz...
0 Kudos
Reply

3,637 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Polux rsv on Sat Sep 24 14:31:59 MST 2011
Should this 25Mhz be generated continously ?
And what else should your application do at the same time? Any interrupt routine ?:rolleyes::D

Angelo
0 Kudos
Reply

3,637 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Sat Sep 24 14:27:02 MST 2011
You don't mention the crystal that you're using on your board, since this will be the biggest factor to determine if you can generate a 25MHz output or not (since you'll need to have something you can multiply and divide and arrive at exactly 25MHz within the limits of the PLL, etc.).

I'd agree with Zero that using the CLKOUT would probably be the easiest.  You can use a timer as well, but because 25MHz output only allows 4 ticks you probably want to make sure there are no interrupts that might throw your timing off, etc.  If all you need is a 25MHz output there are far cheaper ways to get it than dedicating a $10 MCU to that task.  But ... maybe it's just for a specific duration?
0 Kudos
Reply

3,637 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Sep 24 09:37:27 MST 2011
What about using CLKOUT?
0 Kudos
Reply