Translate

21 September 2012

Das Controller-Programm Stand 21.09.2012

Falls es jemanden interessiert.........

Mein Controller-Programm  habe ich in Bascom geschrieben.
So wie es jetzt ist läuft es schon ganz brauchbar, obwohl es noch nicht
fertig ist. Es fehlen noch ein paar Dinge, die aber für erste Tests entbehrlich
sind. z.B. Temperaturmessung am Kühlkörper, Störmeldeausgang,
Plausibilitätsprüfung beim Stromwandler  etc........
Das sind aber alles leicht zu programmierende Funktionen, die ich so
nach und nach hinzufügen möchte.
Schwieriger wird da noch die Drehzahlerfassung und Begrenzung,
da muss ich auch noch die Hardware ändern, weil ich dafür
einen Interrupt brauche, und beide Interrupt-Kanäle momentan noch am
Drehencoder hängen. Es wird aber nur einer benötigt,
das sollte also auch machbar sein.

Für einen funktionieenden Controller sind vor allem so Dinge
wie die Parameter des Strompedals wichtig, die Stromanzeige,
und eine Strombegrenzung, und das funktioniert hervorragend.

Die Leerlauf-Funktion "IDLE" ist ein kleines Extra, da ich ja die
Servopumpe und die Lichtmaschine per Riemen antreiben will wie schon beim
Verbrennungsmotor. hier gibt es auch eine Start-Stop-Funktion.
die minimale PWM Rate ist einstellbar, ebenso der maximale Strom.
wenn man den Knopf kurz antippt wird der Motor angehalten,
und fängt erst bei Betätigen des Potis an, wieder zu laufen.
Erst ab einer gewissen Gasstellung wird die Leerlauffunktion wieder aktiviert.
Hier müssen aber erst noch Praxistests die Brauchbarkeit beweisen.
Das ist bei Autos mit Verbrennungsmotor auch noch mit der Kupplung gekoppelt.


Das ist der momentane Zwischenstand des Controller-Programms
mit folgenden Features:

LCD-Display mit Anzeige aller wichtigen Parameter,

Strombegrenzung und Strommessung per LEM HASS200-S

Parametrierbares Poti (Nulllage ; Voll betätigt  ;  Warngrenzen für Fehlermeldung )

Nullstellungsüberwachung beim Start

Plausibilitätsprüfung beim Poti

Pausibilitätsprüfung des LEM-Wandlers fehlt noch,
aber Prüfung ob kleiner 25 bzw größer 1000 sollte reichen, da diese Werte
nie erreicht werden können ausser bei Kurzschluss oder Drahtbruch

Parametrierung per Menue

Drehencoder mit Taste als Eingabeinstrument

Start-Stop-Funktion mit eigens parametrierbaren Strom und PWM-Werten

Viel Spass beim Nachvollziehen der Abläufe
Da kann man sicher noch einiges besser lösen, aber es entsteht ja erst.....


Ab hier beginnt das Programm

$regfile = "m168def.dat"
$crystal = 4000000
$baud = 1200 ' unnötig, kein RS232 verwendet ev.Option?
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc

Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
Config Lcdbus = 4

Config Lcd = 20 * 4a , Chipset = Ks077                     'für EA DIP204-4
Cursor Off
Cls

Dim A As Word
Dim A1 As Integer
Dim B As Integer
Dim B0 As Word
Dim B1 As Word
Dim Null As Word
Dim Nullee As Eram Word
Dim Amp As Long
Dim Ampmax As Word
Dim Ampmaxee As Eram Word
Dim Menzahl As Word
Dim Limithi As Word
Dim Limitlo As Word
Dim Disp As Byte
Dim Error As Bit
Dim Idlebit As Bit
Dim Errorhi As Word
Dim Errorhiee As Eram Word
Dim Errorlo As Word
Dim Errorloee As Eram Word
Dim Pothi As Word
Dim Pothiee As Eram Word
Dim Potlo As Word
Dim Potloee As Eram Word
Dim Idlepot As Word
Dim Idlepotee As Eram Word
Dim Idleamp As Word
Dim Idleampee As Eram Word
Dim Potdiff As Word
Dim Potout As Word
Dim Setupexit As Bit
Dim Adc1 As Word

Config Pind.2 = Input
Config Pind.3 = Input
Config Pind.4 = Input

Portd.2 = 1
Portd.3 = 1
Portd.4 = 1


Config Portd.6 = Output          'PWM-Ausgang

Config Int0 = Change    'für den Drehencoder
Enable Interrupts
Enable Int0
On Int0 Updn:

Config Timer0 = Pwm , Pwm = On , Compare A Pwm = Clear Down , Prescale = 1

