Paul wrote: >Hello everybody, >I am having deficalty in getting the right dely to the clock i am using >for my pic16f877. which i am using 20MHz clock. I have calculated a >1msec as follows: > >I have a clock of 20MHz that meens 50nsec No, this means 200ns. Each instruction takes 4, sometimes 8 (eg. goto) clock cycles. Cut down your multiplier by a factor of 4. >then I have three instructions for each function so what i did is >50nsec X 3inst X (how many time to be multiplied (n))= 1msec >so, >n = (1m X 20MHz) / 3inst = 6666.66666 >then, >I devided that number by 100 to split it into two equations, so I got 67 >and 100. > >the following is my iomplemented function, however, i am not getting the >right delay. I am geting larger delay > > > >Wait1ms > movlw .67 > movwf temp11 >Wait1msB1 > movlw .100 > movwf temp12 >Wait1msB2 > decfsz temp12,1 ; this is one instruction > goto Wait1msB2 ; this is two instructions which make 3 total > decfsz temp11,1 ; the same here > goto Wait1msB1 > return -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics