Администрация форума не несёт ответственности за достоверность информации и оставляет за собой право редактировать или в особых случаях даже удалять посты без предупреждения. Спасибо за понимание.

Программирование ATMEL в BASCOM.

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.



Поливатор на шаговиках

Сообщений 1 страница 4 из 4

1

Может кому пригодится. Хорошая штука:

К сожалению с исходником что-то случилось и я решил выложить его сюда пока полностью неразрушил.
Почему-то цикл не повторяется, а микроконтроллер перезагружается. Хотя есть уверенность что я его додыр протёр прошивкой:

Код:
$regfile = "m328pbdef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 128
$framesize = 288


'=================== Шаговые двигателя===============
Config Porte.0 = Output
Config Portb.6 = Output
Config Portb.7 = Output

Config Portb.1 = Output
Config Portb.2 = Output

Stp2 Alias Portb.6
Dir2 Alias Portb.7

Stp1 Alias Portb.1
Dir1 Alias Portb.2
'Powermoto Alias Porte.0
'Config Porte.0 = Output

'Концевики
Kny Alias Pinc.4
Knx Alias Pinc.5
Config Portc.5 = Input
Config Portc.4 = Input

Clapan Alias Portd.6
Config Portd.6 = Output
Const Offclapan = 1
Const Onclapan = 0
'====================================================

'Powermoto = 0


Dim P As Byte
Dim O As Byte
'Dim I As Byte
Dim Tm As Byte
Dim Vrw As Word
'Dim Vrw2 As Word

Dim Ogrx As Word                                            'Const Ogrx = 300
Dim Ogry As Word                                            'Const Ogry = 300

Dim Tmpx As Word
Dim Tmpy As Word
'Числовая система координат INTEGER
Dim X As Integer
Dim Y As Integer

Dim Tmx As Integer
Dim Tmy As Integer

'===================================
Dim Vr_speed As Byte
Dim Tmpausy As Byte
Dim Tmpausx As Byte
Dim Speed As Byte
Dim Speed_sys As Byte


Dim Tm_null As Word



Dim Gx As Byte
Dim Gy As Byte
Dim Ciklix As Word
Dim Cikliy As Word
'Dim Tm_cikli As Byte

Dim Trigx As Byte
Dim Trigy As Byte

Dim X_a As Integer
Dim Y_a As Integer
Dim X_b As Integer
Dim Y_b As Integer
Dim Vri As Integer

Dim Pozicia As Byte

Dim Adrs As Byte
Adrs = 3

Goto Prog:
'======================== Программа цикличного полива
Programma:
  Select Case Adrs
        Case 1
           X_a = 405
           X_b = 460

           Y_a = -260
           Y_b = -355

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 200
           Tmpausy = 40
           Speed_sys = 25
           'Adrs = 1
        'Case 1

        Case 2                                    'Клумба у 3 подъезда
           X_a = 80
           X_b = 380

           Y_a = -560
           Y_b = -640

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 80
           Tmpausy = 12
           Speed_sys = 25


        Case 3                                    'Распрыскивание над черёмухой
           X_a = 15
           X_b = 370

           Y_a = -70
           Y_b = -170

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 15
           Tmpausy = 15
           Speed_sys = 30


        Case 4                                    'Первая часть под черёмухой
           X_a = 50
           X_b = 235

           Y_a = -430
           Y_b = -510

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 200
           Tmpausy = 10
           Speed_sys = 25

        Case 5                                    'Вторая часть под черёмухой
           X_a = 40
           X_b = 130

           Y_a = -450
           Y_b = -400

           Ciklix = 15
           Cikliy = 0

           Tmpausx = 80
           Tmpausy = 40
           Speed_sys = 40

        Case 6                                              'Кусты у 2 подъезда
           'Gosub Null
           Vri = 0
           X_a = -210
           X_b = -40

           Y_a = -270
           Y_b = -370

           Ciklix = 20
           Cikliy = 0

           Tmpausx = 100
           Tmpausy = 30
           Speed_sys = 25

        Case 7                                              'куст у подъезда

           X_a = -300
           X_b = -310

           Y_a = -65
           Y_b = -155

           Ciklix = 15
           Cikliy = 0

           Tmpausx = 100
           Tmpausy = 40
           Speed_sys = 80
        Case 8                                    'Папортник

           X_a = -250
           X_b = -120

           Y_a = -505
           Y_b = -565

           Ciklix = 25
           Cikliy = 0

           Tmpausx = 40
           Tmpausy = 100
           Speed_sys = 25
        Case 9                                    'Куст у урны у 3 подъезда

           X_a = -180
           X_b = -50

           Y_a = -135
           Y_b = -200

           Ciklix = 20
           Cikliy = 0

           Tmpausx = 80
           Tmpausy = 100
           Speed_sys = 25

        Case 10                                   'Два куста у папортника

           X_a = -190
           X_b = -260
           Y_a = -430
           Y_b = -570

           Ciklix = 20
           Cikliy = 0

           Tmpausx = 250
           Tmpausy = 20
           Speed_sys = 25
        Case 11                                   'Дождь

           X_a = 310
           X_b = -200
           Y_a = -50
           Y_b = -210
           Ciklix = 15
           Cikliy = 0
           Tmpausx = 30
           Tmpausy = 10
           Speed_sys = 20

        Case 12                                   'переход перед выходом в ноль

           X_a = 100
           X_b = 100
           Y_a = -20
           Y_b = -20
           Ciklix = 1
           Cikliy = 0
           Tmpausx = 60
           Tmpausy = 80
           Speed_sys = 30
           Adrs = 0
   End Select
