Sample Program

Frequency Measuring Program for PF-700


'**************************************************************
'
'  Frequency Measuring Program for PF-700
'
'    2000/11/29 Koichi Hirata
'
'    pf700a.bas
'
'**************************************************************
'
' for AT90S2313-10PC
'
'*********************
' Initial set
'*********************
'
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
Config Lcd = 16 * 2                                           'configure lcd screen
Config Timer1 = Timer , Prescale = 1024                       'Timer1 Setup
Dim A As Byte
Dim B As String * 16
Dim X As Single                                               ' Word
Ddrb = &B11111100
Ddrd = &B00110000
'
'*********************
' First screen
'*********************
'
Cls                                                           'clear the LCD display
Lcd "Freq Counter"                                            'display this at the top line
Lowerline                                                     'select the lower line
Lcd "for PF-700"                                              'display this at the lower line
Wait 1
'
'*********************
' Sencing (Loop)
'*********************
'
Start Timer1                                                  'Start Timer1
Do
   A = 0
   Timer1 = 0
   While A < 4
      If A = 0 And Pinb.0 = 1 Then
        A = 1
        Portd.4 = 1
      End If
      If A = 1 And Pinb.0 = 0 Then
        A = 2
        Timer1 = 0
        Portd.4 = 0
      End If
      If A = 2 And Pinb.0 = 1 Then
        A = 3
        Portd.4 = 1
      End If
      If A = 3 And Pinb.0 = 0 Then
        A = 4
        X = Timer1
        Portd.4 = 0
      End If
      If Timer1 => 50000 Then                                 'Time Over=5 sec
        A = 4
        X = Timer1
      End If
   Wend
'
' Calculation
'
   X = 10000 / X                                              'Frequency (Hz)
   X = X / 2                                                  'For PF-700 (Reduced 1/2 by Bevel gears)
   B = Str(x)
   B = Left(b , 4)
'
' Result screen
'
   Cls
   Home Upper
   Lcd "Freq= "
   Lcd B
   Lcd " Hz"
'   If X =< 0.1 Then
'     Lowerline                                                'select the lower line
'     Lcd "Time Over"
'   End If
   Wait 1
Loop
End

[ Microcomputer ] [ Hirata HOME ] [ Power and Energy Engineering Division ] [ NMRI HOME ]
Contact khirata@nmri.go.jp