how to generate square signal with F=10khz using PIC16F84A with a XTAL 4MHZ

MaxHeadRoom

Joined Jul 18, 2013
21,612
Clues: Use Timer 0, the instruction time is 1mhz for a 4mhz clock.
What fraction of a second is 1 cycle at 10Khz.
How much assembly have you done?

Max.
 

R!f@@

Joined Apr 2, 2009
9,734
Code:
; Delay = 1 seconds
; Clock frequency = 4 MHz

; Actual delay = 1 seconds = 1000000 cycles
; Error = 0 %

    cblock
    d1
    d2
    d3
    endc

Delay
            ;999990 cycles
    movlw    0x07
    movwf    d1
    movlw    0x2F
    movwf    d2
    movlw    0x03
    movwf    d3
Delay_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    $+2
    decfsz    d3, f
    goto    Delay_0

            ;6 cycles
    goto    $+1
    goto    $+1
    goto    $+1

            ;4 cycles (including call)
    return
 

R!f@@

Joined Apr 2, 2009
9,734
Code:
; Delay = 2 seconds
; Clock frequency = 4 MHz

; Actual delay = 2 seconds = 2000000 cycles
; Error = 0 %

    cblock
    d1
    d2
    d3
    endc

Delay
            ;1999996 cycles
    movlw    0x11
    movwf    d1
    movlw    0x5D
    movwf    d2
    movlw    0x05
    movwf    d3
Delay_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    $+2
    decfsz    d3, f
    goto    Delay_0

            ;4 cycles (including call)
    return
 

Thread Starter

andrew132

Joined Feb 2, 2017
96
Code:
; Delay = 1 seconds
; Clock frequency = 4 MHz

; Actual delay = 1 seconds = 1000000 cycles
; Error = 0 %

    cblock
    d1
    d2
    d3
    endc

Delay
            ;999990 cycles
    movlw    0x07
    movwf    d1
    movlw    0x2F
    movwf    d2
    movlw    0x03
    movwf    d3
Delay_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    $+2
    decfsz    d3, f
    goto    Delay_0

            ;6 cycles
    goto    $+1
    goto    $+1
    goto    $+1

            ;4 cycles (including call)
    return
can you explain to me how do i calculate how much time the delay will do ? for example i need a 2ms delay
 

R!f@@

Joined Apr 2, 2009
9,734
Code:
; Delay = 2 milli seconds
; Clock frequency = 4 MHz

; Actual delay = 0.002 seconds = 2000 cycles
; Error = 0 %

    cblock
    d1
    d2
    endc

            ;1998 cycles
    movlw    0x8F
    movwf    d1
    movlw    0x02
    movwf    d2
Delay_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    Delay_0

            ;2 cycles
    goto    $+1
 

Thread Starter

andrew132

Joined Feb 2, 2017
96
Clues: Use Timer 0, the instruction time is 1mhz for a 4mhz clock.
What fraction of a second is 1 cycle at 10Khz.
How much assembly have you done?

Max.
i dont know how much cycle the pic will do
i use pic16f84a for leds and switches
and i dont have too much experience in how to generate square signal using a pic16f84a
 
Top