|
|
|
Sample Program
'**************************************************************
'
' Frequency and Electric Power Measuring Program for PF-700
'
' 2000/11/30 Koichi Hirata
'
' pf700d.bas
'
'**************************************************************
'
' for AT90S8535-8PC
'
'*********************
' 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
Config Adc = Single , Prescaler = Auto 'For A/D conv.
Start Adc
Dim A As Byte
Dim B As String * 16
Dim X As Single
Dim Vv0 As Word
Dim Vv1 As Word
Dim V0 As Single
Dim V1 As Single
Dim Vm As Single
Dim We As Single
Dim B0 As String * 16
Dim B1 As String * 16
Ddrb = &B11111100
Ddrd = &B00110000
'
'*********************
' First screen
'*********************
'
Cls 'clear the LCD display
Lcd "Measuring Prog." '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)
'*********************
'
' Timer for frequency
'
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 => 20000 Then 'Time Over = about 2 sec
A = 4
X = Timer1
End If
Wend
'
' Read A/D value
'
Vv0 = 0
Vv1 = 0
For A = 1 To 50
Vv0 = Vv0 + Getadc(1) 'read A/D value from channel 1
Vv1 = Vv1 + Getadc(2) 'read A/D value from channel 2
Waitms 5
Next A
Vv0 = Vv0 / 50
Vv1 = Vv1 / 50
'
' Calculation for ferequency
'
X = 8000 / X 'Frequency (Hz)
X = X / 2 'For PF-700 (Reduced 1/2 by Bevel gears)
B = Str(x)
B = Left(b , 4)
'
' Calculation for A/D
'
V0 = Vv0 * 5
V0 = V0 / 1024 'Voltage (V)
V1 = Vv1 * 5
V1 = V1 / 1024 'Voltage (V)
Vm = 2 * V0
Vm = Vm - V1 'Voltage (V) of D/C motor for PF-700
We = 2 * V1 'Electric current (A) for PF-700
We = We * Vm 'Electric power of D/C motor for PF-700
B0 = Str(vm)
B0 = Left(b0 , 4)
V1 = V1 * 2
B1 = Str(we)
B1 = Left(b1 , 4)
'
' Result screen
'
Cls
Home Upper
Lcd "Freq= "
Lcd B
Lcd " Hz"
Lowerline 'select the lower line
Lcd B0
Lcd " V x "
Lcd B1
Lcd " W "
Wait 1
Loop
End
|
|
[ Microcomputer ] [ Hirata HOME ] [ Power and Energy Engineering Division ] [ NMRI HOME ] |
|
|
| Contact khirata@nmri.go.jp |