Need help understanding the clocking frequency... not a hard question :)

Status
Not open for further replies.

erospawn

New Member
With the following code, the clocking frequency would be 1Mhz with a 4Mhz clock, correct? If I were using TMR0 with prescaler at 1:2 my oveflow frequency would be 4Khz with a period of 2us?

list P=16f630
#include <p16f630.inc>
__config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CP_OFF

cblock 20h
BH,BL,wait,del_clk1,del_clk2,run,runn,count
endc

RESET_VECTOR CODE 0X000
goto main

main


bsf STATUS,RP0 ;bank 1
call 0x3ff
movwf OSCCAL
movlw 0x00
movwf TRISC ;make all PORTC outputs
movlw 0xfD
movwf TRISA ;make all PORTA inputs
movlw 0x00
movwf OPTION_REG
bcf STATUS,RP0
CLRF TMR0
BCF INTCON,5
movlw 0x07 ;turn off comparitors
movwf CMCON
 
With OPTION_REG cleared, the prescale is 2, but that makes TMR0 overflow at 512 µs if the oscillator is at 4 MHz. That give an overflow frequency of 1953.125 Hz
 
eros, Keep in mind that the calculation is with a preload of 0. If you preload TMR0 with 131 you'll get your 4KHz frequency (250 µs period).
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…