Return








Prog:


X_b = 0
Y_b = 0
X_a = 0
Y_a = 0

'Gosub Null

Pozicia = 0
Clapan = Offclapan
Speed_sys = 100
Speed = 80
Ciklix = 0
Cikliy = 0



Do



   If Speed > 0 Then
      Decr Speed
      Else
         Speed = Speed_sys

        If Tmpx = 0 Then

               If X > Tmx Then
                      Dir1 = 0
                      Incr Tmx
                      Gx = 0
                      Stp1 = Not Stp1
                      Tmpx = Tmpausx

                      Elseif X < Tmx Then
                        Dir1 = 1
                        Gx = 0
                        Stp1 = Not Stp1
                        Decr Tmx
                        Tmpx = Tmpausx
                      Else
                        Gx = 1
                        Trigx = Not Trigx

                        If Trigx = 0 Then
                           X = X_a
                           Else
                              X = X_b
                              If Pozicia = 0 Then Pozicia = 1
                              If Ciklix > 0 And Pozicia = 2 Then Decr Ciklix       'Цикли шагов двигателей

                        End If

               End If

           Else
              If Tmpx > 0 Then Decr Tmpx

        End If


        If Tmpy = 0 Then

              If Y > Tmy Then
                      Dir2 = 0
                      Incr Tmy
                      Stp2 = Not Stp2
                      Gy = 0
                      Tmpy = Tmpausy

                      Elseif Y < Tmy Then
                        Dir2 = 1
                        Stp2 = Not Stp2
                        Decr Tmy
                        Gy = 0
                        Tmpy = Tmpausy

                      Else
                             Gy = 1
                             Trigy = Not Trigy

                             If Trigy = 0 Then

                                   Y = Y_a

                                   Else
                                      Y = Y_b

                                      If Pozicia = 1 Then
                                         Pozicia = 2
                                         Clapan = Onclapan
                                      End If

                                      If Cikliy > 0 And Pozicia = 2 Then Decr Cikliy       'Цикли шагов двигателей

                             End If

                             Tmpy = Tmpausy
              End If

         Else
            If Tmpy > 0 Then Decr Tmpy
        End If


      '=================================================================== Задатчик цикла
      If Ciklix = 0 And Cikliy = 0 Then

                Clapan = Offclapan
                Wait 1

                Gosub Null
                'Получение новых координат
                Gosub Programma:



               Adrs = Adrs + 1
               Pozicia = 0
               Trigx = 0
               Trigy = 0
               X = X_a
               Y = Y_a
               Gx = 0
               Gy = 0


      End If








   End If