Disp = 0
B1 = 0
Null = Nullee
Ampmax = Ampmaxee
Error = 1
Errorhi = Errorhiee
Errorlo = Errorloee
Pothi = Pothiee
Potlo = Potloee
Idlepot = Idlepotee
Idleamp = Idleampee
Idlebit = 0

If Null > 65000 Then            'Standardwerte beim ersten Einschalten
Nullee = 512
Null = Nullee
Ampmaxee = 10
Ampmax = Ampmaxee
Errorhiee = 1023
Errorhi = Errorhiee
Errorloee = 0
Errorlo = Errorloee
Pothiee = 1000
Pothi = Pothiee
Potloee = 100
Potlo = Potloee
Idlepotee = 0
Idlepot = Idlepotee
Idleampee = 30
Idleamp = Idleampee
Goto Setup
End If

Press:                                        ' Menue aufrufen
If Pind.4 = 1 Then Goto Run
Error = 1
Idlebit = 0
B1 = 0
Ocr0a = 0
Cls
Waitms 200
If Pind.4 = 1 Then Goto Run
Locate 1 , 1
Lcd "Taste gedrueckt "
Waitms 200
If Pind.4 = 1 Then Goto Run
Locate 1 , 1
Lcd "Setup in 4 Sek "
Wait 1

If Pind.4 = 1 Then Goto Run
If Pind.4 = 0 Then
Cls
Locate 1 , 1
Lcd "Setup in 3 Sek "
Wait 1
End If

If Pind.4 = 1 Then Goto Run
If Pind.4 = 0 Then
Cls
Locate 1 , 1
Lcd "Setup in 2 Sek "
Wait 1
End If


If Pind.4 = 1 Then Goto Run
If Pind.4 = 0 Then
Cls
Locate 1 , 1
Lcd "Setup in 1 Sek "
Wait 1
End If

If Pind.4 = 1 Then Goto Run
Taste:
If Pind.4 = 0 Then
Locate 1 , 1
Lcd "Setup wird gestartet"
Locate 2 , 1
Lcd "Taste loslassen!"
Wait 1
End If
If Pind.4 = 0 Then Goto Taste
Goto Setup


Cls



Run:
Cls
Potdiff = Pothi - Potlo     'Umrechnungsfaktor fürs Poti berechnen
Potdiff = Potdiff * 10
Potdiff = Potdiff / 256


Do

Debounce Pind.4 , 0 , Press


A = Getadc(0) 'Input LEM-Wandler
B = Getadc(1) 'Input Poti


A1 = A - Null                               'Nullabgleich LEM
'If A1 < 0 Then A1 = 0
Amp = A1 * 1565
Amp = Amp / 1000

If B > Errorhi Then
Error = 1
Locate 4 , 1
Lcd " Error Poti high"
End If

If B > Errorlo And B < Errorhi And Error = 1 Then

Locate 4 , 1
Lcd " Check Throttle "
End If


If B < Errorlo Then
Error = 1
Locate 4 , 1
Lcd " Error Poti low "
End If

' Fehler zurücksetzen
If B < Potlo And B > Errorlo And B > Idlepot And Error = 1 Then
Error = 0
Locate 4 , 1
Lcd "                           "
End If

B = B - Potlo
If B < 0 Then B = 0



B = B * 10
B = B / Potdiff

'B = Poti umgerechnet

If B > 255 Then B = 255
If B > Idlepot Then Idlebit = 1
'Poti
If B > B1 And Amp < Ampmax Then Incr B1
If B1 < Idlepot And Amp < Idleamp And Idlebit = 1 Then Incr B1
If B < B1 And B1 > Idlepot Then Decr B1
If B1 > 0 And Amp > Ampmax Then Decr B1
If B1 > 0 And B1 > B And Idlebit = 0 Then Decr B1
If B < Idlepot And Amp > Idleamp Then Decr B1

If Error = 1 Then                 'bei Fehler STOPP
B1 = 0
End If

Ocr0a = B1                           'PWM Wert  setzen

Gosub Displ                            'Werte anzeigen

Loop







Updn:    'Subroutine fürs Menue
If Menzahl < Limithi And Pind.2 = Pind.3 Then Incr Menzahl
If Menzahl > Limitlo And Pind.2 <> Pind.3 Then Decr Menzahl
'Licht = Lichtan
'Setuptime = 500
Return

Displ:                   ' Display langsam schreiben
If Disp = 10 Then
Locate 1 , 1
Lcd "Pot" ; B ; " " ;
End If

If Disp = 20 Then
Locate 1 , 8
Lcd "LEM" ; A1 ; " " ;
End If

If Disp = 30 Then
Locate 1 , 15
Lcd "PWM" ; B1 ; " " ;
End If

If Disp = 40 Then
Locate 2 , 1
Lcd "Amp" ; Amp ; " " ;
End If

If Disp = 50 Then
Locate 2 , 8
Lcd "max" ; Ampmax ; " " ;
End If

