Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

'standard' PIC clock freqs?

Status
Not open for further replies.
Before I know the default value of the general purpose registers aren't zero, I didn't clear them and my LCD started with unexpected symbol :D
It seems out of topic :D

Thanks
 
Mike, just a thought. Most new PICs (and soon all new PICs I'm sure) have built in OSC and they all support 4MHz. Can you dynamically switch to the internal clock, do the iButton stuff and back to the user clock?
 
Sure, that would work.

You could also use a generic DelayTcy() subroutine along with a simple DelayUS(microseconds) macro which allows you to specify delays in microseconds and then passes a correctly "scaled" delay parameter to the DelayTcy() subroutine based on your clock speed. Here's an example;

Code:
        radix   dec
;******************************************************************
;                                                                 *
;  DelayUS() Macro                    Mike McLaren, K8LH, Jun'07  *
;                                                                 *
;  simple macro "front end" for a 16-bit DelayTcy() routine that  *
;  allows you to specify delays in 'usecs' instead of 'cycles'.   *
;                                                                 *
;  the 'usec' delay range for a 16-bit target DelayTcy() routine  *
;  is based on clock frequency;                                   *
;                                                                 *
;     4 MHz,  1   cycle /usec, 12..65536 usecs delay              *
;     6 MHz,  1.5 cycles/usec,  8..43690 usecs delay * inprecise  *
;     8 MHz,  2   cycles/usec,  6..32768 usecs delay              *
;    10 MHz,  2.5 cycles/usec,  5..26214 usecs delay * inprecise  *
;    12 MHz,  3   cycles/usec,  4..21845 usecs delay              *
;    16 MHz,  4   cycles/usec,  3..16384 usecs delay              *
;    20 MHz,  5   cycles/usec,  3..13107 usecs delay              *
;    24 MHz,  6   cycles/usec,  2..10922 usecs delay              *
;    28 MHz,  7   cycles/usec,  2.. 9362 usecs delay              *
;    32 MHz,  8   cycles/usec,  2.. 8192 usecs delay              *
;    36 MHz,  9   cycles/usec,  2.. 7281 usecs delay              *
;    40 MHz, 10   cycles/usec,  2.. 6553 usecs delay              *
;    48 MHz, 12   cycles/usec,  1.. 5461 usecs delay              *
;                                                                 *
;  the DelayUS() macro requires the following equate;             *
;                                                                 *
clock   equ   4                 ; see list above
;                                                                 *
;  DelayUS() macro;                                               *
;                                                                 *
DelayUS macro   usecs           ; delay range: see list above
        DelayTcy(usecs*(10000/(4000/clock))/10)
        endm
;                                                                 *
;******************************************************************
;******************************************************************
;                                                                 *
;  DelayTcy(), 12..65547 Tcy          Mike McLaren, K8LH, Jun'07  *
;                                                                 *
;  requires the use of constant operands known at assembly time!  *
;                                                                 *
;  8 words, 1 RAM variable, 16-bit core                           *
;                           ^^^^^^^^^^^                           *
;  the DelayTcy() macro produces four instructions;               *
;                                                                 *
DelayTcy macro  delay           ; parameter range 12..65547
        movlw   high(delay-12)+1
        movwf   TMRH
        movlw   low(delay-12)
        rcall   DelayLo-((delay%3)*2)
        endm
;                                                                 *
;  code for simulation testing;                                   *
;                                                                 *
SimTest
        DelayUS(65000)          ; use the DelayUS() macro, or
;       DelayTcy(100)           ; use the DelayTcy() macro
        nop                     ; put simulator breakpoint here
;                                                                 *
;******************************************************************
;                                                                 *
Delay.18F
        nop                     ; entry point for delay%3 == 2
        nop                     ; entry point for delay%3 == 1
DelayLo                         ; entry point for delay%3 == 0
        addlw   -3              ; subtract 3 cycle loop time
        bc      DelayLo         ;
DelayHi
        addlw   -3              ; subtract 3 cycle loop time
        decfsz  TMRH,F          ; TMRH done? yes, skip, else
        bra     DelayLo         ; loop again
        return                  ;
;                                                                 *
;******************************************************************
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top