public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Drift in Real Time Clock
@ 2007-06-05  4:59 M Arshad Khan
  2007-06-05 12:31 ` M Arshad Khan
  2007-06-05 17:49 ` Andrew Lunn
  0 siblings, 2 replies; 8+ messages in thread
From: M Arshad Khan @ 2007-06-05  4:59 UTC (permalink / raw)
  To: ecos-discuss, ecos-discuss

Hello
we r running eCos on simple intel based PC. we want to find the drift
in the real time colck, for this we simply capture a 100Sec signal
using 20mSec interrupt. the signal was captured using a counter by
triggering the channel of the counter using parallel port of the PC.
the code is given below.
from the results we found that  the drift was 7mili Sec in 100 Sec.
This drift is very large to fitt for real time colck. we also tried
this code on different PC's but app same results. can any body tell me
why i am getting so much drift...
any suggestions..



#include <pkgconf/system.h>     /* which packages are enabled/disabled */
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
#endif
#ifdef CYGPKG_LIBC
# include <pkgconf/libc.h>
#endif
#ifdef CYGPKG_IO_SERIAL
# include <pkgconf/io_serial.h>
#endif

#ifndef CYGFUN_KERNEL_API_C
# error Kernel API must be enabled to build this example
#endif
/* INCLUDES */

#include <stdio.h>                      /* printf */
#include <string.h>                     /* strlen */
#include <cyg/kernel/kapi.h>            /* All the kernel specific stuff */
#include <cyg/io/io.h>                  /* I/O functions */
#include <cyg/hal/hal_arch.h>           /* CYGNUM_HAL_STACK_SIZE_TYPICAL */

#include <cyg/hal/hal_io.h>		/* HAL input and output */

cyg_uint8 val;

cyg_handle_t counter_hdl;
cyg_handle_t sys_clk;
cyg_handle_t alarm_hdl;
cyg_alarm_t alarm_handler;
cyg_alarm alarm_obj;

unsigned long iindex;
unsigned long ccount=0;
//
// Main starting point for the application.
//

void cyg_user_start( void )
{
	HAL_WRITE_UINT8(0x378,0x00);
        sys_clk = cyg_real_time_clock();

        cyg_clock_to_counter( sys_clk,&counter_hdl );

        cyg_alarm_create(
counter_hdl,alarm_handler,(cyg_addrword_t)&iindex,&alarm_hdl,&alarm_obj
);

        cyg_alarm_initialize( alarm_hdl,cyg_current_time() + 200,2 );



}

//
// Alarm handler.
//

void alarm_handler(cyg_handle_t alarm_handle, cyg_addrword_t data )
{
	if(ccount==0)
	{
		    	HAL_WRITE_UINT8(0x378,0x01);	      	
	}
		
	if(ccount==(100*50))
	{
		    	HAL_WRITE_UINT8(0x378,0x02);	      	
	}
	ccount++;
}

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ECOS] Drift in Real Time Clock
  2007-06-05  4:59 [ECOS] Drift in Real Time Clock M Arshad Khan
@ 2007-06-05 12:31 ` M Arshad Khan
  2007-06-05 17:49 ` Andrew Lunn
  1 sibling, 0 replies; 8+ messages in thread
From: M Arshad Khan @ 2007-06-05 12:31 UTC (permalink / raw)
  To: ecos-discuss, ecos-discuss

Hello
we r running eCos on simple intel based PC. we want to find the drift
in the real time colck, for this we simply capture a 100Sec signal
using 20mSec interrupt. the signal was captured using a counter by
triggering the channel of the counter using parallel port of the PC.
the code is given below.
from the results we found that  the drift was 7mili Sec in 100 Sec.
This drift is very large to fitt for real time colck. we also tried
this code on different PC's but app same results. can any body tell me
why i am getting so much drift...
any suggestions..



#include <pkgconf/system.h>     /* which packages are enabled/disabled */
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
#endif
#ifdef CYGPKG_LIBC
# include <pkgconf/libc.h>
#endif
#ifdef CYGPKG_IO_SERIAL
# include <pkgconf/io_serial.h>
#endif