If Disp = 60 Then
B0 = Getadc(1)
Locate 3 , 1
Lcd "ADC" ; B0 ; " " ;
End If

If Disp = 70 Then
Locate 3 , 9
Lcd "lo" ; Potlo ; " " ;
End If

If Disp = 80 Then
Locate 3 , 15
Lcd "hi" ; Pothi ; " " ;
End If

If Disp = 90 And B < Idlepot And Error <> 1 And Idlebit = 1 Then
Locate 4 , 1
Lcd " IDLE "
End If

If Disp = 90 And B > Idlepot And Error <> 1 Then
Locate 4 , 1
Lcd " "
End If

Incr Disp
If Disp > 110 Then Disp = 0
Return


Setup:

Menzahl = Null
Setup1:
A = Getadc(0)
Locate 1 , 1
Lcd "Setup Nullpunkt Amp."
Locate 2 , 1
Lcd Null ; " (Istwert:" ; A ; ") "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 600
Limitlo = 400

Debounce Pind.4 , 0 , Setup1x
Null = Menzahl

Goto Setup1
Setup1x:
Nullee = Null
Cls


'Exit

Menzahl = 0
Setupexit1:
Locate 1 , 1
Lcd "exit Setup? "
Locate 2 , 1
If Menzahl = 0 Then Lcd " extended Setup "
If Menzahl = 1 Then Lcd "=> extended Setup "
Locate 3 , 1
If Menzahl = 0 Then Lcd "=> Exit Setup "
If Menzahl = 1 Then Lcd " Exit Setup "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 1
Limitlo = 0

Debounce Pind.4 , 0 , Setupexit1x


Goto Setupexit1
Setupexit1x:
If Menzahl = 0 Then Goto Run
Cls

Menzahl = Ampmax
Setupampmax:
Locate 1 , 1
Lcd "Setup Max.Ampere "
Locate 2 , 1
Lcd Ampmax ; "A maximal "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 600
Limitlo = 5

Debounce Pind.4 , 0 , Setupampmaxx
Ampmax = Menzahl

Goto Setupampmax
Setupampmaxx:
Ampmaxee = Ampmax
Cls


Menzahl = Idlepot
Setupidlepot:
Locate 1 , 1
Lcd "Setup Idlepot "
Locate 2 , 1
Lcd Idlepot ; " PWM max at Idle "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 30
Limitlo = 0

Debounce Pind.4 , 0 , Setupidlepotx
Idlepot = Menzahl

Goto Setupidlepot
Setupidlepotx:
Idlepotee = Idlepot
Cls


Menzahl = Idleamp
Setupidleamp:
Locate 1 , 1
Lcd "Setup Idleamp "
Locate 2 , 1
Lcd Idleamp ; "A max at Idle "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 50
Limitlo = 25

Debounce Pind.4 , 0 , Setupidleampx
Idleamp = Menzahl

Goto Setupidleamp
Setupidleampx:
Idleampee = Idleamp
Cls



Menzahl = Potlo
Setup3:
B = Getadc(1)
Locate 1 , 1
Lcd "Setup Pot Null "
Locate 2 , 1
Lcd Potlo ; " ADC: " ; B ; " "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 255
Limitlo = 0

Debounce Pind.4 , 0 , Setup3x
Potlo = Menzahl

Goto Setup3
Setup3x:
Potloee = Potlo
Cls



Menzahl = Pothi
Setup4:
B = Getadc(1)
Locate 1 , 1
Lcd "Setup Pot High "
Locate 2 , 1
Lcd Pothi ; " ADC: " ; B ; " "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 1023
Limitlo = 512

Debounce Pind.4 , 0 , Setup4x
Pothi = Menzahl

Goto Setup4
Setup4x:
Pothiee = Pothi
Cls




Menzahl = Errorlo
Setup5:
B = Getadc(1)
Locate 1 , 1
Lcd "Setup Error low "
Locate 2 , 1
Lcd Errorlo ; " ADC: " ; B ; " "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = Potlo
Limitlo = 0

Debounce Pind.4 , 0 , Setup5x
Errorlo = Menzahl

Goto Setup5
Setup5x:
Errorloee = Errorlo
Cls



Menzahl = Errorhi
Setup6:
B = Getadc(1)
Locate 1 , 1
Lcd "Setup Error High "
Locate 2 , 1
Lcd Errorhi ; " ADC: " ; B ; " "
Locate 4 , 1
Lcd "weiter mit Enter >>"

Limithi = 1023
Limitlo = Pothi

Debounce Pind.4 , 0 , Setup6x
Errorhi = Menzahl

Goto Setup6
Setup6x:
Errorhiee = Errorhi
Cls


Goto Run


End

Keine Kommentare:

Kommentar veröffentlichen