PDA

View Full Version : Code Measure Frequency by TMR1



blinkstar88
- 10th October 2007, 02:59
Anyone have sample code in basic to measure frequency through TMR1?

Any help will appreciated

Thanks

mvs_sarma
- 10th October 2007, 09:44
please try this site
http://www.best-microcontroller-projects.com/pic-frequency-counter.html

blinkstar88
- 11th October 2007, 01:50
Sarma,

Thank for the info, i've download the link. It;s seem look what i want. Unfortunately i'm not familiar with C.

I just need the measure freq via tmr routine section. Its would be great if you can convert it to Basic for me

I will post my routine in the next couple days. I'm working on it.

Cheers

GioppY
- 11th October 2007, 09:58
This works with P16F628 (4MHz)
Interrupt must be disabled
Result 32bit counter Hicntr,Locntr



'
Locntr var word
Hicntr var word
'
'
Freqy:
Hicntr = 0
'tmr1 no gate control, no prescaler, no sync, external clock source, stop tmr1
t1con = %00000110
tmr1l = 0
tmr1h = 0 'clr counter
pir1.0 = 0 'clr tmr1if
asm
movlw 77 ; x 4MHz
movwf r1 ;load 1sec. gate timer
movlw 70
movwf r2
movlw 2
movwf r3
movlw 1
movwf r4
bsf t1con,0 ;start Tmr1
measure
clrwdt ;1
btfss pir1,0 ;1 / 2
goto skkp ;2
bcf pir1,0 ;1
incf _Hicntr,f ;1
btfsc status,z ;1 / 2
incf _Hicntr+1,f ;1
goto precise ;2 9tic
skkp
goto $+1 ;2
goto $+1 ;2
nop ;1 9tic
precise
decfsz r1
goto measure
decfsz r2
goto measure
decfsz r3
goto measure
decfsz r4
goto measure
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
nop
endasm
t1con.0 = 0 'stop tmr1
if pir1.0 = 1 then 'tmr1 overflow ?
Hicntr = Hicntr + 1
endif
Locntr.byte0 = tmr1l
Locntr.byte1 = tmr1h
lcdout $FE,1
lcdout hex4 Hicntr,hex4 Locntr
pause 100
goto freqy
'
'
Regards

vmarvyn
- 19th February 2011, 09:51
hi there
am looking for a source code to implement a frequency comparator on a pic.....can any1 please help me

thnks