12.02.2013, 05:28 PM
Hat zumindest den Vorteil, die Samplefrquenz in großen Teilen einstellen zu können, ohne die Laufzeit "signifikant" zu verändern.
Ich mach das bei meiner Büchse so, ist Basis und nicht optimiert.
Ich mach das bei meiner Büchse so, ist Basis und nicht optimiert.
Code:
$regfile = "m8adef.dat"
$crystal = 8000000
'$lib "lcd4_own.lbx"
$hwstack = 48
$swstack = 64
$framesize = 128
'Config Lcd = 16 * 2
'Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2
Config Timer0 = Timer , Prescale = 1024 'Konfiguriere Timer1
Enable Timer0 'schalte den Timer1 ein
On Timer0 Isr_von_timer0 'verzweige bei Timer1 überlauf zu Isr_von_Timer1
Timer1 = 34285 'Timer1 soll schon von 34285 wegzählen
Config Lcd = 16 * 2 ' , Chipset = Ks077
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2
Config Lcdbus = 4
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Const Adc_multi_voltage = 0.0239995
Const Adc_multi_current = 0.00685
Dim Index As Byte
Dim Value_voltage(64) As Word
Dim Value_current(64) As Word
Dim Average_voltage As Long
Dim Average_voltage_temp As Single
Dim Average_voltage_string As String * 6
Dim First_line_string As String * 8
Dim Second_line_string As String * 8
Dim Average_current As Long
Dim Average_current_temp As Single
Dim Average_power_temp As Single
Dim Average_current_string As String * 6
Dim Average_power_string As String * 6
Dim Timer0_temp As Byte
Dim Timer_temp_toggle As Byte
Dim Display_bit As Bit
Dim Count As Byte
'--------------Main--------------------------
'Double-Init for Slow-Displays
Initlcd
Cls
Cursor Off Noblink
' Spanungsteiler 39k/10k für UMax = 24.5V = 5V
Locate 1 , 1
Lcd "BIERCHEN"
Locate 2 , 1
Lcd "JUNGE!"
Wait 1
Cls
Enable Interrupts
Index = 1
Timer0_temp = 1
Display_bit = 0
Timer_temp_toggle = 1
Do
Disable Interrupts
'Mainloop
Value_current(index) = Getadc(4) 'messen
Value_voltage(index) = Getadc(5) 'messen
Incr Index
Enable Interrupts
If Index = 65 Then
Index = 1
End If
Average_voltage = 0
Average_current = 0
For Count = 1 To 64
Average_voltage = Average_voltage + Value_voltage(count)
Average_current = Average_current + Value_current(count)
Next
Average_voltage_temp = Average_voltage / 64
Average_current_temp = Average_current / 64
If Average_voltage_temp <= 447 Then
Second_line_string = "UNDRVOLT"
' Lcd "Undrvolt" '10,7V
Elseif Average_voltage_temp <= 472 Then
Second_line_string = "PWR LOW "
' Lcd "Pwr low " '11,3V
Elseif Average_voltage_temp >= 836 Then
Second_line_string = "OVERVOLT"
' Lcd "Overvolt" '20V
Else
Average_current_temp = Average_current_temp * Adc_multi_current
Average_current_string = Fusing(average_current_temp , "##.##")
Second_line_string = " " + Average_current_string
End If
Average_voltage_temp = Average_voltage_temp * Adc_multi_voltage
Average_voltage_string = Fusing(average_voltage_temp , "##.##")
First_line_string = " " + Average_voltage_string + " V "
Average_power_temp = Average_voltage_temp * Average_current_temp
Average_power_string = Fusing(average_power_temp , "##.##")
'Waitms 10
Loop
Isr_von_timer0:
Incr Timer0_temp
If Timer0_temp = 6 Then
Timer0_temp = 1
If Timer_temp_toggle >= 50 Then
Toggle Display_bit
Timer_temp_toggle = 1
End If
If Display_bit = 1 Then
Locate 1 , 1
Lcd First_line_string
Locate 2 , 8
Lcd "A"
Locate 2 , 1
Lcd Second_line_string
Incr Timer_temp_toggle
Else
Locate 1 , 1
' Lcd "POWER "
Lcd First_line_string
Locate 2 , 1
Lcd " " ; Average_power_string ; " "
Locate 2 , 8
Lcd "W"
Incr Timer_temp_toggle
Incr Timer_temp_toggle
End If
End If
Return