Loop

Do
Loop

End

Null:
    Clapan = Offclapan
    If Knx = 0 Then
      Dir1 = 0
      For P = 1 To 100
         Stp1 = Not Stp1
         Waitms 10
      Next P
    End If

    If Knx = 1 Then
       Do
          If Tmx > 0 Then
             Dir1 = 1
             Elseif Tmx < 0 Then
             Dir1 = 0
             Else
              Dir1 = 1
          End If


          Vrw = 0
          Do
             Stp1 = Not Stp1
             Waitms 2
             If Knx = 0 Then


                   If Dir1 = 0 Then
                      Dir1 = 0
                      For P = 1 To 150
                         Stp1 = Not Stp1
                         Waitms 20
                      Next P
                   End If
                   Exit Do

             End If

             Incr Vrw
          Loop Until Vrw = 1450




          Dir1 = Not Dir1
          Vrw = 0
          If Knx = 1 Then
             Do
                Stp1 = Not Stp1
                Waitms 2
                If Knx = 0 Then
                   If Dir1 = 0 Then
                      Dir1 = 0
                      For P = 1 To 150
                         Stp1 = Not Stp1
                         Waitms 20
                      Next P
                   End If
                   If Knx = 1 Then
                         Dir1 = 0
                         Vrw = 0
                         Do
                            Stp1 = Not Stp1
                            Waitms 10
                            If Knx = 0 Then Exit Do
                            Incr Vrw
                         Loop Until Vrw = 1450

                   End If
                   Exit Do
                End If
                Incr Vrw
             Loop Until Vrw = 1450
          End If
       Loop Until Knx = 0
    End If


    If Kny = 0 Then
      Dir2 = 1
      For P = 1 To 100
         Stp2 = Not Stp2
         Waitms 10
      Next P
    End If

   If Kny = 1 Then
      Do
         If Tmy > 0 Then
            Dir2 = 1
            Elseif Tmy < 0 Then
            Dir2 = 0
            Else
            Dir2 = 0

         End If
         Vrw = 0
         Do
            Stp2 = Not Stp2
            Waitms 2
            If Kny = 0 Then
               If Dir2 = 1 Then
                For P = 1 To 150
                   Stp2 = Not Stp2
                   Waitms 20
                Next P
               End If
               Exit Do
            End If

            Incr Vrw
         Loop Until Vrw = 1200

         Dir2 = Not Dir2
         Vrw = 0
         If Kny = 1 Then
            Do
               Stp2 = Not Stp2
               Waitms 2
               If Kny = 0 Then Exit Do
               Incr Vrw
            Loop Until Vrw = 1200
         End If
      Loop Until Kny = 0
   End If

   'X_a = 0
   'Y_a = 0
   'X = 0
   'Y = 0
   'X_b = 0
   'Y_b = 0

   Tmx = 0
   Tmy = 0
   'X = 0
   'Y = 0

   'Gx = 0
   'Gy = 0


   Tmpausx = 100
   Tmpausy = 100
   Speed_sys = 100
   'Powermoto = 0
Return

+5

2

Исходник рабочий))) Перегружал импульс реле клапана воды, заменил на транзистор и всё в норме.
Кратко:
Начальная точка
X_a = 405
X_b = 460

Конечная точка
Y_a = -260
Y_b = -355

Обязательные повторы для каждой оси:
Ciklix = 10
Cikliy = 0

Скорость каждой оси:
Tmpausx = 200
Tmpausy = 40

Общий замедлитель:
Speed_sys = 25

Клапан включается когда вместе с запуском уменьшения циклов - то-есть после выхода на нужную позицию.

Устройство простое, код легко адаптируется.

0

3

Я всё-же плату в LAY формате подготовлю сразу.
Вот думаю под Arduino Nano сделать? Тогда можно быстренько на PureBasic программу создать для программирования и отладки полива.

0

4

Ещё рабочий код с оптимизированным выходов в нулевую позицию:

Код:
$regfile = "m328pbdef.dat"
$crystal = 8000000
$hwstack = 196
$swstack = 196
$framesize = 196


