Beginner: Delay in microsecond range / Serial Output over LPC-Link ?

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

Beginner: Delay in microsecond range / Serial Output over LPC-Link ?

720 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by naequs on Tue Oct 15 13:17:49 MST 2013
Hi Guys,

I'm fairly new to LPC's (well, uC's in general), starting out with the LPCXpresso 812 board.
For a start, i want to use a DS1820 temperature sensor and have the code all set up as outlined in MAXIM AN126.
But i need to write a function that produces a rather accurate delay in the microsecond range to properly time the samples/writes.
An interrupt based timer doenst seem like a good idea due to the clock rate.
Can anyone give me some tips on what would be an appropriate approach?

Also, a more general question about UART/Terminal: Is it possible to send serial data back through the LPC-Link so there is no need for an FTDI cable for terminal output ?

Thanks in advance !

edit: i'll try to use UART for the 1wire communication now. The second question remains unanswered though ;)
Labels (1)
0 Kudos
Reply
3 Replies

671 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by naequs on Sat Oct 26 05:52:45 MST 2013
markr: thank you! that could quite fit the bill for me.

starblue: yeah i've seen a similar example with UART, but i'm going to try markr's suggestion first.



0 Kudos
Reply

671 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Thu Oct 24 01:38:08 MST 2013
I've seen SPI used for communicating with a 1-wire device (EEPROM),
with a small external circuit to combine MISO and MOSI.
I don't know whether that is feasible on the LPC800, though.
0 Kudos
Reply

671 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by markr on Wed Oct 23 14:07:34 MST 2013
I believe there is a piece of code that will get you what you want. In the microbuilder LPC810_Codebase repository, in the file "system_LPC8xx.c", the function is called "__delayticks()" It delays 3 clock ticks every time around the loop, for a total delay of 3*X clock ticks.

I put it inside a define that gives a fairly accurate X uSec delay.

In my code, I renamed the function to __delay3ticks and include it above main, followed by

#define DELAYUS(A) __delay3ticks(A*(__SYSTEM_CLOCK/3000000))

A couple comments and a big warning:
__SYSTEM_CLOCK is the core clock, which is defined by either the LPC libraries or the microbuilder code.
It assumes flash timing is 0. This is not the default for the LPC libraries. If flash timing is 1, ie 2 clock/access, then the number of ticks will double and the divisor should be 6000000.
'A' is the desired delay time in uSec. (1e-6 seconds)
It has a granularity of 3 CPU clock ticks. So at 24MHz, the granilarity is 125nS. As the system clock slows, the granularity gets bigger. And finally
It does [u]not[/u] disable interrupts. It can be interrupted, which will throw the timing completely out the window. You could add an IRQ disable/enable to the code, but that would need to be accounted for in calculating the delay time. And depending on your code, disabling interrupts for many microseconds may have its own host of issues. TANSTAAFL.

I believe cpldcpu originally wrote the nice little piece of code that does the work.

-markr
0 Kudos
Reply