From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18970 invoked by alias); 30 May 2008 04:43:24 -0000 Received: (qmail 18961 invoked by uid 22791); 30 May 2008 04:43:23 -0000 X-Spam-Check-By: sourceware.org Received: from elasmtp-scoter.atl.sa.earthlink.net (HELO elasmtp-scoter.atl.sa.earthlink.net) (209.86.89.67) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 30 May 2008 04:42:59 +0000 Received: from [75.82.39.242] (helo=PAULD) by elasmtp-scoter.atl.sa.earthlink.net with esmtpa (Exim 4.67) (envelope-from ) id 1K1wS8-0006JP-6w; Fri, 30 May 2008 00:42:57 -0400 From: "Paul D. DeRocco" To: "ariga masahiro" , Date: Fri, 30 May 2008 04:43:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: <000501c8c20b$273c4830$1c0110ac@ariga> X-ELNK-Trace: bd7d5d4e6f8f652c74cfc7ce3b1ad11381c87f5e51960688db0ab7970cf5ad092af26c5a431d0119350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-IsSubscribed: yes Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: RE: [ECOS] Re: In trouble of timer operations X-SW-Source: 2008-05/txt/msg00115.txt.bz2 > From: ariga masahiro [mailto:ariga@link-lab.co.jp] > > Forgive my ignorance,but please teach me more. > If I like to insert exactly, say 20msec, delay how should I write > program ? You can't delay _exactly_ 20ms, you can only delay with an accuracy of 10ms. Calling cyg_thread_delay(2) would delay more than 10ms but no more than 20ms. Delays are implemented by a timer interrupt, which is happening all the time, every 10ms, like the ticking of a clock, whether you're using it for anything or not. When you call cyg_thread_delay(2), it puts the thread to sleep, and sets its sleep count to 2 ticks. The next timer interrupt happens between 0 and 10ms later, and decrements the sleep count for the thread to 1. The timer interrupt occurs 10ms later, decrements the sleep count to 0, and wakes up the thread. If you need perfectly accurate delays, while other threads and interrupts are running, you can't do it, not with any RTOS. If you need somewhat more accuracy, like 1ms accuracy, you can change the timer interrupt to run at 1KHz, and then call cyg_thread_delay(20) for a 20ms delay. That will give you a delay that's more than 19ms but no more than 20ms. If you make the timer interrupt run at 10KHz, you have 100us resolution. But the faster you run the timer interrupt, the more of the CPU time will be wasted on timer interrupts. -- Ciao, Paul D. DeRocco Paul mailto:pderocco@ix.netcom.com -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss