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
'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
'*****
Users browsing this forum: No registered users and 23 guests