Author Topic: Generating a 5MHz clock on a GPIO pin on an LPC1768  (Read 2166 times)

0 Members and 1 Guest are viewing this topic.

Online perdrixTopic starter

  • Frequent Contributor
  • **
  • Posts: 677
  • Country: gb
Generating a 5MHz clock on a GPIO pin on an LPC1768
« on: August 02, 2023, 12:43:54 pm »
The processor is running with a processor clock of 100MHz.

I only have the following GPIO pins available for use:

 P0.2, P0.3, P0.23, P0.24, P0.25 and P0.26

I tried to use a timer interrupt to generate a 5MHz clock signal, but AFAICT there just aren't enough processor cycles available to handle a timer interrupt every 10 clocks (which makes sense) and I only achieved a 1MHz signal out and there were probably not many processor cycles available to do any other work!

Is there a neat way to get a 5MHz clock out those pins using hardware to toggle it (perhaps using one of the peripherals)?  Ideally I'd like to use P0.23 and P0.26 for the clock signal (but not both at the same time).

Thanks, David
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3634
  • Country: it
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #1 on: August 02, 2023, 12:53:04 pm »
Check the datasheet for one of the following
- Output compare/PWM/Whatever is called on LPC
- Timer module could have a trigger output
- Reference clock generator
- I2S Clock
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 4103
  • Country: nl
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #2 on: August 02, 2023, 01:22:06 pm »
I'm not familiar with that processor, but normally this is done with one of the timer modules in your uC.

It may also be possible to abuse DMA for this. I'm thinking along the lines of setting up a small array with ones and zero's and use DMA to output that array to an output pin in a circular way. I never used DMA myself though so I'm not sure if this can work.
 

Offline wek

  • Frequent Contributor
  • **
  • Posts: 561
  • Country: sk
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #3 on: August 02, 2023, 02:38:49 pm »
I don't use the LPC1768, but P0.23 appears to be usable as I2SRX_CLK - can't that be abused in some way to output the required clock?

JW
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: dk
« Last Edit: August 03, 2023, 12:11:02 pm by bingo600 »
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 28861
  • Country: nl
    • NCT Developments
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #5 on: August 03, 2023, 06:58:20 am »
The USB enabled LPC mcus typically have two plls. One for usb and one for the rest of the system. So you can run the timer from a 100mhz clock and usb from a 48mhz clock
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online perdrixTopic starter

  • Frequent Contributor
  • **
  • Posts: 677
  • Country: gb
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #6 on: August 03, 2023, 09:35:43 am »
Let's make this clear I already know how to use the timers in the LPC1768.   The clock runs at 100MHz.  To generate a 5MHz square wave you need to generate a timer interrupt every 100ns or 10 clock cycles

To do that the timer has to be set with a MR0 set to 10, and run off the processor clock (CCLK).  This causes a timer interrupt every TEN processor cycles and it takes many more clocks than that to process an interrupt.

That's why I need a HW generated 5MHz (and 1MHz - though not at the same time).

PWM doesn't appear to be an option as AFAICT none of these pins appear to be usable as PWM output pins (please put me straight if I got that wrong).

I'm not sure about abusing I2S to clock out on P0.23 - I've a nasty feeling that it will interfere with way too many other pins I see a lot of google in my future.

D.


 

Online hans

  • Super Contributor
  • ***
  • Posts: 1731
  • Country: 00
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #7 on: August 03, 2023, 10:12:17 am »
Yes, no timer outputs on any of those pins..
Regarding DMA to transfer to GPIOs: you can't use bitbanding for that, as that's a memory view only available to CPU. So it would need to write the whole port. Now the LPC1768 does have SET/CLR registers, but they are not combined (as in STM32), so the DMA controller would have to support increment both memory and peripheral address.
But a bigger issue with DMA is the high amount of bus transfers. 5MHz clock = 10MT/s, of the 100MHz bus cycles available. I don't know about the bus structure used, but if it has some arbitration overhead it could consume even more bandwidth or cause considerable jitter.

Now it does look you could use I2SRX_CLK. Despite the name "RX", the I2S master could still be the LPC1768, where it is sampling data from an audio ADC. I think you can map individual I2S pins using the pin function select registers, so only I2SRX_CLK is driven to P0[23]. Fig 107 on page 487 of the user manual does show several dividers in place, where:
I2SRXMCLK = PCLK_I2S * (X/Y) /2
(which signal could stay internal in the chip)
And I2SRX_CLK is I2SRXMCLK / N where N=1..64

So that sounds like it could do what you want.
« Last Edit: August 03, 2023, 01:54:19 pm by hans »
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3634
  • Country: it
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #8 on: August 03, 2023, 10:47:27 am »
Unless you have some pins that are hardwired to be SPI/I2S when you switch on the peripheral (for example, dedicated pins achieve higher clock frequency), i see no reason why you couldn't enable I2S and just route the clock pin.

