Reply by John S April 22, 20102010-04-22
#define uStimer T0TC
#define TicPeruS 36
Int32U uSstore;

#define ifelapsedwrt(y,x) ((y + (x) - uStimer) & 0x80000000)
#define ifelapseduS(x) (ifelapsedwrt(uSstore,x*TicPeruS))
#define waitus(x) uSstore = uStimer; while (ifelapseduS(x) == 0);

This is what I use for uS timing. It has the advantage that the condition stays true for 0x80000000 ticks, which means no worrying about missing the exact match and going around again.

--- In l..., Robert Adsett wrote:
>
> On 4/13/2010 5:34 PM, voltz56 wrote:
> >
> >
> > Hmmm, I still thought it would be possible to generate accurate
> > delays down a usec without using interrupts especially in a test
> > environment that is running no other code (just the delay routine).
> > Iv achieved this on an 8051 I didnt think it would be a problem
> > on....
>
> Some notes I made.
>
> http://www.aeolusdevelopment.com/AppNotes/LPC210X/an-timerperformance.pdf
>
> Non-interrupt based, but about 10uS overhead. That could be reduced by
> sacrificing dynamic range.
>
> Why do you need uS delays? uS precision is straightforward, single
> digit uS delays not so easy.
>
> Robert
>
> --
> http://www.aeolusdevelopment.com/
>
> From the Divided by a Common Language File (Edited to protect the guilty)
> ME - "I'd like to get Price and delivery for connector Part # XXXXX"
> Dist./Rep - "$X.XX Lead time 37 days"
> ME - "Anything we can do about lead time? 37 days seems a bit high."
> Dist./Rep - "that is the lead time given because our stock is live....
> we currently have stock."
>

An Engineer's Guide to the LPC2100 Series

Reply by Robert Adsett April 18, 20102010-04-18
On 4/13/2010 5:34 PM, voltz56 wrote:
> Hmmm, I still thought it would be possible to generate accurate
> delays down a usec without using interrupts especially in a test
> environment that is running no other code (just the delay routine).
> Iv achieved this on an 8051 I didnt think it would be a problem
> on....

Some notes I made.

http://www.aeolusdevelopment.com/AppNotes/LPC210X/an-timerperformance.pdf

Non-interrupt based, but about 10uS overhead. That could be reduced by
sacrificing dynamic range.

Why do you need uS delays? uS precision is straightforward, single
digit uS delays not so easy.

Robert

--
http://www.aeolusdevelopment.com/

From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time? 37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live....
we currently have stock."
Reply by voltz56 April 15, 20102010-04-15
I'm beginning to think the keil software has a mind of its own. I just tested again and now Im getting +20ns "every time". This I can live with. Thanks for all your help.

Regards,
J
--- In l..., "Mark" wrote:
>
> Hi
>
> At 48MHz there would be an increment once every 20ns.
> I don't know how well this clock is synchronised to the clock being used for instruction execution - 20ns jitter is probably to be expected but I can't explain +60..70ns every three interrupts. Maybe it is an accumulation of the 20ns each time (?)
>
> Regards
>
> Mark
> --- In l..., "voltz56" wrote:
> >
> > Excellent that seems to have worked, thanks. Although every 3th interrupt is off by +60 to 70ns, is that normal?
> >
> > Regards,
> > J
> >
> > --- In l..., "Mark" wrote:
> > >
> > > Hi
> > >
> > > I would try setting the pre-scaler to 0 and setting the match value to the number of clocks that you require (0x30).
> > >
> > > Regards
> > >
> > > Mark
> > >
> > >
> > > http://www.uTasker.com
> > >
> > >
> > > --- In l..., "voltz56" wrote:
> > > >
> > > >
> > > > --- In l..., "voltz56" wrote:
> > > > >
> > > > > When I configure the prescaler for a 1ms tick, it is off by 84ns
> > > > when
> > > > > checked in the keil debugger, this much inaccuracy I can live with.
> > > > > , but when I have it configured for 1us it is off by approximately
> > > > > 940ns, this is a major problem for me.
> > > > >
> > > > > Regards,
> > > > > J
> > > > >
> > > > >
> > > > > //delay = us * no_loops
> > > > > void delay_us(unsigned int no_loops)
> > > > > {
> > > > > unsigned int i;
> > > > > for(i = 0; i < no_loops; i++)
> > > > > {
> > > > > //pclk = cclk = 48MHz
> > > > >
> > > > > T0_PR = 0x30; //Load Prescaler register
> > > > for
> > > > > usec tick, formula --> toHex(interval/(1/pclk))
> > > > > T0_TCR = 0x00000003; //Reset counter and
> > > > prescaler
> > > > > T0_TCR = 0x00000001; //enable timer
> > > > > while ( T0_TC < 1);
> > > > > T0_TCR &= ~(1<<0); // Stop timer
> > > > > }/*end for*/
> > > > >
> > > > > }/*end delay*/
> > > > >
> > > >
> > > > Still no joy with this, anyone, any ideas or suggestions?
> > > >
> > > > http://pastebin.com/1j2b9G62
> > > >
> > > > Regards,
> > > > J
> > > >
> > >
>

