Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] frequency counter in picbasic

Status
Not open for further replies.

leemarrow

Full Member level 3
Joined
May 3, 2001
Messages
174
Helped
11
Reputation
22
Reaction score
9
Trophy points
1,298
Activity points
985
picbasic frequency counter

Hi,
someone have developped a picbasic program for frequency counter pic based?
 

picbasic counter

Hi !

Yeah ! It is possible to do with PBP, but you will have some restrictions and depends on the range of frequency to be measured.
You can use the command COUNT to measure signals (digital) entering in a pin up to 25kHz (4MHz PIC). Note that the PIC will be waiting the time specified within the line command, counting the pulses.
Other way is to measure the width or the period of the signal with the command PULSEIN and make some calculation to find frequency (f = 1/T)
Another way is using the timers and prescalers (enabled by basic commands) to count the signal pulses.
 

frequency counter picbasic

hi:
you can use timer1 in pic16f627 or16f628 in counter mode with prescale
1024 so you can measure frequency to 50MHZ
REGARD
 

pic16f627 frequency counter

Hi Leemarrow

There is an app on Basic Stamp:

File...... SHOWFREQ.BS2
Purpose... Displays input frequency


**broken link removed** that contains
article + code

**broken link removed**

Stamp Basic can be converted into PicBasic, I think at Melabs is some doc
about that also check the Picbasic manual.

Regards
Tornado
 

picbasic count signal

In PBP you can using command COUNT for counting frequency
with 4 MHz crytal you can counting 25KHz and 20Mhz for 125KHz. if input signal you through a circuit devide frequency example div 100 or before you put it a pin on MCS PIC you can counting range into MHz.
see my code in PBP for data display on LCD with sumulation in Proteus
Have fun!
 

picbasic rpm

what ver. of proteus are you using i can't read the file.
 

picbasic counter with lcd

i have developed a freq counter based on the same concept but using ccs c.....it works...if u need any information on tat msg me i ll be happy to help..... any way it works till 67Mhz
 

basic stamp frequency counter

the project is good than you
 

frequency counter proteus

matelda said:
hi:
you can use timer1 in pic16f627 or16f628 in counter mode with prescale
1024 so you can measure frequency to 50MHZ
REGARD
Can you post some code;
 

frequency counter pic basic

HERE IS THE CODE THAT MEASURES FREQUNCY AND RPM AS WELL


'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : SYED AYAZ AHMED *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 2/7/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
Device 16F870
'BOOTLOADER On
XTAL 20
Declare WATCHDOG TRUE

'Config CPD_ON, CP_ALL
Declare LCD_TYPE 0
Declare LCD_DTPIN PORTC.0
Declare LCD_RSPIN PORTC.4
Declare LCD_ENPIN PORTC.5
Declare LCD_LINES 2

' ** Declare the flags of the INTCON register **
Symbol RBIF = INTCON.0 ' RB Port Interrupt Flag
Symbol INT0IF = INTCON.1 ' RB0 External Interrupt Flag
Symbol TMR0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
Symbol RBIE = INTCON.3 ' RB Port Change Interrupt Enable
Symbol INT0IE = INTCON.4 ' RB0 External Interrupt Enable
Symbol PEIE = INTCON.6 ' Peripheral Interrupt Enable
Symbol GIE = INTCON.7 ' Global Interrupt Enable
Symbol T0IF = INTCON.2 ' Timer0 Overflow Interrupt Flag

Symbol LED_PORT = PORTB.7
'
DelayMS 200
Cls
ALL_DIGITAL=true
PORTB_PULLUPS=true
TRISB = %00000001 ' Set bit 2-7 to outputs, bit 0 input
Symbol Tmr0ReloadVal = 100 ;256 - 200

Symbol RPM_In = PORTB.0

Dim DISPVAL As DWord
Dim Hz2Counter As DWord
Dim FREQ As DWord
Dim RPMRaw As DWord
Dim DLY As Byte
Dim ONES As Byte
Dim TENS As Byte
Dim HUNDREDS As Byte
Dim THOUSANDS As Byte

Dim TIMESHARE As Byte ' Used by the interrupt for time sharing
Dim RefreshReq As Bit


' Set TMR0 to interrupt on rollover
OPTION_REG = %00000100 ' Set the prescaler to 1:32
INTCON = %11110000 ' Enable TMR0 overflow interrupt and ' Assign TMR0 clock to internal source and interrupt on RB0
TMR0 = Tmr0ReloadVal

; While GIE = 1 : GIE = 0 : Wend ' Make sure global interrupts are off


Clear
Input RPM_In


'
GoTo OVER_SUBS ' Jump over the subroutine
'
On_Interrupt GoTo MULT_INT ' Point to the interrupt handler and ENABLE global interrupts
'---------------------------------------------------------------------------------------
' INTERRUPT HANDLER



MULT_INT:
If INT0IF = 1 Then ' If we have an interrupt from INT0 then we have an RPM pulse
Inc RPMRaw ' so up our interrupt counter
Clear INT0IF ' Clear the interrupt flag now
GoTo IntExit ' exit
EndIf

If T0IF = 1 Then
TMR0 = TMR0 + Tmr0ReloadVal ' reload with the nearest we can get to 1ms interrupts
Else
GoTo IntExit ' not a INT0 interrupt? Bad thing but better exit anycase
EndIf

Inc Hz2Counter ' Every 1 of a second we will read the FREQUENCY
If Hz2Counter = 1000 Then
LED_PORT = LED_PORT ^ 1
FREQ = RPMRaw
RPMRaw = 0
Hz2Counter = 0
RefreshReq = 1
EndIf
Clear T0IF ' Reset TMR0 interrupt flag
IntExit:
Context Restore ' Exit the interrupt

'---------------------------------------------------
OVER_SUBS:

While 1 = 1
If RefreshReq >= 1 Then
DISPVAL = FREQ * 60 ' Do the maths to convert it to RPM
'GoSub Build_Digits
Toggle LED_PORT 'TO MAKE ENSURE PIC IS RUNING
Print At 1,1,Dec DISPVAL," RPM "
Print At 2,1,Dec FREQ," Hz "

RefreshReq = 0

EndIf
Wend
 
picbasic manual

Thank you.
I will test
 

ccs c frequency meter

Can you post the circuit;
 

pic basic flag

i have omitted necessary connection like resonator/crystal,LCD supply and contrast
 

Re: pic basic flag

akvii said:
i have omitted necessary connection like resonator/crystal,LCD supply and contrast

Hi,

I would like to know what the maximum FQ this setup will read?

best regards,
S.
 

i have tested it on 500KHz and its working fine....theoretically it should work on atleast 2MHz,provided if 20MHz crystal is used for PIC
 

500V what...is it AC or DC???
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top