Another crazy idea: Output a lower frequency clock (how much depends on the hardware) and use a PLL to scale it up. But i don't know how much hardware you can change, and if you can change the hardware i would look into changing the pin arrangement so you have PWM and be done with it.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 28861
  • Country: nl
    • NCT Developments
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #9 on: August 03, 2023, 12:13:14 pm »
This sounds like it is time for a new board revision that provides a timer pwm or match output on the right pin
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 
The following users thanked this post: Siwastaja, JPortici

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 9769
  • Country: fi
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #10 on: August 03, 2023, 12:26:34 pm »
This sounds like it is time for a new board revision that provides a timer pwm or match output on the right pin

Yes, or modifying the existing board(s), if not hundreds of them, with a simple bodge wire (or two if you have all other pins in use and need to do a swap).
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6571
  • Country: es
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #11 on: August 03, 2023, 01:49:02 pm »
Is it like in stm32, where you can remap pins to different peripherals?
What are the options for those pins?

You still have a way no matter what, run a timer at 10MHz, attach a circular dma channel configured to transfer a buffer with two values for resetting/setting the BSRR bits for that port (Is it like stm32?). Edit: FIOSET/FIOCLR?
So each time the timer expires the DMA updates the pin.
In circular mode the DMA will run forever, no need of any irq.
« Last Edit: August 03, 2023, 02:03:19 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 28861
  • Country: nl
    • NCT Developments
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #12 on: August 03, 2023, 07:28:04 pm »
Time triggered dma could be a way but it will eat a significant amount of memory bandwidth
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline wek

  • Frequent Contributor
  • **
  • Posts: 561
  • Country: sk
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #13 on: August 03, 2023, 08:59:49 pm »
> I'm not sure about abusing I2S to clock out on P0.23 - I've a nasty feeling that it will interfere with way too many other pins I see a lot of google in my future.

Why don't you just try. It should be something like a 10 minute exercise - set P0.23 to this peripheral, enable clock to I2S, set its Rx to master, set the clock prescaler. I don't quite see why would that interfere with any other pin.

JW
 

Online peter-h

  • Super Contributor
  • ***
  • Posts: 4629
  • Country: gb
  • Doing electronics since the 1960s...
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #14 on: August 04, 2023, 06:25:56 am »
Could this be done with DMA, memory to GPIO, circular mode, reading two locations one containing 1 and the other 0 ?

You would not have much control over the frequency but it would be fast ;)
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 4103
  • Country: nl
Re: Generating a 5MHz clock on a GPIO pin on an LPC1768
« Reply #15 on: August 05, 2023, 01:55:16 pm »
Let's make this clear I already know how to use the timers in the LPC1768.   The clock runs at 100MHz.  To generate a 5MHz square wave you need to generate a timer interrupt every 100ns or 10 clock cycles

To do that the timer has to be set with a MR0 set to 10, and run off the processor clock (CCLK).  This causes a timer interrupt every TEN processor cycles and it takes many more clocks than that to process an interrupt.

Using a timer to generate a periodic ISR is only one of the many uses of a timer.
Another very common use of a timer is to generate a PWM output directly.
And it's easy to program the timer itself in such a way that it overflows every 200ns combined wit resetting the output at overflow, and then setting the output with a capture  / compare register halfway the count.

That's why I need a HW generated 5MHz (and 1MHz - though not at the same time).
Yes, exactly. Program the timer once, and it will output 5MHz to a hardware pin for as long as it has power applied or you have had enough of it.

The only limitation is that not all outputs can be used for PWM, which leads to:
PWM doesn't appear to be an option as AFAICT none of these pins appear to be usable as PWM output pins (please put me straight if I got that wrong).
Stop the guesswork and check the datasheet. You'll know soon enough if this can work or not. Usually there is some big matrix in the datasheet which lists all the alternate pin functions for each of the pins.
And if it's possible, it is by far the best method. All the others are kludges. I would even consider cutting a PCB track and routing a wire or two to swap some pins to make this possible, or revise the project and spin a new PCB variant.

This may work:
I'm not sure about abusing I2S to clock out on P0.23 - I've a nasty feeling that it will interfere with way too many other pins I see a lot of google in my future.

With STM32 you can swap pins on an individual bases to a GPIO pin, or to an "alternate function" (which is one of timer, uart, spi, etc pins). and by only setting the clock pin to an "alternate output", it's quite possible it won't interfere with other pins.


« Last Edit: August 05, 2023, 02:00:05 pm by Doctorandus_P »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf