Hallo

Um das Bascom mit der bee etwas zu pushen habe ich die ACS-Funktion von C nach Bascom umgeschrieben:
Code:
' nibobee ACS mit Bascom (und zusätzlich allgemeinene Funktionen)       16.1.10 mic

' https://www.roboternetz.de/phpBB2/vi...=480966#480966

Declare Sub Motorpwm(byval Pwm_l As Byte , Byval Pwm_r As Byte)       'Pwm für Motoren setzen (0-255)
Declare Sub Motordir(byval Dir_l As Byte , Byval Dir_r As Byte)       'Drehrichtungen der Motoren setzen (1/0)
Declare Sub Setleds(byval Leds As Byte)                     'Leds als Bitmuster setzen &B000xxxx
Declare Function Getkeys() As Byte                          'Bitmuster der Tasten einlesen &B0000xxxx
Declare Sub Odo_reset                                       ' Odometryzähler auf null setzen
Declare Sub Sleep(byval Pause As Byte)                      'Pause 1/36000 Sekunde warten
Declare Sub Msleep(byval Pause As Word)                     'Pause 1/1000 Sekunde warten
Declare Sub Acs                                             ' acs_left und acs_right aktuallisieren

$regfile = "m16def.dat"
$crystal = 15000000
$hwstack = 48                                               ' kleiner 48 ergibt Stapelüberlauf!
$swstack = 8
$framesize = 24

$baud = 19200

Acs_led_left Alias Porta.2                                  'acs Anoden
Acs_led_right Alias Porta.3
Acs_led_36khz Alias Portc.2                                 ' Kathode mit Widerstand
Acs_tsop Alias Pinc.3                                       'Eingang!

Led0 Alias Portb.0
Led1 Alias Portb.1
Led2 Alias Portb.2
Led3 Alias Portb.3
Lineled Alias Portb.4

Config Led0 = Output                                        ' LEDs 0-3
Config Led1 = Output
Config Led2 = Output
Config Led3 = Output
Config Lineled = Output                                     ' Lineled

Config Acs_led_left = Output                                'acs
Config Acs_led_right = Output
Config Acs_led_36khz = Output
Config Acs_tsop = Input

Config Portc.4 = Input                                      ' keys
Config Portc.5 = Input
Config Portc.6 = Input
Config Portc.7 = Input
Portc = &B11110000                                          'Tasten-PullUp Bit 4-7 einschalten

Config Portd.2 = Input                                      ' odo_l int0
Config Portd.3 = Input                                      ' odo_r int1
Config Portd.4 = Output                                     ' pmw_r
Config Portd.5 = Output                                     ' pwm_l
Config Portd.6 = Output                                     ' dir_l
Config Portd.7 = Output                                     ' dir_r

'Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 1
Config Timer2 = Pwm , Compare Pwm = Disconnect , Prescale = 1       'gemessene 36kHz!
Ocr2 = 151                                                  '36kHz mit Puls:Pause 50:50
Tcnt2 = 99                                                  'Frequenzkorrektur beim Start
Config Adc = Single , Prescaler = 64 , Reference = Avcc     ' 235 kHz
Config Int0 = Change
Config Int1 = Change

Dim B As Byte , W As Word
Dim Odo_count_l As Word , Odo_count_r As Word
Dim Count36khz As Byte
Dim Acs_left As Byte , Acs_right As Byte
Dim Acs_count As Byte

Start Adc
On Oc2 Isr_timer2_comp
On Ovf2 Isr_timer2_ovl
On Int0 Isr_int0
On Int1 Isr_int1
Enable Oc2
Enable Ovf2
Enable Int0
Enable Int1
Enable Interrupts

Do
   Call Acs
   Reset Led0
   Reset Led1
   Reset Led2
   Reset Led3
   If Acs_left > 251 Then
      Set Led1
   Else
      If Acs_left > 230 Then Set Led0
   End If
   If Acs_right > 251 Then
      Set Led2
   Else
      If Acs_right > 230 Then Set Led3
   End If
   Call Msleep(100)
Loop
End

Sub Acs
   Ocr2 = 253
   Set Acs_led_left
   While Acs_tsop = 1 And Ocr2 > 151
      Acs_count = 8
      While Acs_count > 0
      Wend
      Ocr2 = Ocr2 - 1
   Wend
   Reset Acs_led_left
   Acs_left = Ocr2
   While Acs_tsop = 0
   Wend

   Ocr2 = 253
   Set Acs_led_right
   While Acs_tsop = 1 And Ocr2 > 151
      Acs_count = 8
      While Acs_count > 0
      Wend
      Ocr2 = Ocr2 - 1
   Wend
   Reset Acs_led_right
   Acs_right = Ocr2
   While Acs_tsop = 0
   Wend
End Sub

Sub Motorpwm(byval Pwm_l As Byte , Byval Pwm_r As Byte)
   Pwm1a = Pwm_l * 4
   Pwm1b = Pwm_r * 4
End Sub

Sub Motordir(byval Dir_l As Byte , Byval Dir_r As Byte)
   If Dir_l = 0 Then Portd.6 = 0 Else Portd.6 = 1
   If Dir_r = 0 Then Portd.7 = 1 Else Portd.7 = 0
End Sub

Sub Setleds(byval Leds As Byte)
      Led0 = Leds.0
      Led1 = Leds.1
      Led2 = Leds.2
      Led3 = Leds.3
End Sub

Function Getkeys() As Byte
   Getkeys = Pinc / 16                                      ' Pins einlesen und nach rechts schieben
   Getkeys = Getkeys Xor 255                                ' invertieren
   Getkeys = Getkeys And 15                                 ' Bit4-7 ausblenden
End Function

Sub Odo_reset
   Disable Interrupts
   Odo_count_l = 0
   Odo_count_r = 0
   Enable Interrupts
End Sub

Sub Sleep(byval Pause As Byte)
   Count36khz = Pause
   While Count36khz > 0
   Wend
End Sub

Sub Msleep(byval Pause As Word)
   While Pause > 0
      Call Sleep(36)
      Decr Pause
   Wend
End Sub

Isr_int0:
   Incr Odo_count_l
   Led0 = Pind.2
Return

Isr_int1:
   Incr Odo_count_r
   Led3 = Pind.3
Return

Isr_timer2_comp:
   Toggle Acs_led_36khz
Return

Isr_timer2_ovl:
   Tcnt2 = Tcnt2 + 99                                       'Frequenzkorrektur 36kHz
   Reset Acs_led_36khz
   If Count36khz > 0 Then Decr Count36khz
   If Acs_count > 0 Then Decr Acs_count
Return
Die Werte meiner Liniensensoren sind auch unterschiedlich. Die Mitte hat (aufbaubedingt?) immer den höchsten Wert, die linke Seite schwächelt etwas und hat ca. 50 weniger als die rechte Seite bei hell.

Gruß

mic

[Edit]
Setup Timer2 geändert!!!