LPC1114 Microseconds Delay

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

LPC1114 Microseconds Delay

3,455 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 07:40:21 MST 2013
Hello my dear friends,

I am in need of some pointers on how to get delays going in the microsecond range. I have already done he obvious and taken a look around the forums for anyone else who has had this issue. Here is one: http://knowledgebase.nxp.com/showthread.php?t=2817

I have tried using a SysTick interrupt handler just like in post #5 and also tried the custom delay function in post #2. Also tried modifying the MHZ_PRESCALE in timer16.h all to no avail. I can get the milliseconds delay to work easely but getting it into microseconds has been giving a lot of trouble. Any pointers and help is greatly appreciated. Thank you for your time.
0 Kudos
Reply
14 Replies

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 15:05:19 MST 2013
Thanks RazorConcepts, that did the trick.

GPIOSetDir( 3, 2, 1 ); //DIR M0 TO sensor
GPIOSetValue( 1, 9, 1 ); //DIR M0 TO sensor

GPIOSetValue( 3, 2, 0 );// Send low pulse
for (i = 0; i<25000; i++) {}
GPIOSetValue( 3, 2, 1 );// Send high pulse
for (i = 0; i<6; i++) {}
GPIOSetValue( 3, 2, 0 );// Send low pulse

GPIOSetValue(1, 9, 0 );  //DIR sensor TO M0


Not a very elegant way I guess but it was the easiest thing to do.
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Aug 07 13:31:37 MST 2013
You can just spin, waiting for the period to elapse. The most reliable way of doing this would be to set off a timer at a known frequency and then poll the timer waiting for the correct period to expire.

What I told you is that you cannot use an interrupt driven timer to measure such small delays on a 48mhz processo, and expect to do anything else.
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RazorConcepts on Wed Aug 07 13:15:18 MST 2013
You would make a for loop, and inside you call NOP (no operation) instructions. I'm new to LPC as well so I'm not sure on the exact syntax of the NOP instruction for LPC devices, or how many cycles a NOP instruction takes (but its usuualy just one instruction cycle).
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 13:13:42 MST 2013
Mike Simmonds, so basically interface the single sensor pin into two separate pins on the MCU by Y-splitting the sensor pin and adding a diode on the PWM signal output pin?
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 13:13:19 MST 2013

Quote: MikeSimmonds
It is very probably true that your micro can not interface in a bit bang fashion as you describe and the Fall Guy has demonstrated.

However, I would suggest interfacing your device's signal pin to TWO cpu pins! -- one input and one output with a loop back prevention diode between them.

The the poor design of the sensor is mitigated by treating the start and receive as two independant problems.

Set the output pin to a standard PWM -- 2 microsecs hi, 200 millisesc low (i.e. whatever you want the sampling interval to be).
Set the inpit pin for input capture to get a value proportional to the return pulse width -- that is precisely what it is designed to do.

For details, these forums have many posts both on PWM and on input capture; there is example code in the LPCXpresso setup and on this site also.

Regards, Mike



So basically interface the single sensor pin into two separate pins on the MCU by Y-splitting the sensor pin and adding a diode on the PWM signal output pin?
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 12:20:29 MST 2013
What would be the best way to waste clock cycles?
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Wed Aug 07 11:38:48 MST 2013
It is very probably true that your micro can not interface in a bit bang fashion as you describe and the Fall Guy has demonstrated.

However, I would suggest interfacing your device's signal pin to TWO cpu pins! -- one input and one output with a loop back prevention diode between them.

The the poor design of the sensor is mitigated by treating the start and receive as two independant problems.

Set the output pin to a standard PWM -- 2 microsecs hi, 200 millisesc low (i.e. whatever you want the sampling interval to be).
Set the inpit pin for input capture to get a value proportional to the return pulse width -- that is precisely what it is designed to do.

For details, these forums have many posts both on PWM and on input capture; there is example code in the LPCXpresso setup and on this site also.

Regards, Mike


0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RazorConcepts on Wed Aug 07 11:38:03 MST 2013
An interrupt based microsecond delay may not work, but you can just waste clock cycles to act as a delay.
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 10:45:12 MST 2013
Can't really just spit out a PWM on the pin. The signal pin switches between being an output and an input periodically. Once the 5us pulse is sent, I then wait about Tholdoff  = 750us and then switch the GPIO pin to be an input at which point the sensor sends a pulse with the pulse width being proportional to the distance to the obstacle in front of the sensor. A PWM would not work in this application. 

So what youre saying is that the LPC1114 cannot do microsecond delays? Is this a true statement?
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Aug 07 10:27:22 MST 2013
That sounds like a PWM to me:
http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign/LPC1343_LPC1114_PWM.aspx
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 10:09:20 MST 2013
Basically I want to send a low pulse on a GPIO pin and hold it low for 2 microseconds and then send a high pulse that lasts for 5 microseconds and then send another low 2 microsecond pulse and so on and so forth. I am trying to interface the Parralax Ping Sensor: http://www.pololu.com/file/0J214/PING_documentation.pdf
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Aug 07 09:22:36 MST 2013
Lets say your LPC1114 is running at 48MHz.

So the processor can execute a MAXIMUM of 48 instructions in 1 microsecond. However, not all instructions are single-cycle, there may be wait-states imposed by the flash and branches will lose a couple of cycles while it refills the pipeline. In reality it will be more like 40 instructions allowing for 'delays'.

Servicing a SysTick interrupt is going to take about 30 of those instructions (I haven't counted, but that is the right order).

I assume you are going to have other interrupts in the system? Are you going to try to do something useful, too?

Hmm. I don't think this is going to work...
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by exgreyfox on Wed Aug 07 09:08:15 MST 2013

Quote: TheFallGuy
How many microsecond delay do you want? The core is not going to get much chance to execute code if you want a small number of microseconds.



I am looking to do a delay of 2 and 5 microseconds to interface a sonar sensor.
0 Kudos
Reply

3,071 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Aug 07 08:09:41 MST 2013
How many microsecond delay do you want? The core is not going to get much chance to execute code if you want a small number of microseconds.
0 Kudos
Reply