Update ...
habe mich heute mit der Motor-Ansteuerung befasst ... Es funktioniert auf jeden Fall schon mal ...
noch über die RS232 angesteuert, später über I2C-Slave ...
Mit den Gebern am Motor wird die Drehzahl über die Interrupt-Eingänge INT0 / INT1 und den Timer0 erfasst ( Frequenzmessung ).
Über RS232 kann ich die Geschwindigkeit Test-weise vorgeben (0 / 25 / 50 / 100 / 130 )
Der Motor-Treiber wird über ein PWM angesteuert und entsprechend nachgeregelt ... da muss ich aber noch mal ran und die Beschleunigungskurve anpassen ...
Da ich Bascom und Nano Neuling bin hat es mich doch schon ein wenig gefordert ... zum Einstieg genau das richtige
Code:
' ------------ Bascom - Parameter ------------------------$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 100
$swstack = 100
$framesize = 100
$baud = 19200
Print "Start_Main"
' ------------ Timer_0 ------------------------
Config Timer0 = Timer , Prescale = 256
On Ovf0 Tim0_isr
Enable Timer0
' ------------ PWM (Timer_1) -------------------
Config Portb.1 = Output
Config Portb.2 = Output
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 64
' ------------ RS232 - Input ------------------------
Config Serialin = Buffered , Size = 40
' ------------ DIM ------------------------
Dim Na As String * 30 'RS232-Input-String
Dim Si As Byte 'RS232 Input
Dim Z0 As Integer
Dim Z1 As Integer
Dim Z0x As Word
Dim Z1x As Word
Dim Tx As Byte
Dim Tmx As Byte
Dim P1 As Byte
Dim P2 As Byte
Dim V1 As Word
Dim V2 As Word
' -------- Interrupt
Config Int0 = Falling
Config Int1 = Falling
Enable Int0
Enable Int1
On Int0 Int0_sub
On Int1 Int1_sub
Enable Interrupts
' -------- Hauptschleife ----------------------
Print "Start_Main Hauptschleife"
Do
' Hauptschleife
If Ischarwaiting() <> 0 Then
Si = Inkey()
If Si <> 13 And Si <> 10 And Len(na) < 30 Then
Na = Na + Chr(si)
Else
If Ucase(na) = "STATUS" Then
Print "ACK;STATUS"
Print "Status Z0x=" ; Z0x ; " Z1x=" ; Z1x
Elseif Ucase(na) = "ON" Then
Print "ACK;ON"
Print "ON;"
Elseif Ucase(na) = "OFF" Then
Print "ACK;OFF"
Print "OFF;"
Elseif Ucase(na) = "0" Then
Print "ACK"
V1 = 0 : V2 = 0
Print "V= " ; V1
Elseif Ucase(na) = "25" Then
Print "ACK"
V1 = 25 : V2 = 25
Print "V= " ; V1
Elseif Ucase(na) = "50" Then
Print "ACK"
V1 = 50 : V2 = 50
Print "V= " ; V1
Elseif Ucase(na) = "100" Then
V1 = 100 : V2 = 100
Print "V= " ; V1
Elseif Ucase(na) = "130" Then
V1 = 130 : V2 = 130
Print "V= " ; V1
Else
Print "NAK;" ; Na
End If
Na = ""
End If
End If
Loop
Tim0_isr:
' ---- Timer_0
Incr Tx
If Tx > 31 Then
Tx = 0
Incr Tmx
Z0x = Z0
Z0 = 0
Z1x = Z1
Z1 = 0
If V1 < Z0x And P1 < 255 Then
P1 = P1 + 5
End If
If V1 > Z0x And P1 > 0 Then
P1 = P1 - 5
End If
If V2 < Z1x And P2 < 255 Then
P2 = P2 + 5
End If
If V2 > Z1x And P2 > 0 Then
P2 = P2 - 5
End If
Compare1a = P1
Compare1b = P2
End If
If Tmx > 9 Then
Print "Status Z0x=" ; Z0x ; " Z1x=" ; Z1x ; " P1=" ; P1 ; " P2= " ; P2
Tmx = 0
End If
Return
Return
Int0_sub:
Incr Z0
Return
Return
Int1_sub:
Incr Z1
Return
Return
Lesezeichen