'=================== Шаговые двигателя===============
Config Porte.0 = Output
Config Portb.6 = Output
Config Portb.7 = Output

Config Portb.1 = Output
Config Portb.2 = Output

Stpy Alias Portb.6
Diry Alias Portb.7

Stpx Alias Portb.1
Dirx Alias Portb.2
'Powermoto Alias Porte.0
'Config Porte.0 = Output

'Концевики
Kny Alias Pinc.4
Knx Alias Pinc.5
Config Portc.5 = Input
Config Portc.4 = Input

Clapan Alias Portd.6
Config Portd.6 = Output
Const Offclapan = 0
Const Onclapan = 1
'====================================================

'Powermoto = 0


Dim P As Byte
Dim O As Byte
'Dim I As Byte
Dim Tm As Byte
Dim Vrw As Word
'Dim Vrw2 As Word

Dim Ogrx As Word                                            'Const Ogrx = 300
Dim Ogry As Word                                            'Const Ogry = 300

Dim Tmpx As Word
Dim Tmpy As Word
'Числовая система координат INTEGER
Dim X As Integer
Dim Y As Integer

Dim Tmx As Integer
Dim Tmy As Integer

'===================================
Dim Vr_speed As Byte
Dim Tmpausy As Byte
Dim Tmpausx As Byte
Dim Speed As Byte
Dim Speed_sys As Byte


Dim Tm_null As Word



Dim Gx As Byte
Dim Gy As Byte
Dim Ciklix As Word
Dim Cikliy As Word
'Dim Tm_cikli As Byte

Dim Trigx As Byte
Dim Trigy As Byte

Dim X_a As Integer
Dim Y_a As Integer
Dim X_b As Integer
Dim Y_b As Integer
Dim Vri As Integer

Dim Pozicia As Byte

Dim Adrs As Byte
Adrs = 0

Goto Prog:
'======================== Программа цикличного полива



Programma:
  Select Case Adrs
      Case 0                                                'Полив дальних кустов 3 подъезд  урна
'(
            X_a = 325
            X_b = 348

            Y_a = -310
            Y_b = -280

            Ciklix = 5
            Cikliy = 0

            Tmpausx = 250
            Tmpausy = 250
            Speed_sys = 30
            Wait 2
')          adrs=0

      Case 1                                                'Полив дальних кустов 3 подъезд
           X_a = 405
           X_b = 460

           Y_a = -265
           Y_b = -353

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 200
           Tmpausy = 40
           Speed_sys = 25
        Case 2                                              'Клумба у 3 подъезда
           X_a = 80
           X_b = 380

           Y_a = -560
           Y_b = -640

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 80
           Tmpausy = 12
           Speed_sys = 25


        Case 3                                              'Распрыскивание над черёмухой
           X_a = 15
           X_b = 370

           Y_a = -70
           Y_b = -170

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 15
           Tmpausy = 15
           Speed_sys = 30


        Case 4
            X_a = 240
            X_b = 200

            Y_a = -410
            Y_b = -420

            Ciklix = 50
            Cikliy = 0

            Tmpausx = 20
            Tmpausy = 55
            Speed_sys = 30



        Case 5                                              'Первая часть под черёмухой
           X_a = 50
           X_b = 235

           Y_a = -430
           Y_b = -510

           Ciklix = 10
           Cikliy = 0

           Tmpausx = 200
           Tmpausy = 10
           Speed_sys = 25

        Case 6                                              'Вторая часть под черёмухой
           X_a = 40
           X_b = 130

           Y_a = -450
           Y_b = -400

           Ciklix = 15
           Cikliy = 0

           Tmpausx = 80
           Tmpausy = 40
           Speed_sys = 40

        Case 7                                              'Кусты у 2 подъезда
           'Gosub Null
           Vri = 0
           X_a = -210
           X_b = -40

           Y_a = -270
           Y_b = -370

           Ciklix = 20
           Cikliy = 0

           Tmpausx = 130
           Tmpausy = 20
           Speed_sys = 20
        Case 8                                              'Кусты у 2 подъезда
           'Gosub Null
           Vri = 0
           X_a = -210
           X_b = -30

           Y_a = -270
           Y_b = -330

           Ciklix = 0
           Cikliy = 30

           Tmpausx = 40
           Tmpausy = 40
           Speed_sys = 60
        Case 9                                              'куст у подъезда

           X_a = -300
           X_b = -310

           Y_a = -65
           Y_b = -165

           Ciklix = 20
           Cikliy = 0

           Tmpausx = 100
           Tmpausy = 40
           Speed_sys = 80
        Case 10                                             'Папортник

           X_a = -250
           X_b = -120

           Y_a = -495
           Y_b = -560

           Ciklix = 25
           Cikliy = 0

           Tmpausx = 40
           Tmpausy = 30
           Speed_sys = 25
        Case 11                                             'Куст у урны у 2 подъезда

           X_a = -180
           X_b = -50

           Y_a = -125
           Y_b = -190

           Ciklix = 20
           Cikliy = 0

           Tmpausx = 80
           Tmpausy = 100
           Speed_sys = 25

        Case 12                                             'Два куста у папортника

           X_a = -210
           X_b = -280
           Y_a = -370
           Y_b = -560

           Ciklix = 20
           Cikliy = 0

           Tmpausx = 250
           Tmpausy = 20
           Speed_sys = 25
        Case 13                                             'Дождь

           X_a = 280
           X_b = -200
           Y_a = -50
           Y_b = -210
           Ciklix = 15
           Cikliy = 0
           Tmpausx = 30
           Tmpausy = 10
           Speed_sys = 20

        Case 14                                             'переход перед выходом в ноль

           X_a = 100
           X_b = 100
           Y_a = -20
           Y_b = -20
           Ciklix = 1
           Cikliy = 0
           Tmpausx = 60
           Tmpausy = 80
           Speed_sys = 30
           Adrs = 0
   End Select

