I have been trying to understand the code for a frequency counter as I would like to build one. After searching for several days I have read this thread http://www.picbasic.co.uk/forum/showthread.php?t=1137.
Ero's code is well explained but I'm missing the plot here. I am a new person to Microchip and I'm trying to learn desperately hard.
I have several questions, I am using this circuit: http://paulfjujo.free.fr/FREQ/images/weedfreq.jpg
From Ero's code I understand that the pins are different. I have been gifted the PCBs for the frequency counter and so I'm really trying hard to make them work.
I am not sure if the problem is that I have not put the transistor buffer amplifier in the circuit and I'm feeding the output direct to pin 1 of the 74HCT132.
I am putting the code here, can you please help? As you can see I make several mistakes.
Thank you for your time.
Vivena
---------
PS: I understand this is picbasic forum and the code I'm trying to port is to protonbasic which I've studied trouble is should I switch to the picbasic then I will have to buy the compiler again?
'Name : Frekans-628.BAS *
'Author : [Erol ERDAL) *
;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings
Device = 16F628A
Config FOSC_XT, WDTE_OFF, PWRTE_ON, MCLRE_ON, BOREN_ON, LVP_OFF, CPD_OFF, CP_OFF
;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
Xtal 4
DEFINE OSC 4
Declare LCD_Type 0 ' Type of LCD Used is Alpha
Declare LCD_DTPin PORTB.0
Declare LCD_RSPin PORTA.2 ' Register Select pin on A2
Declare LCD_ENPin PORTA.0 ' Enable pin on A0
Declare LCD_RWPin PORTA.1 ' Read/Write Pin is Port A1
Declare LCD_Interface 8 ' Interface method is 8 bits in this case
Declare LCD_Lines 2
Declare LCD_CommandUs 4000
Declare LCD_DataUs 250
TRISA= 001000
TRISB = 00000
All_Digital True
Symbol TESTLED = PORTA.1
Dim fout As Word
Dim foutL As fout.Byte0
Dim foutHH As fout.Byte1 ' FoutH causing duplicate
Dim Mode As Byte
Dim Delay As Word
Dim Delay_Us As Word
Dim x As Word
Dim tenth As Byte
Dim Z As Bit
'-------------------------------------------------------------------
Z=0
CMCON=7
Mode=0
'************************* Main***************************
Cls
START:
GoSub TUS 'this is for mode select
Select Case Mode
Case 0
Delay=1000; Delay_Us=400
GoSub OLC
Lcdout $FE,$1,"0-65 KHz : MOD=",Dec Mode
Lcdout $FE,$C0,#fout," Hz": PAUSE 100
'Print 2,1, Dec fout
GoTo START
Case 1
Delay_Us=100; Delay=100
GoSub OLC :fout=fout/100
Lcdout $FE,1,"65-650KHz: MOD=",Dec Mode
Lcdout $FE,$C0,#fout," KHz": PAUSE 100
GoTo START
Case 2
Delay_Us=996; Delay=9
GoSub OLC:fout=fout/10:tenth=(fout//1000)/10
Lcdout $FE,1,"650-6,5MHz:MOD=", Dec Mode
Lcdout $FE,$C0,#fout/1000,",",#tenth," MHz": PAUSE 100
GoTo START
Case 3
Delay_Us=992; Delay=0
GoSub OLC:tenth=(fout//1000)/10:fout=fout/1000
Lcdout $FE,1,"6,5-30 MHz:MOD=" ,Dec Mode
Lcdout $FE,$C0,#fout,",",#tenth," MHz": PAUSE 100
GoTo START
End Select
Z=0
GoTo START
End
TUS:
PAUSE 70:
If PORTA.4=1 Then
If Z=1 Then CIK
Mode=Mode+1: Pause 10
If Mode=4 Then Mode=0
Z=1
Return
EndIf
Z=0
CIK:
Return
' ---------------frequency counting ------------------------------------
OLC:
If PORTA.3=0 Then
x=x+1
If x>(Delay+Delay_Us) Then Return
EndIf
TMR1L=0
TMR1H=0
T1CON=7
pause Delay
pauseus Delay_Us
T1CON=6
foutL=TMR1L
foutHH=TMR1H
Return
Bookmarks