I am quite new to CortexM3, so I am not sure what is the best approach to achieve microseconds delay. What I did on ARM7 and some 8-bit processors, is "waste time loops" in assembler which do some NOPs and tweak it with oscilloscope for certain osc freq. But with enabling PLL on CortexM3 I am wondering if I could achieve same with timers ? If I set PLL to get 120Mhz, will my timer work at that freq or at base freq of 20Mhz as osc ?
Thanks.
If I set PLL to get 120Mhz, will my timer work at that freq or at base freq of 20Mhz as osc ?
My Cortex M3 manual doesn't list any PLL.
Ah, you must be talking about a specific chip that has a Cortex M3 as a core.
Presumably the documentation for that chip gives you a clue? How can we help if we don't even know what specific chip your talking about?
Remember that programming is all about getting detale correct.
Sorry I thought that is common for CortexM3. Chip is LPC1788.
Have you checked the manual for specific details?
The timers can run at a very high tick frequency. Just read out the TC value. Then busy-loop until (TC-start) >= your expected delay.
This works well for us delays.
If you then need extremely short delays, then just nop() the individual machine clock cycles.
Can I use SysTick for that ? Will it also run on PLL frequency? So I can spare the timer to do some other stuff.
It's up to you to figure out what timers you can use.
But notice that a single timer can solve many problems if you use it free-running instead of using the auto-reset feature.
Then you can use it to create 1ms or 1s interrupts or whatever you need and at the same time do software delays with maybe 0.05 us resolution. If the ISR is ready to check which match register that produced the interrupt, then you can have that same timer create up to four periodic interrupts - each with different frequency.
In the end, it's just a question of if you are willing to reprogram match registers in the ISR.
The SysTick counter is 24-bit and counts backward as I recall. Check if your part implements the optional DWT_CYCCNT register, it's 32-bit wide, and clocks at processor speed. At 120 MHz that would wrap just shy of 36 seconds.
infocenter.arm.com/.../index.jsp
embeddedb.blogspot.com/.../how-to-count-cycles-on-arm-cortex-m.html