Reply by Mark April 15, 20102010-04-15
Hi

At 48MHz there would be an increment once every 20ns.
I don't know how well this clock is synchronised to the clock being used for instruction execution - 20ns jitter is probably to be expected but I can't explain +60..70ns every three interrupts. Maybe it is an accumulation of the 20ns each time (?)

Regards

Mark

--- In l..., "voltz56" wrote:
>
> Excellent that seems to have worked, thanks. Although every 3th interrupt is off by +60 to 70ns, is that normal?
>
> Regards,
> J
>
> --- In l..., "Mark" wrote:
> >
> > Hi
> >
> > I would try setting the pre-scaler to 0 and setting the match value to the number of clocks that you require (0x30).
> >
> > Regards
> >
> > Mark
> >
> >
> > http://www.uTasker.com
> >
> >
> > --- In l..., "voltz56" wrote:
> > >
> > >
> > > --- In l..., "voltz56" wrote:
> > > >
> > > > When I configure the prescaler for a 1ms tick, it is off by 84ns
> > > when
> > > > checked in the keil debugger, this much inaccuracy I can live with.
> > > > , but when I have it configured for 1us it is off by approximately
> > > > 940ns, this is a major problem for me.
> > > >
> > > > Regards,
> > > > J
> > > >
> > > >
> > > > //delay = us * no_loops
> > > > void delay_us(unsigned int no_loops)
> > > > {
> > > > unsigned int i;
> > > > for(i = 0; i < no_loops; i++)
> > > > {
> > > > //pclk = cclk = 48MHz
> > > >
> > > > T0_PR = 0x30; //Load Prescaler register
> > > for
> > > > usec tick, formula --> toHex(interval/(1/pclk))
> > > > T0_TCR = 0x00000003; //Reset counter and
> > > prescaler
> > > > T0_TCR = 0x00000001; //enable timer
> > > > while ( T0_TC < 1);
> > > > T0_TCR &= ~(1<<0); // Stop timer
> > > > }/*end for*/
> > > >
> > > > }/*end delay*/
> > > >
> > >
> > > Still no joy with this, anyone, any ideas or suggestions?
> > >
> > > http://pastebin.com/1j2b9G62
> > >
> > > Regards,
> > > J
> > >
>

Reply by voltz56 April 15, 20102010-04-15
Excellent that seems to have worked, thanks. Although every 3th interrupt is off by +60 to 70ns, is that normal?

Regards,
J

--- In l..., "Mark" wrote:
>
> Hi
>
> I would try setting the pre-scaler to 0 and setting the match value to the number of clocks that you require (0x30).
>
> Regards
>
> Mark
> http://www.uTasker.com
> --- In l..., "voltz56" wrote:
> >
> >
> > --- In l..., "voltz56" wrote:
> > >
> > > When I configure the prescaler for a 1ms tick, it is off by 84ns
> > when
> > > checked in the keil debugger, this much inaccuracy I can live with.
> > > , but when I have it configured for 1us it is off by approximately
> > > 940ns, this is a major problem for me.
> > >
> > > Regards,
> > > J
> > >
> > >
> > > //delay = us * no_loops
> > > void delay_us(unsigned int no_loops)
> > > {
> > > unsigned int i;
> > > for(i = 0; i < no_loops; i++)
> > > {
> > > //pclk = cclk = 48MHz
> > >
> > > T0_PR = 0x30; //Load Prescaler register
> > for
> > > usec tick, formula --> toHex(interval/(1/pclk))
> > > T0_TCR = 0x00000003; //Reset counter and
> > prescaler
> > > T0_TCR = 0x00000001; //enable timer
> > > while ( T0_TC < 1);
> > > T0_TCR &= ~(1<<0); // Stop timer
> > > }/*end for*/
> > >
> > > }/*end delay*/
> > >
> >
> > Still no joy with this, anyone, any ideas or suggestions?
> >
> > http://pastebin.com/1j2b9G62
> >
> > Regards,
> > J
>

Reply by Mark April 15, 20102010-04-15
Hi

I would try setting the pre-scaler to 0 and setting the match value to the number of clocks that you require (0x30).

Regards

