CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to produce PWM in 12f675?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

Time travel
PostPosted: Fri Jul 30, 2004 2:38 pm     Reply with quote

Years back, when I used PBP I worked on a few projects that needed variable delays. With the help from some persons on the PICLIST I was able to come up with this. Note that this was compiled from several sources (Andrew Warren, Dwayne Reid come to mind), I redefine it to suit my purposes and commented as much as possible.

Code:

(C)Copyright 2000 LR, compiled from various sources available on PICLIST (A Warren, D Reid, and others)
delayFn            ; This function does the follwing (let delay=x) -> delay = 4*(delay/4)-1+8 = delay + 7cyc
   movf _delay,W      ; Save _delay in W for later use of 2 LSBs

   BCF STATUS,0      ; Divide by four
   RRF _delay      ;
   BCF STATUS,0      ;
   RRF _delay      ;

   ANDLW 3         ; Extract 2 LSBs from original _delay - this number is the same amount of delay we need to
            ;before the 4x-1 loop
   XORLW 3         ; 3 - W = W
   ADDWF PCL      ; Cycles to be added, by incrementing program counter:
   NOP         ; +3 cyc
   NOP         ; +2 cyc
timeLoop   
   NOP         ; +1 cyc & 4 cycle delay loop begin
   DECFSZ _delay      ; +0 cyc
   GOTO timeLoop
;+(_delay + 7)cyc -> total delay


I also did a search on the PICLIST again, and came up with this:

Code:

From Dwayne Reid

;10 bit delay routine providing 1 cycle resolution.  Works with both 12 & 14 bit core PICs.
;Original idea from Mike Harrison.  This version by Dwayne Reid
;
;enters with upper 8 bits of delay in DELAYU, lower 2 bits in bits 1,0 of DELAYL
;bits 7..2 in DELAYL can be used as flags for whatever purpose desired.
;returns with W destroyed
Delay10bit      ;delay is 10 bit value + 7 cycles ( + call + return, if any)
     incf        DELAYU,F        ;correct for dec & test instead of test & dec
Dly10bLoop
     comf        DELAYL,W        ;invert LSBs
     decfsz      DELAYU,F
       goto      Dly10bLoop      ;coarse delay to closest 4 cycles
     andlw       b'00000011'
     addwf       PCL,F
     nop
     nop
     nop
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group