#ifndef CYGFUN_KERNEL_API_C
# error Kernel API must be enabled to build this example
#endif
/* INCLUDES */

#include <stdio.h>                      /* printf */
#include <string.h>                     /* strlen */
#include <cyg/kernel/kapi.h>            /* All the kernel specific stuff */
#include <cyg/io/io.h>                  /* I/O functions */
#include <cyg/hal/hal_arch.h>           /* CYGNUM_HAL_STACK_SIZE_TYPICAL */

#include <cyg/hal/hal_io.h>		/* HAL input and output */

cyg_uint8 val;

cyg_handle_t counter_hdl;
cyg_handle_t sys_clk;
cyg_handle_t alarm_hdl;
cyg_alarm_t alarm_handler;
cyg_alarm alarm_obj;

unsigned long iindex;
unsigned long ccount=0;
//
// Main starting point for the application.
//

void cyg_user_start( void )
{
	HAL_WRITE_UINT8(0x378,0x00);
        sys_clk = cyg_real_time_clock();

        cyg_clock_to_counter( sys_clk,&counter_hdl );

        cyg_alarm_create(
counter_hdl,alarm_handler,(cyg_addrword_t)&iindex,&alarm_hdl,&alarm_obj
);

        cyg_alarm_initialize( alarm_hdl,cyg_current_time() + 200,2 );



}

//
// Alarm handler.
//

void alarm_handler(cyg_handle_t alarm_handle, cyg_addrword_t data )
{
	if(ccount==0)
	{
		    	HAL_WRITE_UINT8(0x378,0x01);	      	
	}
		
	if(ccount==(100*50))
	{
		    	HAL_WRITE_UINT8(0x378,0x02);	      	
	}
	ccount++;
}

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Drift in Real Time Clock
  2007-06-05  4:59 [ECOS] Drift in Real Time Clock M Arshad Khan
  2007-06-05 12:31 ` M Arshad Khan
@ 2007-06-05 17:49 ` Andrew Lunn
  2007-06-05 18:31   ` Andrew Lunn
  2007-06-06 10:33   ` M Arshad Khan
  1 sibling, 2 replies; 8+ messages in thread
From: Andrew Lunn @ 2007-06-05 17:49 UTC (permalink / raw)
  To: M Arshad Khan; +Cc: ecos-discuss, ecos-discuss

On Tue, Jun 05, 2007 at 09:59:21AM +0500, M Arshad Khan wrote:
> Hello
> we r running eCos on simple intel based PC. we want to find the drift
> in the real time colck, for this we simply capture a 100Sec signal
> using 20mSec interrupt. the signal was captured using a counter by
> triggering the channel of the counter using parallel port of the PC.
> the code is given below.
> from the results we found that  the drift was 7mili Sec in 100 Sec.
> This drift is very large to fitt for real time colck. we also tried
> this code on different PC's but app same results. can any body tell me
> why i am getting so much drift...
> any suggestions..
> 

I believe the PC clock ticks at a base rate of 1193182Hz. The eCos
clock is usually configured for 10ms. That would be 11931.82
ticks. Obviously you cannot have fractional ticks, so you end up with
11932 ticks per 10ms. The error is then 0.0015%. 

0.0015% of 100Sec = 0.0015seconds i.e. 1.5ms. So something is not
right somewhere, but i think you get the idea. 

