How to make frequency meter res. 0.1 Hz

Sezione dedicata al sistema di sviluppo BASCOM-AVR per i micro AVR
At90s, Attiny, Atmega e Xmega

How to make frequency meter res. 0.1 Hz

Postby heri » 12 Aug 2011, 16:40

Hi All,
Can everyone help me?
How to make Frequency meter 0-100 Hz with resolution 0.1 Hz in Bascom AVR ?
Please give me the sample code for it ?
Thnks
heri
 
Posts: 1
Joined: 12 Aug 2011, 13:46

Re: How to make frequency meter res. 0.1 Hz

Postby tubincolo » 18 Aug 2011, 20:11

Maybe the following will help you.
Tested with an Atmega168 but can be adapted to almost any mcu.
When you measure the very low frequency (0.01) then the wait is of course 100 seconds after the first high to low, that could be up to 200 seconds before you see the result!
Will also post in the shared code section of the forum.

Code: Select all
'FREQUENCY METER FOR A RANGE OF 100 HZ TO 0.01 HZ (and a bit higher)
$regfile = "m168def.dat" 'MICRO
$crystal = 8000000 'INTERNAL 8 MHZ CLOCK
$baud = 115200 'BAUD RATE
$hwstack = 64
$swstack = 64
$framesize = 64
Config Timer2 = Timer , Prescale = 1
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portb.0 , Rs = Portb.1
Config Lcd = 16 * 2
'OR USE PRINT INSTEAD OF LCD
Dim Cycle_status As Byte
Dim Countvar1 As Long 'CONTINUING COUNT
Dim Countvar2 As Long 'VALUE FOR CALC. DISPLAY
Dim Divi As Long
Divi = 40750 'USE TO CALCULATE FREQUENCY
Dim Frequ As Single
Dim Tim1_count As Word
Cycle_status = 1
'OR USE PINCHANGE INTERRUPT ON OTHER PINS WITH THE DIVISION CHANGED
Config Portd.2 = Input 'FREQUENCY INPUT
Portd.2 = 1 'PULL UP RESISTOR ON
Config Int0 = Falling 'RISING EDGE OF PULSE
On Timer2 Lcount_isr 'LOOP COUNTER
On Int0 Status_update_isr 'STATUS OF CYCLE
Enable Timer2 'USE AS COUNTER
Enable Int0
Enable Interrupts
'*******
Cls
Timer1 = 0
Do
Frequ = Divi \ Countvar2
Locate 1 , 1
Lcd Fusing(frequ , "#.##") ; " Hz " 'USE LCD OR PRINT
Loop
End 'end program
'******* ISR ROUTINES ********
Lcount_isr: 'TIMER2 OVERFLOW INT
If Cycle_status = 0 Then Incr Countvar1
Timer2 = 155
Return
'***
Status_update_isr: 'INT0 FROM FREQUENCY INPUT
If Cycle_status = 0 Then
Countvar2 = Countvar1
Countvar1 = 0
Cycle_status = 1
Else
Cycle_status = 0
Countvar1 = 0
End If
Return
'*****
tubincolo
 
Posts: 18
Joined: 19 Jun 2011, 11:16


Return to BASCOM-AVR

Who is online

Users browsing this forum: No registered users and 19 guests

cron