Mark
http://www.uTasker.com
--- In l..., "voltz56" wrote:
> --- In l..., "voltz56" wrote:
> >
> > When I configure the prescaler for a 1ms tick, it is off by 84ns
> when
> > checked in the keil debugger, this much inaccuracy I can live with.
> > , but when I have it configured for 1us it is off by approximately
> > 940ns, this is a major problem for me.
> >
> > Regards,
> > J
> >
> >
> > //delay = us * no_loops
> > void delay_us(unsigned int no_loops)
> > {
> > unsigned int i;
> > for(i = 0; i < no_loops; i++)
> > {
> > //pclk = cclk = 48MHz
> >
> > T0_PR = 0x30; //Load Prescaler register
> for
> > usec tick, formula --> toHex(interval/(1/pclk))
> > T0_TCR = 0x00000003; //Reset counter and
> prescaler
> > T0_TCR = 0x00000001; //enable timer
> > while ( T0_TC < 1);
> > T0_TCR &= ~(1<<0); // Stop timer
> > }/*end for*/
> >
> > }/*end delay*/
> > Still no joy with this, anyone, any ideas or suggestions?
>
> http://pastebin.com/1j2b9G62
>
> Regards,
> J
>

Reply by voltz56 April 15, 20102010-04-15
--- In l..., "voltz56" wrote:
>
> When I configure the prescaler for a 1ms tick, it is off by 84ns
when
> checked in the keil debugger, this much inaccuracy I can live with.
> , but when I have it configured for 1us it is off by approximately
> 940ns, this is a major problem for me.
>
> Regards,
> J
> //delay = us * no_loops
> void delay_us(unsigned int no_loops)
> {
> unsigned int i;
> for(i = 0; i < no_loops; i++)
> {
> //pclk = cclk = 48MHz
>
> T0_PR = 0x30; //Load Prescaler register
for
> usec tick, formula --> toHex(interval/(1/pclk))
> T0_TCR = 0x00000003; //Reset counter and
prescaler
> T0_TCR = 0x00000001; //enable timer
> while ( T0_TC < 1);
> T0_TCR &= ~(1<<0); // Stop timer
> }/*end for*/
>
> }/*end delay*/
>

Still no joy with this, anyone, any ideas or suggestions?

http://pastebin.com/1j2b9G62

Regards,
J

Reply by voltz56 April 14, 20102010-04-14
--- In l..., "rtstofer" wrote:
> > Well I think I spoke too soon. The interrupt is firing, but Im still
> > having trouble with the interval accuracy. When configured for 1us the
> > interval measured in keil debugger is 190ns.
> >
> > http://pastebin.com/LneyYUq5
> >
> > Regards,
> > V
> > The value you are setting to T0_MCR seems a little odd.
>
> Richard
>

Ya just noticed that, think I accidentally assigned that to MCR instead of MR0 at some point when testing. That is not my problem though as I have just checked.

Regards,
J

Reply by rtstofer April 14, 20102010-04-14
> Well I think I spoke too soon. The interrupt is firing, but Im still
> having trouble with the interval accuracy. When configured for 1us the
> interval measured in keil debugger is 190ns.
>
> http://pastebin.com/LneyYUq5 Regards,
> V
>

The value you are setting to T0_MCR seems a little odd.

Richard

Reply by voltz56 April 14, 20102010-04-14
--- In l..., "Mark" wrote:
>
> --- In l..., "voltz56" vltzzzzzzz@ wrote:
> >
> > > I do not see any code turning on the power for the timers.
> > >
> > > regards,
> > > Charles
> > >
> >
> > Your joking right?
> >
> > I think the problem is with my startup file, -there doesnt appear to
> be
> > any code to enable/config interrupts, but Im unsure how to do this.
> >
> > http://pastebin.com/cDB2j3Sb
> >
> > Regards,
> > J
> > Hi
>
> All peripherals default to powered up on the LPC2106 so, as long as
they
> haven't been disabled to save power, a power up is not necessary.
>
> The peripheral code looks OK so I would agree that the interrupt
hasn't
> been enabled to the core. This can be done in the code as follows,
> depending on compiler:
>
> __enable_interrupt() - IAR intrinsic
> __enable_irq() - Keil intrinsic
>
> for GCC the following assembler can be called (extern void
> __irq_en(void) from C)
> .code 32
> .global __irq_en
> __irq_en:
> mrs r12, CPSR
> /* get present SR value */
> bic r12, r12, #0xC0
> /* remove IRQ and FIQ mask bits */
> msr CPSR_c, r12
> /* set new value to SR */
> bx lr
> /* return with interrupts enabled */
> Regards
>
> Mark
>
> www.uTasker.com
Well I think I spoke too soon. The interrupt is firing, but Im still
having trouble with the interval accuracy. When configured for 1us the
interval measured in keil debugger is 190ns.

http://pastebin.com/LneyYUq5

Regards,
V