Check i have the clock frequency correct and perform your own
calculation about what accuracy is achievable.

            Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Drift in Real Time Clock
  2007-06-05 17:49 ` Andrew Lunn
@ 2007-06-05 18:31   ` Andrew Lunn
  2007-06-06 10:33   ` M Arshad Khan
  1 sibling, 0 replies; 8+ messages in thread
From: Andrew Lunn @ 2007-06-05 18:31 UTC (permalink / raw)
  To: M Arshad Khan; +Cc: ecos-discuss, ecos-discuss

On Tue, Jun 05, 2007 at 09:59:21AM +0500, M Arshad Khan wrote:
> Hello
> we r running eCos on simple intel based PC. we want to find the drift
> in the real time colck, for this we simply capture a 100Sec signal
> using 20mSec interrupt. the signal was captured using a counter by
> triggering the channel of the counter using parallel port of the PC.
> the code is given below.
> from the results we found that  the drift was 7mili Sec in 100 Sec.
> This drift is very large to fitt for real time colck. we also tried
> this code on different PC's but app same results. can any body tell me
> why i am getting so much drift...
> any suggestions..
> 

I believe the PC clock ticks at a base rate of 1193182Hz. The eCos
clock is usually configured for 10ms. That would be 11931.82
ticks. Obviously you cannot have fractional ticks, so you end up with
11932 ticks per 10ms. The error is then 0.0015%. 

0.0015% of 100Sec = 0.0015seconds i.e. 1.5ms. So something is not
right somewhere, but i think you get the idea. 

Check i have the clock frequency correct and perform your own
calculation about what accuracy is achievable.

            Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Drift in Real Time Clock
  2007-06-05 17:49 ` Andrew Lunn
  2007-06-05 18:31   ` Andrew Lunn
@ 2007-06-06 10:33   ` M Arshad Khan
  2007-06-06 10:37     ` M Arshad Khan
  2007-06-06 12:20     ` Nick Garnett
  1 sibling, 2 replies; 8+ messages in thread
From: M Arshad Khan @ 2007-06-06 10:33 UTC (permalink / raw)
  To: M Arshad Khan, ecos-discuss, ecos-discuss

On 6/5/07, Andrew Lunn <andrew@lunn.ch> wrote:
> On Tue, Jun 05, 2007 at 09:59:21AM +0500, M Arshad Khan wrote:
> > Hello
> > we r running eCos on simple intel based PC. we want to find the drift
> > in the real time colck, for this we simply capture a 100Sec signal
> > using 20mSec interrupt. the signal was captured using a counter by
> > triggering the channel of the counter using parallel port of the PC.
> > the code is given below.
> > from the results we found that  the drift was 7mili Sec in 100 Sec.
> > This drift is very large to fitt for real time colck. we also tried
> > this code on different PC's but app same results. can any body tell me
> > why i am getting so much drift...
> > any suggestions..
> >
>
> I believe the PC clock ticks at a base rate of 1193182Hz. The eCos
> clock is usually configured for 10ms. That would be 11931.82
> ticks. Obviously you cannot have fractional ticks, so you end up with
> 11932 ticks per 10ms. The error is then 0.0015%.
>
> 0.0015% of 100Sec = 0.0015seconds i.e. 1.5ms. So something is not
> right somewhere, but i think you get the idea.
>
> Check i have the clock frequency correct and perform your own
> calculation about what accuracy is achievable.
>
>            Andrew
>
yes the problem was with the initialization value i varry this value
and got delay of 1.5ms in 100 s using initialization value of 11934
(very strange...). now i want to reduce the time of one tick from 10ms
to 1ms... so that i can generate interrupt of 1ms i tried it by
changing the values of clock resolution numerator and clock resolution
denominator but same 10ms. any suggestion in this regard?...

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Drift in Real Time Clock
  2007-06-06 10:33   ` M Arshad Khan
@ 2007-06-06 10:37     ` M Arshad Khan
  2007-06-06 12:20     ` Nick Garnett
  1 sibling, 0 replies; 8+ messages in thread
From: M Arshad Khan @ 2007-06-06 10:37 UTC (permalink / raw)
  To: M Arshad Khan, ecos-discuss, ecos-discuss

On 6/5/07, Andrew Lunn <andrew@lunn.ch> wrote:
> On Tue, Jun 05, 2007 at 09:59:21AM +0500, M Arshad Khan wrote:
> > Hello
> > we r running eCos on simple intel based PC. we want to find the drift
> > in the real time colck, for this we simply capture a 100Sec signal
> > using 20mSec interrupt. the signal was captured using a counter by
> > triggering the channel of the counter using parallel port of the PC.
> > the code is given below.
> > from the results we found that  the drift was 7mili Sec in 100 Sec.
> > This drift is very large to fitt for real time colck. we also tried
> > this code on different PC's but app same results. can any body tell me
> > why i am getting so much drift...
> > any suggestions..
> >
>
> I believe the PC clock ticks at a base rate of 1193182Hz. The eCos
> clock is usually configured for 10ms. That would be 11931.82
> ticks. Obviously you cannot have fractional ticks, so you end up with
> 11932 ticks per 10ms. The error is then 0.0015%.
>
> 0.0015% of 100Sec = 0.0015seconds i.e. 1.5ms. So something is not
> right somewhere, but i think you get the idea.
>
> Check i have the clock frequency correct and perform your own
> calculation about what accuracy is achievable.
>
>            Andrew
>
yes the problem was with the initialization value i varry this value
and got delay of 1.5ms in 100 s using initialization value of 11934
(very strange...). now i want to reduce the time of one tick from 10ms
to 1ms... so that i can generate interrupt of 1ms i tried it by
changing the values of clock resolution numerator and clock resolution
denominator but same 10ms. any suggestion in this regard?...

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Drift in Real Time Clock
  2007-06-06 10:33   ` M Arshad Khan
  2007-06-06 10:37     ` M Arshad Khan
@ 2007-06-06 12:20     ` Nick Garnett
  2007-06-06 14:29       ` Nick Garnett
  1 sibling, 1 reply; 8+ messages in thread
From: Nick Garnett @ 2007-06-06 12:20 UTC (permalink / raw)
  To: M Arshad Khan; +Cc: ecos-discuss, ecos-discuss

"M Arshad Khan" <marshadkhan@gmail.com> writes:

> yes the problem was with the initialization value i varry this value
> and got delay of 1.5ms in 100 s using initialization value of 11934
> (very strange...). now i want to reduce the time of one tick from 10ms
> to 1ms... so that i can generate interrupt of 1ms i tried it by
> changing the values of clock resolution numerator and clock resolution
> denominator but same 10ms. any suggestion in this regard?...
>

You need to change the period value too, it is not changed
automatically if you just change the resolution parameters. However,
going to a 1KHz tick rate will make the drift worse. For better
accuracy it might make sense to choose a frequency that is more
directly related to the PC clock frequency. 

Also, the crystal that drives the clock will have limited accuracy,
which will vary with things like temperature. So there is only a
limited amount you can do to eliminate drift; unless you regularly
query an external clock and calibrate it in the way that fully
functional NTP clients do.

-- 
Nick Garnett                                     eCos Kernel Architect
eCosCentric Limited     http://www.eCosCentric.com/   The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.    Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Drift in Real Time Clock
  2007-06-06 12:20     ` Nick Garnett