Return

Const Nlx = 0
Const Npx = 1

Const Knxon = 0
Const Knxoff = 1

Const Nly = 0
Const Npy = 1

Const Knyon = 0
Const Knyoff = 1
Null:
    Clapan = Offclapan
    Gx = 0
    Gy = 0
    If Knx = Knxon Then
               Dirx = Nlx                                   'Съезд с концевика
               For P = 1 To 50
                  Stpx = Not Stpx
                  Waitms 10
               Next P
               Dirx = Npx
    End If

    If Knx = Knxoff Then


          'Проверка положения для ускорения выхода в ноль за счёт значения координат и нужного направления

          If Tmx => 0 Then
             Dirx = Npx
             Elseif Tmx < 0 Then
             Dirx = Nlx
             'Else
              'Dir1 = 1                                      ' Выбирается направление движения в случае квантовой предсказуемости
          End If
      Wait 2
          '=====Поиск
      Do

          If Knx = Knxoff Then
                      Vrw = 0
                      Do
                         Stpx = Not Stpx
                         Waitms 5
                         If Knx = Knxon Then

                              Dirx = Nlx                    'Съезд с концевика
                              For P = 1 To 60
                                 Stpx = Not Stpx
                                 Waitms 5
                              Next P

                              Wait 1

                              Dirx = Npx

                              For P = 1 To 80
                                 Stpx = Not Stpx
                                 Waitms 20
                                 If Knx = Knxon Then
                                     Gx = 1
                                     Exit For

                                 End If

                              Next P

                              Exit Do
                         End If

                         Incr Vrw
                      Loop Until Vrw = 850

          End If

          If Knx = Knxoff Then
             Dirx = Not Dirx
             Else
               Exit Do
          End If
      Loop Until Gx = 1

    End If


    Gy = 0

    If Kny = Knyoff Then

        If Tmy > 0 Then
             Diry = Npy
             Elseif Tmy <= 0 Then
             Diry = Nly
        End If

          '=====Поиск
      Do

         If Kny = Knyoff Then
                      Vrw = 0
                      Do
                         Stpy = Not Stpy
                         Waitms 5
                         If Kny = Knyon Then

                              Diry = Nly                    'Съезд с концевика
                              For P = 1 To 30
                                 Stpy = Not Stpy
                                 Waitms 5
                              Next P
                              Diry = Npy
                              O = 0
                              For P = 1 To 50
                                 Stpy = Not Stpy
                                 Waitms 20
                                 If Kny = Knyon Then
                                    Gy = 1
                                    Exit For
                                 End If

                              Next P

                              Exit Do
                         End If

                         Incr Vrw
                      Loop Until Vrw = 800

                      If Kny = Knyoff Then
                        Diry = Not Diry
                        Else
                           Exit Do
                      End If
         End If


      Loop Until Gy = 1

   End If

   'X_a = 0
   'Y_a = 0
   'X = 0
   'Y = 0
   'X_b = 0
   'Y_b = 0

   Tmx = 0
   Tmy = 0
   'X = 0
   'Y = 0

   'Gx = 0
   'Gy = 0


   Tmpausx = 100
   Tmpausy = 100
   Speed_sys = 100
   'Powermoto = 0
