Hallo allerseits,

habe folgendes Problem:
Hardware: RN-Control board

Das Programm soll ein Abwärtszähler in Sekunden mit einem PWM Ausgang für einen Servomotor werden. Die Zeit und Geschwindigkeit werden über 2 Encoder eingestellt. Über eine beleuchtete Taste wird der Abwärtszähler eingeschaltet. Der Motor läuft nun mit der eingestellten Geschwindigkeit bis die Zeit abgelaufen ist. Außerdem gibt es noch ein LCD zur Anzeige. Das Programm funktioniert eigendlich. Wenn ich aber versuche einen PWM Ausgang zu programmieren geht gar nichts mehr. Ich habe das versucht über die config servo funktion und über Timer0 = PWM. Hat alles nicht geklappt.

Es wäre schön wenn einer mal den Code ansieht und mir ein paar Tips gibt, wie man so was richtig programmiert


Code:
 $regfile = "m32def.dat"                                                   'specify the used micro
      $crystal = 4000000                                                        ' used crystal frequency
      $hwstack = 32                                                             ' default use 32 for the hardware stack
      $swstack = 64                                                             ' default use 10 for the SW stack
      $framesize = 40                                                           ' default use 40 for the frame spaceconfig

      Config Clock = Soft                                                       ' Konfiguriere softclock für LCD Anzeige in mm:ss
      Config Debounce = 30                                                      'Konfiguriere Debouncezeit = 30ms

     Config Timer1 = Timer , Prescale = 1024                                    'Konfiguriere Timer1 Für Sekundentakt                            '
     Enable Timer1                                                              ' Timer1 einschalten
     On Timer1 Sekundentakt                                                     'Verzweige bei Timer1 überlauf zu   Isr_von_Timer1
     Timer1 = 49900

     Enable Interrupts

     Config Portb.3 = Input                                                     'Start/Abbruch Taster
     Config Portb.4 = Output                                                    'LED  blinkt während Betrieb

     Config Porta.0 = Input
     Config Porta.1 = Input
     Config Porta.2 = Input
     Config Porta.3 = Input
     Config Porta.4 = Input
     Config Porta.5 = Input


     Portb.3 = 1
     Portb.4 = 0
     Porta = &B11111111
     'Portd = &B11111111

      Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
      Config Lcd = 20 * 4
      Cursor Off

      Dim B As Byte
      Dim A As Byte
      Dim Speed As Integer
      Dim Overtorque As Word
      Dim Flag_overtorque As Bit
      Dim Sekunde As Long
      Dim Act_sekunde As Long
      Dim Str_time As String * 10
      Dim Str_speed As String * 10
      Dim Taster_count As Byte
      Dim Skip_flag As Byte
      Dim Mem_sekunde As Eram Long
      Dim Mem_speed As Eram Integer

      Taster_start_stop Alias Pinb.3

      Speed = Mem_speed
      Sekunde = Mem_sekunde
      Taster_count = 0
      Skip_flag = 1

      Cls
      Home
      Lcd "** CALOGRINDER V5 **"
      Locate 3 , 5 : Lcd "PVT-BENSHEIM"
      Wait 2
      Lowerline
      Cls
      Home
      Lcd "SPEED (%)"
      Str_speed = Str(speed)
      Locate 1 , 18 : Lcd Format(str_speed , "000")
      Lowerline
      Lcd "TIME (min)"
      Str_time = Time(sekunde)
      Locate 2 , 16 : Lcd Right(str_time , 5)
      Thirdline
      Lcd "____________________"
      Fourthline
      Lcd "REMAINING TIME"
      Locate 4 , 16
      Lcd "00:00"

   '-----------------------------------------------------------------------------------
      Mainprogram:
 '-----------------------------------------------------------------------------------
      Do
          B = Encoder(pina.1 , Pina.0 , Runtime_up , Runtime_down , 0)
          A = Encoder(pina.4 , Pina.3 , Speed_up , Speed_down , 0)
          Debounce Pinb.3 , 0 , Tasterevent , Sub
          Debounce Pina.5 , 0 , Speedplus , Sub
          Debounce Pina.2 , 0 , Timeplus , Sub
    Loop

 '-----------------------------------------------------------------------------------
      Speed_up:
 '-----------------------------------------------------------------------------------
      If Skip_flag = 1 Then
         Skip_flag = 0
         Return
      End If
      Incr Speed
      Skip_flag = 1
      If Speed >= 100 Then
         Speed = 100
      End If
      Str_speed = Str(speed)
      Locate 1 , 18
      Lcd Format(str_speed , "000")
      Return

  '-------------------------------------------------------------------------------------
      Speed_down:
 '-------------------------------------------------------------------------------------
      If Skip_flag = 1 Then
         Skip_flag = 0
         Return
      End If
      Decr Speed
     Skip_flag = 1
      If Speed < 1 Then
         Speed = 0
      End If
      Str_speed = Str(speed)
      Locate 1 , 18
      Lcd Format(str_speed , "000")
      Return

 '-------------------------------------------------------------------------------------
      Runtime_up:
 '-------------------------------------------------------------------------------------
      If Skip_flag = 1 Then
         Skip_flag = 0
         Return
      End If
      If Sekunde <= 3598 Then
      Incr Sekunde                                                              '
           Skip_flag = 1
           Str_time = Time(sekunde)
           Locate 2 , 16 : Lcd Right(str_time , 5)
      End If
      Return
 '------------------------------------------------------------------------------------
      Runtime_down:
 '------------------------------------------------------------------------------------
      If Skip_flag = 1 Then
         Skip_flag = 0
         Return
      End If
      If Sekunde > 0 Then
         Decr Sekunde                                                           '
         Skip_flag = 1
         Str_time = Time(sekunde)
         Locate 2 , 16 : Lcd Right(str_time , 5)
      End If
      Return
 '
 '-----------------------------------------------------------------------------
      Sekundentakt:
 '-----------------------------------------------------------------------------
      Timer1 = 49900
      If Taster_count = 1 Then
         Decr Act_sekunde
         Str_time = Time(act_sekunde)
         Locate 4 , 16 : Lcd Right(str_time , 5)
         Gosub Run
      End If
      Return

  '-----------------------------------------------------------------------------
      Run:
  '-----------------------------------------------------------------------------
      '
      Toggle Portb.4
      Waitms 500
      Toggle Portb.4

      If Act_sekunde <= 0 And Taster_count = 1 Then
         Taster_count = 0
         Reset Portb.4
         Cls
         Lowerline
         Locate 2 , 3 : Lcd "**GRINDING END**"
         Sound Portd.7 , 400 , 450
         Waitms 333
         Sound Portd.7 , 400 , 450
         Waitms 333
         Sound Portd.7 , 400 , 450
         Waitms 333
         Goto Startanzeige
      End If
      Return

 '-----------------------------------------------------------------------------
      Tasterevent:
 '-----------------------------------------------------------------------------
      Taster_count = Taster_count + 1
      Act_sekunde = Sekunde
     If Taster_count = 1 And Sekunde = 0 Or Speed = 0 Then
         Taster_count = 0
      End If

      If Sekunde <> Mem_sekunde Then
              Mem_sekunde = Sekunde
      End If
      If Speed <> Mem_speed Then
              Mem_speed = Speed
      End If

      If Taster_count = 2 Then
         Taster_count = 0
         Reset Portb.4
         Cls
         Lowerline
         Locate 2 , 3 : Lcd "<<<<BREAKOFF>>>>"
         Sound Portd.7 , 50 , 80000
         Goto Startanzeige
      End If

      Return

  '-----------------------------------------------------------------------------
      Speedplus:
 '-----------------------------------------------------------------------------
       If Speed < 91 Then
         Speed = Speed + 10
         Str_speed = Str(speed)
         Locate 1 , 18
         Lcd Format(str_speed , "000")
         Waitms 100
      Elseif Speed = 100 Then
         Speed = 0
      End If
      Return

  '-----------------------------------------------------------------------------
  Timeplus:
 ' -----------------------------------------------------------------------------
      Sekunde = Sekunde + 60
      Str_time = Time(sekunde)
      Locate 2 , 16 : Lcd Right(str_time , 5)
      Waitms 100
      Return

 '-----------------------------------------------------------------------------
    Startanzeige:
 '-----------------------------------------------------------------------------
      Cls
      Home
      Lcd "SPEED (%)"
      Str_speed = Str(speed)
      Locate 1 , 18 : Lcd Format(str_speed , "000")
      Lowerline
      Lcd "TIME (min)"
      Str_time = Time(sekunde)
      Locate 2 , 16 : Lcd Right(str_time , 5)
      Thirdline
      Lcd "____________________"
      Fourthline
      Lcd "REMAINING TIME"
      Locate 4 , 16
      Lcd "00:00"
      Return