EDatabaseError
18.03.2007, 14:38
Ich habe hier dieses Programm. Das ganze ist in einer Hardware eingebunden. Nur nach einiger Zeit die der Chip läuft, beginnt das Programm von vorn. (es wird print start ausgelöst)
Man kann sich das so vorstellen:
-> Chip bekommt strom und läuft los
-> Print "start"
-> Warte einige Zeit
-> Print "start"
...
Warum ist das so?
Mfg
Tobi
[Bitte helft mir, es ist sehr von Bedeutung]
'--- [ Init ] ------------------------------------------------------------------
Dim Emin As Eram Word At 0 '0 Wert
Dim Emax As Eram Word At 2 'Max. Wert
Dim Estrecke As Word 'Einheiten Strecke
Dim Sstab As Eram Word At 4 'Abstand zwischen 0 und Max in mm
Dim Offset As Eram Word At 6 'Offset
Const Datensaetze = 42
Dim Volhigh As Eram Word At 8
Dim Volmiddle As Eram Word At 10
Dim Vollow As Eram Word At 12
'--- [ Write into eram - only run the first time! ] ----------------------------
Emin = 0
Emax = 1000
Estrecke = Emax - Emin
Sstab = 2000
Offset = 50
Volhigh = 500
Volmiddle = 800
Vollow = 1500
'--- [ Inizialize compiler ] ---------------------------------------------------
$regfile = "m168def.dat" 'Set chip AVR mega168
$crystal = 16000000 'Set crystal 16 MHz
$baud = 9600 'Set Baudrate 9600
$framesize = 32 'Framesize = 32
$swstack = 32 'SW = 32
$hwstack = 32 'HW = 32
Print "start"
'--- [ Config devices and timers ] ---------------------------------------------
Config Adc = Single , Prescaler = Auto , Reference = Avcc 'Config ADC
Sens Alias Pinc.0 'Setze PINC.0 als Sensor Eingang
Config Pind.6 = Output 'OC0A / Motor PWM
Pwm_out Alias Pind.6
Config Portc.1 = Output 'Direction A
Dira Alias Portc.1
Config Portc.2 = Output 'Direction B
Dirb Alias Portc.2
Audio Alias Portb.5 'Audio Ausgang
Config Pinc.3 = Input 'Start Interrupt / Druckschalter
Inp_start Alias Pinc.3
Config Pind.7 = Input 'Libellen Interrupt
Inp_libelle Alias Pind.7
Config Portb.0 = Output 'ROT
Led_red Alias Portb.0
Config Portb.1 = Output 'GELB
Led_yellow Alias Portb.1
Config Portb.2 = Output 'GRUEN
Led_green Alias Portd.3
Inp_stop Alias Pind.2 'Stop Interrupt!
'Timer0 as PWM for engine
Tccr0a = &B11000001
Tccr0b = &B00000001
Tcnt0 = &B00000000
Timsk0 = &B00000000
Tifr0 = &B00000000
Ocr0a = 255
'Timer1 as clock for time
Config Timer1 = Timer , Prescale = 256
Const Clock = 3036
'--- [ Declare SUBs ] ----------------------------------------------------------
Declare Sub Snd(byval Freq As Word)
'--- [ Declare variables ] -----------------------------------------------------
Dim Daten(datensaetze) As String * 19 'Messdaten
Dim Is_ok As Word 'Wert ab dem die Messung OK ist
Dim Soll As Word 'Sollwert
Dim Ist As Integer 'Ist Position
Dim Hits As Word 'Anschläge
Dim Libelle As Bit 'Libelle
Dim Buffer As String * 8 'RS232 Buffer
Dim Year As Integer 'Jahr
Dim Month As Byte 'Monat
Dim Day As Byte 'Tag
Dim Hour As Byte 'Stunde
Dim Minute As Byte 'Minute
Dim Second As Byte 'Sekunde
Dim Tresult As String * 5 'Zeitstring
Dim Dresult As String * 8 'Datumstring
Dim B1 As Byte 'HV
Dim W1 As Word 'HV
Dim W2 As Word 'HV
Dim I1 As Integer 'HV
Dim I2 As Integer 'HV
Dim S1 As String * 1 'HV
Dim S2 As String * 1 'HV
Dim Start_setted As Bit 'S_HV
Dim After_back As Bit 'S_HV
'--- [ Inizialize variables and constants ] ------------------------------------
Start_setted = 0
After_back = 0
Is_ok = 0
'Soll = 0
'Print Soll ; " on init"
Ist = 0
Hits = 0
Libelle = 0
Buffer = ""
Year = 2000
Month = 1
Day = 1
Hour = 0
Minute = 0
Second = 0
Tresult = ""
Dresult = ""
'--- [ Inizialize Interrupts ] -------------------------------------------------
Sreg.7 = 0
On Int0 Isr_stop 'On Rising Edge
On Pcint1 Isr_start
On Pcint2 Isr_libelle
On Timer1 Isr_clock 'On Timer1
On Urxc Isr_data 'On Urxc
Eicra = &B00000011
Eimsk = &B00000001
Eifr = &B00000001
Pcicr = &B00000110
Pcifr = &B00000110
Pcmsk2 = &B10000000
Pcmsk1 = &B00001000
Pcmsk0 = &B00000000
Enable Timer1
Enable Urxc
Sreg.7 = 1
'--- [ Start secuence ] --------------------------------------------------------
Echo Off
Gosub Clrdata
Dira = 0
Dirb = 0
Ocr0a = 255
Portc.0 = 0
Start Adc
'--- [ Main loop ] -------------------------------------------------------------
Do
Ist = Getadc(0)
If Soll <= Emax Then
W1 = Soll - Offset
If W1 > Ist Then
Dira = 1
Dirb = 0
Ocr0a = 0
End If
W1 = Soll + Offset
If W1 < Ist Then
Dira = 0
Dirb = 1
Ocr0a = 0
End If
W1 = Soll - Offset
W2 = Soll + Offset
If W1 <= Ist Then
If W2 >= Ist Then
Ocr0a = 255
Dira = 0
Dirb = 0
'If Ist >= W1 Then Soll = Emin
If After_back = 1 Then
After_back = 0
Soll = Emax
Print Soll ; " on afterback"
End If
End If
End If
Else
Ocr0a = 255
Dira = 0
Dirb = 0
Sreg.7 = 0
End If
Loop
End
'--- [ Interrupt service routine ] ---------------------------------------------
Isr_stop:
Incr Hits
If Inp_stop = 1 Then Print "STOP 1"
if inp_stop = 0 then print "STOP 0"
If Ist >= Is_ok Then
Gosub Savedata
Soll = Emin
Print Soll ; " on stop_ok"
Else
If Hits = 3 Then
Gosub Savedata
Soll = Emin
Print Soll ; " on stop_3hits"
End If
If Hits < 3 Then
I1 = Ist - 500
If I1 < 0 Then I1 = 0
Soll = I1
Print Soll ; " on stop_hit"
After_back = 1
End If
End If
Return
Isr_start:
If Inp_start = 1 Then Print "START 1"
If Inp_start = 0 Then Print "START 0"
If Inp_start = 0 Then
Start_setted = 1
End If
If Inp_start = 1 Then
If Start_setted = 1 Then
Start_setted = 0
Soll = Emax
Print Soll ; " on start"
End If
End If
Return
Isr_libelle:
If Inp_libelle = 1 Then Print "LIBELLE 1"
If Inp_libelle = 0 Then Print "LIBELLE 0"
If Inp_libelle = 0 Then
Libelle = 1
End If
Return
Isr_data:
B1 = Udr
If Chr(b1) = "!" Then
Soll = 3333
Print Soll ; " on !"
End If
If Chr(b1) = "]" Then
Print Buffer
Gosub Rs232
End If
Buffer = Buffer + Chr(b1)
If Chr(b1) = "[" Then
Buffer = ""
End If
Return
Isr_clock:
Timer1 = Clock
Second = Second + 1
If Second = 60 Then Gosub Addminute
If Minute = 60 Then Gosub Addhour
If Hour = 24 Then Gosub Addday
If Day = 31 Then
Select Case Month
Case 1 : Gosub Addmonth
Case 3 : Gosub Addmonth
Case 5 : Gosub Addmonth
Case 7 : Gosub Addmonth
Case 8 : Gosub Addmonth
Case 10 : Gosub Addmonth
Case 12 : Gosub Addmonth
End Select
End If
If Day = 30 Then
Select Case Month
Case 2 : Gosub Addmonth
Case 4 : Gosub Addmonth
Case 6 : Gosub Addmonth
Case 9 : Gosub Addmonth
Case 11 : Gosub Addmonth
End Select
End If
If Month = 12 Then Gosub Addyear
Tresult = Format(hour , "00") + ":" + Format(minute , "00")
Dresult = Format(year , "00") + "." + Format(month , "00") + "." + Format(day , "00")
Print Soll ; " :: " ; Ist
Return
'--- [ SUBs and functions ] ----------------------------------------------------
Sub Snd(byval Freq As Word)
Sound Audio , 200 , Freq
End Sub
'--- [ GOSUBs ] ----------------------------------------------------------------
Savedata:
For I2 = 0 To Datensaetze
If Daten(i2) = "" Then
Exit For
End If
Next I2
If Hits >= 3 Then S1 = "0" Else S1 = "1"
If Libelle = 1 Then S2 = "0" Else S2 = "1"
Daten(i2) = S1 + "§" + S2 + "§" + Str(soll) + "§" + Str(ist) + "§" + Dresult + "§" + Tresult
Print "DATEN" ; I2
Print Daten(i2)
Hits = 0
Libelle = 0
After_back = 0
Start_setted = 0
Return
Clrdata:
For I2 = 0 To Datensaetze
Daten(i2) = ""
Next I
Return
Addminute:
Minute = Minute + 1
Second = 0
Return
Addhour:
Hour = Hour + 1
Minute = 0
Return
Addday:
Day = Day + 1
Hour = 0
Return
Addmonth:
Month = Month + 1
Day = 0
Return
Addyear:
Year = Year + 1
Month = 0
Return
Rs232:
If Buffer = "CLR" Then
Gosub Clrdata
Print "<EXIT>"
End If
If Instr(buffer , "YR") > 0 Then
Buffer = Right(buffer , 4)
Year = Val(buffer)
End If
If Instr(buffer , "MN") > 0 Then
Buffer = Right(buffer , 2)
Month = Val(buffer)
End If
If Instr(buffer , "DA") > 0 Then
Buffer = Right(buffer , 2)
Day = Val(buffer)
End If
If Instr(buffer , "HR") > 0 Then
Buffer = Right(buffer , 2)
Hour = Val(buffer)
End If
If Instr(buffer , "MI") > 0 Then
Buffer = Right(buffer , 2)
Minute = Val(buffer)
End If
If Instr(buffer , "SC") > 0 Then
Buffer = Right(buffer , 2)
Second = Val(buffer)
Print "<EXIT>"
End If
If Instr(buffer , "SL") > 0 Then
Buffer = Right(buffer , 3)
Is_ok = Val(buffer)
Is_ok = Is_ok * 1
Print "<EXIT>"
End If
If Instr(buffer , "EI") > 0 Then
Buffer = Right(buffer , 4)
End If
If Instr(buffer , "EA") > 0 Then
End If
If Instr(buffer , "OF") > 0 Then
End If
If Instr(buffer , "FA") > 0 Then
End If
If Instr(buffer , "FB") > 0 Then
End If
If Instr(buffer , "FC") > 0 Then
End If
If Buffer = "GDA" Then
End If
If Buffer = "SND" Then
If Daten(1) = "" Then
Else
For I1 = 0 To Datensaetze
If Daten(i1) = "" Then
Exit For
End If
Print "<" ; I1 ; "§" ; Daten(i1) ; ">"
Waitms 10
Next I1
End If
Print "<EXIT>"
End If
If Buffer = "FWD" Then
Soll = Emax
Print Soll ; " on FWD"
End If
If Buffer = "BWD" Then
Soll = Emin
Print Soll ; " on BWD"
End If
If Buffer = "STP" Then
Soll = 3333
Print Soll ; " on STP"
End If
If Buffer = "GIN" Then
Print "<4%Position: " ; Ist ; ">"
End If
If Buffer = "GTI" Then
Print "<3%" ; Tresult ; ">"
Print "<3%" ; Dresult ; ">"
End If
If Buffer = "ABP" Then
Call Snd(volhigh)
Waitms 10
Call Snd(volmiddle)
Waitms 10
Call Snd(vollow)
End If
Return
Man kann sich das so vorstellen:
-> Chip bekommt strom und läuft los
-> Print "start"
-> Warte einige Zeit
-> Print "start"
...
Warum ist das so?
Mfg
Tobi
[Bitte helft mir, es ist sehr von Bedeutung]
'--- [ Init ] ------------------------------------------------------------------
Dim Emin As Eram Word At 0 '0 Wert
Dim Emax As Eram Word At 2 'Max. Wert
Dim Estrecke As Word 'Einheiten Strecke
Dim Sstab As Eram Word At 4 'Abstand zwischen 0 und Max in mm
Dim Offset As Eram Word At 6 'Offset
Const Datensaetze = 42
Dim Volhigh As Eram Word At 8
Dim Volmiddle As Eram Word At 10
Dim Vollow As Eram Word At 12
'--- [ Write into eram - only run the first time! ] ----------------------------
Emin = 0
Emax = 1000
Estrecke = Emax - Emin
Sstab = 2000
Offset = 50
Volhigh = 500
Volmiddle = 800
Vollow = 1500
'--- [ Inizialize compiler ] ---------------------------------------------------
$regfile = "m168def.dat" 'Set chip AVR mega168
$crystal = 16000000 'Set crystal 16 MHz
$baud = 9600 'Set Baudrate 9600
$framesize = 32 'Framesize = 32
$swstack = 32 'SW = 32
$hwstack = 32 'HW = 32
Print "start"
'--- [ Config devices and timers ] ---------------------------------------------
Config Adc = Single , Prescaler = Auto , Reference = Avcc 'Config ADC
Sens Alias Pinc.0 'Setze PINC.0 als Sensor Eingang
Config Pind.6 = Output 'OC0A / Motor PWM
Pwm_out Alias Pind.6
Config Portc.1 = Output 'Direction A
Dira Alias Portc.1
Config Portc.2 = Output 'Direction B
Dirb Alias Portc.2
Audio Alias Portb.5 'Audio Ausgang
Config Pinc.3 = Input 'Start Interrupt / Druckschalter
Inp_start Alias Pinc.3
Config Pind.7 = Input 'Libellen Interrupt
Inp_libelle Alias Pind.7
Config Portb.0 = Output 'ROT
Led_red Alias Portb.0
Config Portb.1 = Output 'GELB
Led_yellow Alias Portb.1
Config Portb.2 = Output 'GRUEN
Led_green Alias Portd.3
Inp_stop Alias Pind.2 'Stop Interrupt!
'Timer0 as PWM for engine
Tccr0a = &B11000001
Tccr0b = &B00000001
Tcnt0 = &B00000000
Timsk0 = &B00000000
Tifr0 = &B00000000
Ocr0a = 255
'Timer1 as clock for time
Config Timer1 = Timer , Prescale = 256
Const Clock = 3036
'--- [ Declare SUBs ] ----------------------------------------------------------
Declare Sub Snd(byval Freq As Word)
'--- [ Declare variables ] -----------------------------------------------------
Dim Daten(datensaetze) As String * 19 'Messdaten
Dim Is_ok As Word 'Wert ab dem die Messung OK ist
Dim Soll As Word 'Sollwert
Dim Ist As Integer 'Ist Position
Dim Hits As Word 'Anschläge
Dim Libelle As Bit 'Libelle
Dim Buffer As String * 8 'RS232 Buffer
Dim Year As Integer 'Jahr
Dim Month As Byte 'Monat
Dim Day As Byte 'Tag
Dim Hour As Byte 'Stunde
Dim Minute As Byte 'Minute
Dim Second As Byte 'Sekunde
Dim Tresult As String * 5 'Zeitstring
Dim Dresult As String * 8 'Datumstring
Dim B1 As Byte 'HV
Dim W1 As Word 'HV
Dim W2 As Word 'HV
Dim I1 As Integer 'HV
Dim I2 As Integer 'HV
Dim S1 As String * 1 'HV
Dim S2 As String * 1 'HV
Dim Start_setted As Bit 'S_HV
Dim After_back As Bit 'S_HV
'--- [ Inizialize variables and constants ] ------------------------------------
Start_setted = 0
After_back = 0
Is_ok = 0
'Soll = 0
'Print Soll ; " on init"
Ist = 0
Hits = 0
Libelle = 0
Buffer = ""
Year = 2000
Month = 1
Day = 1
Hour = 0
Minute = 0
Second = 0
Tresult = ""
Dresult = ""
'--- [ Inizialize Interrupts ] -------------------------------------------------
Sreg.7 = 0
On Int0 Isr_stop 'On Rising Edge
On Pcint1 Isr_start
On Pcint2 Isr_libelle
On Timer1 Isr_clock 'On Timer1
On Urxc Isr_data 'On Urxc
Eicra = &B00000011
Eimsk = &B00000001
Eifr = &B00000001
Pcicr = &B00000110
Pcifr = &B00000110
Pcmsk2 = &B10000000
Pcmsk1 = &B00001000
Pcmsk0 = &B00000000
Enable Timer1
Enable Urxc
Sreg.7 = 1
'--- [ Start secuence ] --------------------------------------------------------
Echo Off
Gosub Clrdata
Dira = 0
Dirb = 0
Ocr0a = 255
Portc.0 = 0
Start Adc
'--- [ Main loop ] -------------------------------------------------------------
Do
Ist = Getadc(0)
If Soll <= Emax Then
W1 = Soll - Offset
If W1 > Ist Then
Dira = 1
Dirb = 0
Ocr0a = 0
End If
W1 = Soll + Offset
If W1 < Ist Then
Dira = 0
Dirb = 1
Ocr0a = 0
End If
W1 = Soll - Offset
W2 = Soll + Offset
If W1 <= Ist Then
If W2 >= Ist Then
Ocr0a = 255
Dira = 0
Dirb = 0
'If Ist >= W1 Then Soll = Emin
If After_back = 1 Then
After_back = 0
Soll = Emax
Print Soll ; " on afterback"
End If
End If
End If
Else
Ocr0a = 255
Dira = 0
Dirb = 0
Sreg.7 = 0
End If
Loop
End
'--- [ Interrupt service routine ] ---------------------------------------------
Isr_stop:
Incr Hits
If Inp_stop = 1 Then Print "STOP 1"
if inp_stop = 0 then print "STOP 0"
If Ist >= Is_ok Then
Gosub Savedata
Soll = Emin
Print Soll ; " on stop_ok"
Else
If Hits = 3 Then
Gosub Savedata
Soll = Emin
Print Soll ; " on stop_3hits"
End If
If Hits < 3 Then
I1 = Ist - 500
If I1 < 0 Then I1 = 0
Soll = I1
Print Soll ; " on stop_hit"
After_back = 1
End If
End If
Return
Isr_start:
If Inp_start = 1 Then Print "START 1"
If Inp_start = 0 Then Print "START 0"
If Inp_start = 0 Then
Start_setted = 1
End If
If Inp_start = 1 Then
If Start_setted = 1 Then
Start_setted = 0
Soll = Emax
Print Soll ; " on start"
End If
End If
Return
Isr_libelle:
If Inp_libelle = 1 Then Print "LIBELLE 1"
If Inp_libelle = 0 Then Print "LIBELLE 0"
If Inp_libelle = 0 Then
Libelle = 1
End If
Return
Isr_data:
B1 = Udr
If Chr(b1) = "!" Then
Soll = 3333
Print Soll ; " on !"
End If
If Chr(b1) = "]" Then
Print Buffer
Gosub Rs232
End If
Buffer = Buffer + Chr(b1)
If Chr(b1) = "[" Then
Buffer = ""
End If
Return
Isr_clock:
Timer1 = Clock
Second = Second + 1
If Second = 60 Then Gosub Addminute
If Minute = 60 Then Gosub Addhour
If Hour = 24 Then Gosub Addday
If Day = 31 Then
Select Case Month
Case 1 : Gosub Addmonth
Case 3 : Gosub Addmonth
Case 5 : Gosub Addmonth
Case 7 : Gosub Addmonth
Case 8 : Gosub Addmonth
Case 10 : Gosub Addmonth
Case 12 : Gosub Addmonth
End Select
End If
If Day = 30 Then
Select Case Month
Case 2 : Gosub Addmonth
Case 4 : Gosub Addmonth
Case 6 : Gosub Addmonth
Case 9 : Gosub Addmonth
Case 11 : Gosub Addmonth
End Select
End If
If Month = 12 Then Gosub Addyear
Tresult = Format(hour , "00") + ":" + Format(minute , "00")
Dresult = Format(year , "00") + "." + Format(month , "00") + "." + Format(day , "00")
Print Soll ; " :: " ; Ist
Return
'--- [ SUBs and functions ] ----------------------------------------------------
Sub Snd(byval Freq As Word)
Sound Audio , 200 , Freq
End Sub
'--- [ GOSUBs ] ----------------------------------------------------------------
Savedata:
For I2 = 0 To Datensaetze
If Daten(i2) = "" Then
Exit For
End If
Next I2
If Hits >= 3 Then S1 = "0" Else S1 = "1"
If Libelle = 1 Then S2 = "0" Else S2 = "1"
Daten(i2) = S1 + "§" + S2 + "§" + Str(soll) + "§" + Str(ist) + "§" + Dresult + "§" + Tresult
Print "DATEN" ; I2
Print Daten(i2)
Hits = 0
Libelle = 0
After_back = 0
Start_setted = 0
Return
Clrdata:
For I2 = 0 To Datensaetze
Daten(i2) = ""
Next I
Return
Addminute:
Minute = Minute + 1
Second = 0
Return
Addhour:
Hour = Hour + 1
Minute = 0
Return
Addday:
Day = Day + 1
Hour = 0
Return
Addmonth:
Month = Month + 1
Day = 0
Return
Addyear:
Year = Year + 1
Month = 0
Return
Rs232:
If Buffer = "CLR" Then
Gosub Clrdata
Print "<EXIT>"
End If
If Instr(buffer , "YR") > 0 Then
Buffer = Right(buffer , 4)
Year = Val(buffer)
End If
If Instr(buffer , "MN") > 0 Then
Buffer = Right(buffer , 2)
Month = Val(buffer)
End If
If Instr(buffer , "DA") > 0 Then
Buffer = Right(buffer , 2)
Day = Val(buffer)
End If
If Instr(buffer , "HR") > 0 Then
Buffer = Right(buffer , 2)
Hour = Val(buffer)
End If
If Instr(buffer , "MI") > 0 Then
Buffer = Right(buffer , 2)
Minute = Val(buffer)
End If
If Instr(buffer , "SC") > 0 Then
Buffer = Right(buffer , 2)
Second = Val(buffer)
Print "<EXIT>"
End If
If Instr(buffer , "SL") > 0 Then
Buffer = Right(buffer , 3)
Is_ok = Val(buffer)
Is_ok = Is_ok * 1
Print "<EXIT>"
End If
If Instr(buffer , "EI") > 0 Then
Buffer = Right(buffer , 4)
End If
If Instr(buffer , "EA") > 0 Then
End If
If Instr(buffer , "OF") > 0 Then
End If
If Instr(buffer , "FA") > 0 Then
End If
If Instr(buffer , "FB") > 0 Then
End If
If Instr(buffer , "FC") > 0 Then
End If
If Buffer = "GDA" Then
End If
If Buffer = "SND" Then
If Daten(1) = "" Then
Else
For I1 = 0 To Datensaetze
If Daten(i1) = "" Then
Exit For
End If
Print "<" ; I1 ; "§" ; Daten(i1) ; ">"
Waitms 10
Next I1
End If
Print "<EXIT>"
End If
If Buffer = "FWD" Then
Soll = Emax
Print Soll ; " on FWD"
End If
If Buffer = "BWD" Then
Soll = Emin
Print Soll ; " on BWD"
End If
If Buffer = "STP" Then
Soll = 3333
Print Soll ; " on STP"
End If
If Buffer = "GIN" Then
Print "<4%Position: " ; Ist ; ">"
End If
If Buffer = "GTI" Then
Print "<3%" ; Tresult ; ">"
Print "<3%" ; Dresult ; ">"
End If
If Buffer = "ABP" Then
Call Snd(volhigh)
Waitms 10
Call Snd(volmiddle)
Waitms 10
Call Snd(vollow)
End If
Return