Return




Prog:


X_b = 0
Y_b = 0
X_a = 0
Y_a = 0

'Gosub Null

Pozicia = 0
Clapan = Offclapan
Speed_sys = 100
Speed = 80
Ciklix = 0
Cikliy = 0


Do



   If Speed > 0 Then
      Decr Speed
      Else
         If Pozicia = 2 Then
            Speed = Speed_sys
            Else
            Speed = 20
         End If


        If Tmpx = 0 Then

               If X > Tmx Then
                      Dirx = 0
                      Incr Tmx
                      Gx = 0
                      Stpx = Not Stpx
                      If Pozicia = 2 Then
                           Tmpx = Tmpausx
                           Else
                           Tmpx = 30
                        End If

                      Elseif X < Tmx Then
                        Dirx = 1
                        Gx = 0
                        Stpx = Not Stpx
                        Decr Tmx

                        If Pozicia = 2 Then
                           Tmpx = Tmpausx
                           Else
                           Tmpx = 30
                        End If

                      Else
                        Gx = 1
                        Trigx = Not Trigx

                        If Trigx = 0 Then
                           X = X_a
                           Else
                              X = X_b
                              Select Case Pozicia
                                 Case 0
                                    Pozicia = 1
                                 Case 2
                                    If Ciklix > 0 Then
                                       Decr Ciklix
                                    End If
                              End Select

                        End If

               End If

           Else
              If Tmpx > 0 Then Decr Tmpx

        End If


        If Tmpy = 0 Then

              If Y > Tmy Then
                      Diry = 0
                      Incr Tmy
                      Stpy = Not Stpy
                      Gy = 0
                      If Pozicia = 2 Then
                           Tmpy = Tmpausy
                           Else
                              Tmpy = 30
                        End If

                      Elseif Y < Tmy Then
                        Diry = 1
                        Stpy = Not Stpy
                        Decr Tmy
                        Gy = 0
                        If Pozicia = 2 Then
                           Tmpy = Tmpausy
                           Else
                              Tmpy = 30
                        End If
                      Else
                             Gy = 1
                             Trigy = Not Trigy

                             If Trigy = 0 Then

                                   Y = Y_a

                                   Else
                                      Y = Y_b
                                      Select Case Pozicia
                                       Case 1
                                         Pozicia = 2
                                         Clapan = Onclapan
                                       Case 2
                                         If Cikliy > 0 Then
                                          Decr Cikliy       'Цикли шагов двигателей
                                         End If
                                      End Select
                             End If
                             Tmpy = Tmpausy
              End If

         Else
            If Tmpy > 0 Then Decr Tmpy
        End If

   End If

   If Speed = 1 Then
   '=================================================================== Задатчик цикла
      If Ciklix = 0 And Cikliy = 0 Then

                Clapan = Offclapan                          'Получение новых значений по адресу ADRS
                Wait 1

                Gosub Null
                'Получение новых координат
                Gosub Programma:



               If Adrs < 250 Then Adrs = Adrs + 1

               Pozicia = 0
               Trigx = 0
               Trigy = 0
               X = X_a
               Y = Y_a
               Gx = 0
               Gy = 0


      End If
End If

Loop

End

0