PDA

View Full Version : Frequency counter-- old project revisit



Vivena
- 27th October 2014, 23:31
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

Archangel
- 28th October 2014, 05:50
Your code looks to be Proton, this forum is M E Labs P basic Pro.

Vivena
- 28th October 2014, 07:22
Archangel
Yes.. But let's put that aside for a moment

If I look at this thread here: http://www.picbasic.co.uk/forum/showthread.php?t=1137

There are three port pins that I'm using in this circuit: http://paulfjujo.free.fr/FREQ/images/weedfreq.jpg, would it then mean I would have to declare 3 pins for use of which portA4 is the input?

Best
Vivena

mark_s
- 28th October 2014, 15:09
Hi, I have tried both of your examples or links.

The first one you only need to input the frequency on the T1CLK pin. Basically you clear timer 1, start tmr1
then pause for 10ms, 100ms or 1s then stop timer1. Read the contents of TMR1L and TMR1H which is your frequency. This method is not very accurate using a pause statement for your time base.

The second, this circuit was designed and sold as a kit by Terry Weeder many years ago. It used the RTCC with a elaborate scheme to gate the input pin on and off then pulsed the rtcc 256 time to purge the result or remainder. This was a very stable and accurate. This used three pins, freq in, gate and purge


http://www.piclist.com/techref/piclist/weedfreq.htm

So to answer your question the code in your first post will not work with the Weeder schematic. There is no timer1 in a pic1684. I started porting the assembly code to PBP at one time, but never finished. Look for the hex file for the pic16f84 and just program a new chip.

Vivena
- 28th October 2014, 17:48
Hello MarK_S
Thank you for the simple explanation. I see the goof-up, I forgot to see the pins involved and assumed that the 16F628 would be good as the other, no wonder I went round in circles.
Thanks for setting me in the correct direction, I will try and read the 16F84A details and see what I can achieve..

I was trying to use Ero's code for a 16F628 unwittingly for a circuit that had a 16F84... whoops..

Thanks once again..

Vivena

Archangel
- 28th October 2014, 22:54
The real issue in using a 628/628A in place of 16F84 is that the 628 has comparator inputs which have to be disabled, otherwise very similar chips, if you have a hex file then go buy a 16f84 and call it good.