@ 2007-06-06 14:29       ` Nick Garnett
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Garnett @ 2007-06-06 14:29 UTC (permalink / raw)
  To: M Arshad Khan; +Cc: ecos-discuss, ecos-discuss

"M Arshad Khan" <marshadkhan@gmail.com> writes:

> yes the problem was with the initialization value i varry this value
> and got delay of 1.5ms in 100 s using initialization value of 11934
> (very strange...). now i want to reduce the time of one tick from 10ms
> to 1ms... so that i can generate interrupt of 1ms i tried it by
> changing the values of clock resolution numerator and clock resolution
> denominator but same 10ms. any suggestion in this regard?...
>

You need to change the period value too, it is not changed
automatically if you just change the resolution parameters. However,
going to a 1KHz tick rate will make the drift worse. For better
accuracy it might make sense to choose a frequency that is more
directly related to the PC clock frequency. 

Also, the crystal that drives the clock will have limited accuracy,
which will vary with things like temperature. So there is only a
limited amount you can do to eliminate drift; unless you regularly
query an external clock and calibrate it in the way that fully
functional NTP clients do.

-- 
Nick Garnett                                     eCos Kernel Architect
eCosCentric Limited     http://www.eCosCentric.com/   The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.    Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-06-06 10:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-05  4:59 [ECOS] Drift in Real Time Clock M Arshad Khan
2007-06-05 12:31 ` M Arshad Khan
2007-06-05 17:49 ` Andrew Lunn
2007-06-05 18:31   ` Andrew Lunn
2007-06-06 10:33   ` M Arshad Khan
2007-06-06 10:37     ` M Arshad Khan
2007-06-06 12:20     ` Nick Garnett
2007-06-06 14:29       ` Nick Garnett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).