//////////////////////////////////////////////////////////////////////////// ////////// Cycle based timing macros (processor speed independent) ///////// //////////////////////////////////////////////////////////////////////////// /* Delay of exactly 1 Tcy */ #define delay_1tcy() asm("nop") /* Delay of exactly 2 Tcy */ #define delay_2tcy() asm("nop"); asm("nop") /* Delay of exactly 4 Tcy */ #define delay_4tcy() delay_2tcy(); delay_2tcy() /* Delay of exactly 5 Tcy */ #define delay_5tcy() delay_4tcy(); delay_1tcy() /* Delay of exactly 10 Tcy */ #define delay_10tcy() delay_5tcy(); delay_5tcy() I have started with these macro definitions. But the problem started to raise when i want to adopt them for proper functions. That will be a bit trouble for me. But after completing such work we can be competitor tot he C18 libraries :) 2006/2/24, Chen Xiao Fan : > > > > > -----Original Message----- > > From: piclist-bounces@mit.edu > > On Behalf Of G=F6khan SEVER > > Sent: Friday, February 24, 2006 7:02 AM > > To: Microcontroller discussion list - Public. > > Subject: [PIC] accurate delay routines > > > > Whereas its PIC18 family compiler it has the delay routines > > what i'm looking for. The routines are cycle based and the > > codes are all open for the routines. I started to > > examine the sources but i realized that they are all ASM based > > and mostly benefitted of PIC18 ASM. I dont have much experience > > with PIC18 assembly so it will be hard for me to adopt them > > for PIC16 family. Are there any other open-source cycle based > > delay implementations which will facilitate my coding works? > > I look into the delay routine source codes of C18 and they > are quite simple. You have to learn some assemblies anyway. > > Back to PICC, maybe the following example macros can > serve as a starting point for you. > > #define delay_1tcy() asm("\tclrwdt") //(or use nop) > #define delay_2tcy() asm("\tincf pcl, w") > #define delay_4tcy() delay_2tcy();delay_2tcy() > #define delay_5tcy() delay_4tcy();delay_1tcy() > #define delay_10tcy() delay_4tcy();delay_4tcy();delay_2tcy() > > Another thing is to use simulator and that will count the > total delay time for you. > > > Regards, > Xiaofan > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist