Atxmega przerwania

Rodzina procesorów bogatszych w wiele nowych rozwiązań i dlatego warto po nie sięgnąć.
ODPOWIEDZ
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Atxmega przerwania

Post autor: Jacek » 05 mar 2022, 21:15

Witam w dokumencie który Bartek umieścił na forum w tym poście viewtopic.php?f=18&t=353
jest opisane jak ustawić zewnętrzne przerwania.

External Pin Interrupt
Example for using Pin 0 of Port E as external Interrupt on falling edge
At first enable the Interrupts:
  1. On Porte_int0 Port_e_int0__isr
  2. Enable Porte_int0 , Lo 'Enable this Interrupt as Lo Level Interrupt
  3. Enable Interrupts
Configure the Pin as Input:
  1. Config Pine.0 = Input 'Set PINE.0 as Input
  2. Porte_pin0ctrl = &B00_011_010 'Enable Pullup and reaction on falling edge
  3.                                       '^   ^
  4.                                       '^   Reaction on falling edge
  5.                                       '^
  6.                                       'Enable Pullup
Setup the Interrupt Mask:
  1. Porte_int0mask = &B0000_0001 'include PIN0 in INT0 Mask
After this you only need a Main Loop and of course an Interrupt Service Routine called
port_E_int0__isr
  1. 'Port E INT0 Interrupt Service Routine
  2. port_E_int0__isr:
  3. Set Pine_0_int_flag
  4. return
chciałbym zrobić to ale dla portu A.0 , ale wyskakuje mi błąd

Error : 41 Line : 759 Variable can not be used with SET [PINA_0_INT_FLAG] zmienna nie może być z SET.
Może ktoś wyjaśnić co mam źle.
pozdrawiam Jacek.
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Atxmega przerwania

Post autor: niveasoft » 08 mar 2022, 19:08

Cześć. Jakoś mi ten post umknął ale Forum mi go podświetliło na czerwono ;)

Sprawa nie jest skomplikowana. Tamten poradnik był chyba pisany na jakąś Xmegę która miała swoją płytkę Xplained i była jako pierwsza w ogóle wdrażana.
Przez to pewnie miała dużo więcej Aliasów w pliku DAT. W takim pliku DAT pewnie pisało, że "Pine_0_int_flag" to nic innego jak PORTE_INTFLAGS.0 dlatego tam to działało. Porobili sobie skróty.

Ty musisz odwołać się do odpowiedniego rejestru kontrolującego flagi w danym porcie i wybrać bit zero. Czyli PORTA_INTFLAGS.0

Ten kod poniżej kompiluje się bez błędu.
  1. $regfile = "xm128a3udef.dat"
  2. $crystal = 32000000                                         '32MHz
  3. $hwstack = 80                                               'this is for my other tasks so
  4. $swstack = 100                                              'you can modify values to your needs
  5. $framesize = 100
  6.  
  7.  Config Submode = New
  8.  
  9. ' ***************** SYSTEM CLOCK CONFIG **************************
  10. '                INTERNAL 32MHz NO PRESCALE
  11. '
  12. Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled
  13. Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
  14. '
  15. ' ENABLING AUTOMATIC OSCILLATOR CALIBRATION
  16.     Osc_dfllctrl.0 = 1
  17.      Dfllrc32m_ctrl.0 = 1
  18. '
  19. '*****************************************************************
  20.  
  21.  Config Pina.0 = Input
  22.  Porta_pin0ctrl = &B00_011_010
  23.  
  24.  Porta_int0mask = &B0000_0001                               'include PIN0 in INT0 Mask
  25.  
  26. On Porta_int0 Port_a_int0__isr
  27.  Enable Porta_int0 , Lo
  28.   Enable Interrupts
  29.  
  30. Do
  31.  
  32. Loop
  33. End
  34.  
  35. Const Pina_0_int_flag = 0
  36.  
  37. Port_a_int0__isr:
  38.   Set Porta_intflags.pina_0_int_flag
  39. Return
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Atxmega przerwania

Post autor: Jacek » 08 mar 2022, 21:40

Dziękuję Bartek teraz nie ma błędu.
Chciałbym wykorzystać to przerwanie ponieważ obrotomierz do tokarki który ma działać na xmedze słabo mi wychodzi.
Kiedyś zamieściłem na tym forum program obrotomierza ale na Atmega32 viewtopic.php?f=3&t=362&p=2958&hilit=TYTAN+750#p2958
i ten program działa bardzo dobrze, różnica między programem a fabrycznym obrotomierzem wynosi kilka obr/min przy ponad 1700obr/min
  1.  
  2. 'PROGRAM OBROTOMNIERZA DO TOKATKI
  3. 'TYTAN 750 WYKORZYSTAŁEM PROCEDURY
  4. 'ZAMIESZCZONE PRZEZ KOLEGÓW Z FORUM
  5. '  https://bart-projects-forum.cba.pl
  6. $regfile = "m644pdef.dat"                                                       '"m32def.dat"
  7. $crystal = 16000000
  8. $hwstack = 255
  9. $swstack = 128
  10. $framesize = 128
  11. Config Submode = New
  12.  
  13. '--------------------------------------------------------------------
  14. $projecttime = 57
  15. $version 0 , 0 , 298
  16. Dim Firmware As String * 32
  17. Firmware = "Obrotomierz TYTAN 750"
  18. 'Debug Off
  19. Debug On
  20. '-------------------------------------------------------------------
  21. 'KONFIGURACJA TIMERA
  22. Config Timer1 = Timer , Prescale = 8
  23. On Timer1 Przertimer1
  24. Enable Timer1
  25. '--------------------------------------------------------------------
  26. 'KONFIGURACFJA ENKODERA
  27. 'Config Int0 = Falling
  28. 'On Int0 Enkoder
  29. 'Enable Int0
  30. '--------------------------------------------------------------------
  31. 'Enable Interrupts
  32. '--------------------------------------------------------------------
  33. 'KONFIGURACJA LCD
  34. Config Lcdpin = Pin , Rs = Porta.0 , E = Porta.1 , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5
  35. Config Lcd = 16x4
  36. '--------------------------------------------------------------------
  37.  
  38. 'KONFIGURACJA PORTÓW
  39. Config Portd.2 = Input : Portd.2 = 1                                            'enkoder kanał A
  40. Config Portd.3 = Input : Portd.3 = 1                                            'enkoder kanał B
  41. Config Portd.6 = Output : Portd.6 = 1                                           'LED Live
  42. Config Portb.0 = Input                                                          ': Pinb.0 = 1                         'sw_menu
  43. Config Portb.1 = Input :                                                        'sw_zero_kąt
  44.  
  45. Portb = &B11111111
  46. '--------------------------------------------------------------------
  47. 'ALIASY PORTÓW
  48. Kanal_a Alias Pind.2
  49. Kanal_b Alias Pind.3
  50. Led_live Alias Portd.6
  51. Sw_menu Alias Pinb.0
  52. Sw_zero_kat Alias Pinb.1
  53. '--------------------------------------------------------------------
  54. 'ZMIENNE ENKODERA
  55. Dim En_impuls As Long                                                           'zmienna przechowywujaca impulsy z enkodera
  56. '--------------------------------------------------------------------
  57. 'ZMIENNE CZASU
  58. Dim Timer_tikx10 As Byte                                                        'zmienna liczaca przepełnienie timera
  59. Dim Timertikx100 As Byte                                                        'zmienna liczaca przepełnienie timera x10
  60. Dim Timertikx200 As Byte                                                        'zmienna liczaca przepełnienie timera x 20
  61. Dim Timertikx500 As Byte                                                        'zmienna liczaca przepełnienie timera x 50
  62. Dim Timer_tik_flag As Byte
  63. Flaga10ms Alias Timer_tik_flag.0
  64. Flaga100ms Alias Timer_tik_flag.1
  65. Flaga500ms Alias Timer_tik_flag.2
  66. Flaga1s Alias Timer_tik_flag.3
  67. Flaga2s Alias Timer_tik_flag.4
  68. Flaga2_5s Alias Timer_tik_flag.5
  69.  'zostaly jeszce trzy wolne flagi
  70.  ' a uzylem tylko jednego bajtu
  71. '####################################################################
  72. 'ZMIENNE POMIARU OBROTÓW
  73. Dim Pomiar1 As Single                                                           'zmienna pomocnicza1
  74. Dim Pomiar2 As Single                                                           'zmienna pomocnicza2
  75. Dim Pomiar3 As Single                                                           'zmienna pomocnicza3
  76. Dim Wynik As String * 5                                                         'zmienna pomocnicza4
  77. Dim Wynik1 As Long
  78. '-----------------------------------------------------------------------
  79. 'ZMIENNE POMIARU KĄTA
  80. Dim Kat_ As Word
  81. Dim Kat_1 As Single
  82. '-----------------------------------------------------------------------
  83. 'ZMIENNE MENU
  84. Dim Poz_menu As Byte                                                            'zmienna menu
  85. Dim Wyswietl_ As Byte                                                           'zmiennawyboru wyświetlania
  86. Dim Flaga_ustaw As Bit
  87. Dim Poz_ustaw As Byte
  88. '--------------------------------------------------------------------
  89. 'ZMIENNE PRZYCISKU ENKODERA
  90. Dim Sw_cnt As Word
  91. Dim Lock As Byte
  92. '----------------------------------------------------------------------------
  93. $include "subs\mruganie.inc"
  94. $include "subs\wyswietl.inc"
  95. $include "subs\pomiar.inc"
  96. '-------------------------------------------------------------------
  97. 'Enable Interrupts
  98. '----------------------------------------------------------------------------
  99. 'KONFIGURACFJA ENKODERA
  100. Config Int0 = Falling
  101. On Int0 Enkoder
  102. Enable Interrupts
  103. Enable Int0
  104. Waitms 500
  105. Cursor Off , Noblink
  106. Cls
  107. Poz_menu = 0
  108. Wait 1
  109. Locate 1 , 4 : Lcd "TYTAN  750"
  110. Locate 2 , 3 : Lcd "OBROTOMIERZ"
  111. Locate 3 , 6 : Lcd "POMIAR"
  112. Locate 4 , 3 : Lcd "KATA  OBROTU"
  113. Wait 5
  114. Cls
  115. '----------------------------------------------------------------------------
  116. Do
  117. '====================================================================
  118.    If Timer_tikx10 >= 10 Then                                                   'jeśli uplyneło 100ms to
  119.       Flaga100ms = 1                                                            'ustaw flage upłyneło 100ms
  120.       Incr Timertikx100                                                         'zwiększaj Timertikx100
  121.       Timer_tikx10 = 0                                                          'zeruj liczenie
  122.    End If                                                                       'koniec warunku
  123.    If Timertikx100 >= 10 Then                                                   'jeśli uplynela sekunda
  124.       Flaga1s = 1                                                               'ustaw flage upłyneła sekunda
  125.       Incr Timertikx200                                                         'zwiększaj Timertikx200
  126.       Incr Timertikx500
  127.       Timertikx100 = 0                                                          'zeruj liczenie
  128.    End If                                                                       'koniec warunku
  129.    If Timertikx200 >= 2 Then                                                    'jeśli upłyneły dwie sekundy
  130.       Flaga2s = 1                                                               'ustaw flagę upłyneły dwie sekundy
  131.       Timertikx200 = 0                                                          'zeruj liczenie
  132.    End If                                                                       'koniec warunku
  133.    If Timertikx500 >= 5 Then
  134.       Flaga500ms = 1
  135.       Timertikx500 = 0
  136.    End If
  137.    '=====================================================================
  138.    If Flaga10ms = 1 Then                                                        'jeśli Flaga10ms jest równa 1
  139.       Flaga10ms = 0                                                             'wyzeruj Flaga10ms                                                            'dopisano 19.06.2018
  140.       If Sw_menu = 0 Then                                                       'jeśli wciśnięto przycisk
  141.          If Lock = 0 Then                                                       'a jeszcze nie ma blokady
  142.             If Sw_cnt < 50 Then                                                 'tu jesteśmy co 10ms i jeśli jeszcze nie osiągneliśmy granicy
  143.                Incr Sw_cnt                                                      'to dodajemy do licznika Sw_cnt
  144.             Else                                                                'jeśli granica osiągnięta
  145.                Lock = 1                                                         'zablokuj dodawanie aż do puszczenia przycisku
  146.                Toggle Flaga_ustaw                                               'Arduino_led                                                  '->zmień stan drugiej diody
  147.             End If
  148.          End If
  149.       Else                                                                      'kiedy zwalniamy przycisk
  150.          If Lock = 0 Then                                                       'a nie było to długie wciśnięcie
  151.             If Sw_cnt > 3 Then                                                  'sprawdź czy to nie drganie styków 3x10ms = 30ms
  152.                If Flaga_ustaw = 1 Then
  153.                   Incr Poz_ustaw
  154.                Else
  155.                   Incr Poz_menu
  156.                End If
  157.             End If
  158.          End If                                                                 '
  159.          Lock = 0 : Sw_cnt = 0                                                  'wyłącz blokadę i zeruj licznik
  160.       End If
  161.  
  162.    End If                                                                       'koniec warunku
  163. '---------------------------------------------------------------------------------------------------
  164.    If Flaga100ms = 1 Then                                                       'jeśli Flaga100ms jest równa 1
  165.       Flaga100ms = 0                                                            'wyzeruj Flaga100ms
  166.    End If                                                                       'koniec warunku
  167.   '--------------------------------------------------------------------------------------------------
  168.    If Flaga500ms = 1 Then                                                       'jeśli Flaga500ms jest równa 1
  169.       Flaga500ms = 0                                                            'wyzeruj Flaga500ms
  170.    End If                                                                       'koniec warunku
  171. '---------------------------------------------------------------------------------------------------
  172.    If Flaga1s = 1 Then                                                          'jeśli Flaga1s jest równa 1
  173.       call Mruganie
  174.       call Wyswietl
  175.       'call Pomiar
  176.       Pomiar1 = En_impuls / 720
  177.       Pomiar2 = Pomiar1 * 60
  178.       Pomiar3 = Pomiar2
  179.       En_impuls = 0
  180.       Flaga1s = 0                                                               'wyzeruj Flaga1s
  181.    End If                                                                       'koniec warunku
  182.  
  183. '---------------------------------------------------------------------------------------------------
  184.    If Flaga2s = 1 Then                                                          'jeśli Flaga2s jest równa 1
  185.       Flaga2s = 0                                                               'wyzeruj Flaga
  186.    End If
  187.                                                       'koniec warunku
  188. '==========================================
  189.    If Flaga_ustaw = 0 And Poz_menu = 0 Then
  190.       Wyswietl_ = 0
  191.    End If
  192.    If Flaga_ustaw = 0 And Poz_menu = 1 Then
  193.       Wyswietl_ = 1
  194.    End If
  195.    If Flaga_ustaw = 1 And Poz_ustaw = 0 Then
  196.       Wyswietl_ = 2
  197.    End If
  198.    If Flaga_ustaw = 1 And Poz_ustaw = 1 Then
  199.       Wyswietl_ = 3
  200.    End If
  201.    If Flaga_ustaw = 1 And Poz_ustaw = 2 Then
  202.       Wyswietl_ = 4
  203.    End If
  204.  
  205.    If Poz_ustaw = 3 Then
  206.       Poz_ustaw = 0
  207.    End If
  208.    If Poz_menu = 2 Then
  209.       Poz_menu = 0
  210.    End If
  211.  
  212. '==============================================
  213.    If Sw_menu = 0 Then
  214.       Poz_menu = Poz_menu + 1
  215.    End If
  216.  
  217.    If Poz_menu = 0 Then
  218.       Wyswietl_ = 0
  219.    End If
  220.    If Poz_menu = 1 Then
  221.       Wyswietl_ = 1
  222.    End If
  223.    If Poz_menu => 2 Then
  224.       Poz_menu = 0
  225.    End If
  226.  
  227.    If Sw_zero_kat = 0 Then
  228.       Kat_1 = 0
  229.    End If
  230.  
  231.  
  232.    If Kat_ > 1000 Then                                                          '720 Then
  233.       Kat_ = 0
  234.    End If
  235.  
  236.    Kat_1 = Kat_                                                                 ' / 2 .7
  237.  
  238. Loop
  239. End
  240. '-----------------------------------------------------------------------------------------------------
  241. '            podprogram przerwań Timer1
  242. Przertimer1:
  243.    Timer1 = 45536                                                               'wstawienie do Timer1 wartości 45536
  244.  
  245.    Incr Timer_tikx10
  246.  
  247.    If Timer_tikx10 = 1 Then
  248.       Set Flaga10ms
  249.    End If
  250.  
  251. Return                                                                          'powrót
  252. '-----------------------------------------------------------------------------------------------------
  253. Enkoder:
  254.    Disable Int0
  255. 'Waitms 1
  256.    If Kanal_a = 0 Then
  257.       If Kanal_b = 0 Then
  258.          Incr En_impuls
  259.          Incr Kat_
  260.       'Else
  261.        ' Decr Kat_
  262.       End If
  263.    End If
  264.    Enable Int0
  265. Return
  266. '--------------------------------------------------------------------
Czy powinienem usunąć linię
  1. '**********************************Enkoder obrotów wrzeciona******
  2. Config Event_system = Dummy , Mux0 = Porta.0 , Qd0 = Enabled , Digflt0 = 8
  3. 'Config Event_system = Dummy , Mux0 = Porta.0 , Qd0 = Enabled , Qdi0 = Enabled , Qdirm0 = 2 , Digflt0 = 8
  4. Config Tce0 = Normal , Prescale = E0 , Event_source = E0 , Event_action = Qdec
z konfiguracji xmegi.

pozdrawiam Jacek.
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Atxmega przerwania

Post autor: Jacek » 14 mar 2022, 8:47

Witam czy zawyżony wynik w tym programie jest spowodowany złym przeliczaniem impulsów.
  1.  
  2. $regfile = "xm128a3udef.dat"
  3. $crystal = 32000000                                                             '32MHz
  4. $hwstack = 80                                                                   'this is for my other tasks so
  5. $swstack = 100                                                                  'you can modify values to your needs
  6. $framesize = 100
  7. Debug On
  8. Config Submode = New
  9. $projecttime = 37
  10. $version 0 , 0 , 10
  11. Dim Firmware As String * 32
  12. Firmware = "OBROTOMIERZ Xmega128A3U"
  13. Const Max_usb_in_command_len = 50
  14. Const Max_nex_command_len = 50
  15. ' ***************** SYSTEM CLOCK CONFIG **************************
  16. '                INTERNAL 32MHz NO PRESCALE
  17. Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled
  18. Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
  19. ' ENABLING AUTOMATIC OSCILLATOR CALIBRATION
  20. Osc_dfllctrl.0 = 1
  21. Dfllrc32m_ctrl.0 = 1
  22. '*****************************************************************
  23. '********************** CLOCK CONFIG *******************************************
  24. ' we select the internal 1 KHz clock from the 32khz Internal Oscillator
  25. Config Clock = Soft , Rtc = 1khz_int32khz_rcosc
  26. Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled  ' the RTC uses LO priority
  27. '****************************************************************
  28. '********************TIMER ODLICZAJĄCY 1ms*******************
  29. Config Tcf0 = Normal , Prescale = 256
  30. Tcf0_per = 125
  31. '******************************************************************
  32. '*******************KONFIGURACJA PAMIĘCI EEPROM************************
  33. Config Eeprom = Mapped                                                          'Setup memory mode for EEPROM in XMEGA
  34. 'Const Updateeprom =
  35. '************ CONFIGURATION FOR COM1 UART_C0************************************
  36. '                ' TX-PORTC.3  RX-PORTC.2   com 2 tcp
  37. Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  38. 'Open "COM1:" For Binary As #buart_channel                   'no need to open any more
  39. Config Serialin0 = Buffered , Size = 128 , Bytematch = None                     'for COM1
  40. Config Serialout0 = Buffered , Size = 128
  41. Open "COM1:" For Binary As #1
  42.    'Config Input1 = Crlf , Echo = Cr
  43.   'Echo On
  44. '
  45. '*******************************************************************************
  46. '*********** CONFIGURATION FOR COM2 UART_C1*************************************
  47. '              ' TX-PORTC.7 RX-PORTC.6  (udp com 1 )
  48. 'Config Com2 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  49. 'Open "COM2:" For Binary As #buart_channel
  50.                                'no need to open any more
  51. 'Config Serialin1 = Buffered , Size = 128 , Bytematch = None 'for COM2
  52. 'Config Serialout1 = Buffered , Size = 128
  53. 'Open "COM2:" For Binary As #1
  54. ' Config Input2 = Cr , Echo = Cr
  55.   'Echo On
  56. '*******************************************************************************
  57. '************ CONFIGURATION FOR COM3 UART_D0************************************
  58. '             ' TX-PORTD.3 RX-PORTD.2    wifi
  59. 'Config Com3 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  60. 'Open "COM3:" For Binary As #buart_channel                   'no need to open any more
  61. 'Config Serialin2 = Buffered , Size = 128 , Bytematch = None 'for COM1
  62. 'Config Serialout2 = Buffered , Size = 128
  63. 'Open "COM3:" For Binary As #2
  64. 'Echo On
  65. '
  66. '*******************************************************************************
  67. '************ CONFIGURATION FOR COM4 UART_D1************************************
  68. '             ' TX-PORTD.3 RX-PORTD.2    wifi
  69. 'Config Com4 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  70. 'Open "COM3:" For Binary As #buart_channel                   'no need to open any more
  71. 'Config Serialin3 = Buffered , Size = 128 , Bytematch = None 'for COM1
  72. 'Config Serialout3 = Buffered , Size = 128
  73. 'Open "COM4:" For Binary As #3
  74. 'Echo On
  75. '
  76. '*******************************************************************************
  77. '************ CONFIGURATION 'COM5 UART_E0 **************************************
  78. '              ' TX-PORTE.3 ' RX-PORTE.2   DEBUG USB COM5
  79. Config Com5 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8       'Asynchroneous
  80. Config Serialin4 = Buffered , Size = Max_usb_in_command_len                     '128 , Bytematch = None                     'for COM4
  81. 'Config Serialout4 = Buffered , Size = Max_usb_out_command_len                   '128
  82. Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
  83. Dim Command1 As String * Max_usb_in_command_len
  84. Open "COM5:" For Binary As #4
  85. Const Usb = 4
  86.    'Config Input1 = Crlf , Echo = Cr
  87.   ' Echo on
  88. '
  89. '*******************************************************************************
  90. '************ CONFIGURATION 'COM6 UART_E1 **************************************
  91. '              ' TX-PORTE.3 ' RX-PORTE.2   Xmega_2_SLAVE
  92. 'Config Com6 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
  93.  'Open "COM5:" For Binary As #buart_channel                  'channel 4
  94. 'Config Serialin5 = Buffered , Size = 128 , Bytematch = None 'for COM4
  95. 'Config Serialout5 = Buffered , Size = 128
  96. 'Open "COM6:" For Binary As #5
  97.    'Config Input1 = Crlf , Echo = Cr
  98.   ' Echo on
  99. '
  100. '*******************************************************************************
  101. '************ CONFIGURATION 'COM5 UART_F0 **************************************
  102. '              ' TX-PORTE.3 ' RX-PORTE.2   NEXTION LCD COM7
  103. Config Com7 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8       'Asynchroneous
  104. Dim Cmd_timeout As Byte , Got_str As Byte
  105.     'unnecessary
  106. Dim Command As String * Max_nex_command_len
  107. Config Serialin6 = Buffered , Size = Max_nex_command_len                        'RX
  108. 'Config Serialout6 = Buffered , Size = 128
  109. Open "COM7:" For Binary As #6
  110. Const Nex = 6
  111. 'Config Input1 = Crlf , Echo = Cr
  112. ' Echo on
  113. '************************ZMIENNE TIMER'a TCF0*****************
  114. Dim Timer_tikx1 As Byte
  115. Dim Timer_tikx10 As Byte
  116. Dim Timer_tikx50 As Byte
  117. Dim Timer_tikx100 As Byte
  118. Dim Timer_tikx500 As Byte
  119. Dim Timer_tikx1000 As Byte
  120. Dim Timer_tik_flag As Byte
  121. '**********************************************************
  122. Config Pina.0 = Input
  123. Config pina.1 = Input
  124. '-----------------------------------------------------------------------------------
  125. Config Portb.7 = Output                                                         'LED_LIVE TEST
  126. Config Xpin = Portb.7 , Outpull = Totem
  127. '------------------------------------------------------------------------------------
  128. 'ZMIENNE ENKODERA
  129. Dim En_impuls As Long                                                           'zmienna przechowywujaca impulsy z enkodera
  130. Dim Pomiar1 As Single                                                           'zmienna pomocnicza1
  131. Dim Pomiar2 As Single                                                           'zmienna pomocnicza2
  132. Dim Pomiar3 As Single
  133. Dim Wynik As String * 5                                                         'zmienna pomocnicza4
  134. Dim Wynik1 As Long
  135. '**************ALIASY*********************
  136. Flaga1ms Alias Timer_tik_flag.0
  137. Flaga10ms Alias Timer_tik_flag.1
  138. Flaga50ms Alias Timer_tik_flag.2
  139. Flaga100ms Alias Timer_tik_flag.3
  140. Flaga500ms Alias Timer_tik_flag.4
  141. Flaga1s Alias Timer_tik_flag.5
  142. Flaga2s Alias Timer_tik_flag.6
  143. Led_live Alias Portb.7
  144. '**************************************************
  145. Porta_pin0ctrl = &B00_011_010
  146.  
  147. Porta_int0mask = &B0000_0001                                                    'include PIN0 in INT0 Mask
  148.  
  149. On Porta_int0 Port_a_int0__isr
  150. Enable Porta_int0 , Lo
  151. Enable Interrupts
  152. '****************************************************************
  153. Print #usb , "This use COM4"                                                    'print current Uart
  154. Print #usb , "MCU Rev. = " ; Mcu_revid                                          'version of the MCU
  155. '****************************************************************
  156. Do
  157.  
  158. '------------------------------------------------
  159.    If Tcf0_intflags.0 = 1 Then
  160.       Flaga1ms = 1
  161.       Incr Timer_tikx1
  162.       Tcf0_intflags.0 = 1
  163.    End If
  164. '------------------------------------------------
  165.    If Timer_tikx1 >= 10 Then
  166.       Incr Timer_tikx10
  167.       Flaga10ms = 1
  168.       Timer_tikx1 = 0
  169.    End If
  170. '------------------------------------------------
  171.    If Timer_tikx10 >= 5 Then
  172.       Incr Timer_tikx50
  173.       Flaga50ms = 1
  174.       Timer_tikx10 = 0
  175.    End If
  176. '------------------------------------------------
  177.    If Timer_tikx50 >= 2 Then
  178.       Incr Timer_tikx100
  179.       Flaga100ms = 1
  180.       Timer_tikx50 = 0
  181.    End If
  182. '------------------------------------------------
  183.    If Timer_tikx100 >= 5 Then
  184.       Incr Timer_tikx500
  185.       Flaga500ms = 1
  186.       Timer_tikx100 = 0
  187.    End If
  188. '------------------------------------------------
  189.    If Timer_tikx500 >= 2 Then
  190.       Incr Timer_tikx1000
  191.       Flaga1s = 1
  192.       Timer_tikx500 = 0
  193.    End If
  194. '======================================
  195.    If Flaga1ms = 1 Then
  196.  
  197.    End If
  198. '------------------------------------------------
  199.    If Flaga10ms = 1 Then
  200.       Flaga10ms = 0
  201.    End If
  202. '------------------------------------------------
  203.    If Flaga100ms = 1 Then
  204.       Flaga100ms = 0
  205.    End If
  206. '-----------------------------------------------
  207.    If Flaga500ms = 1 Then
  208.       Toggle Led_live
  209.       Flaga500ms = 0
  210.    End If
  211. '------------------------------------------------
  212.    If Flaga1s = 1 Then
  213.       Debug #usb , "En_impuls " ; En_impuls
  214.       Pomiar1 = En_impuls / 1000
  215.       Pomiar2 = Pomiar1 * 60
  216.       Pomiar3 = Pomiar2
  217.       Debug #usb , "wynik " ; wynik
  218.       Debug #usb , "OBR/MIN " ; Wynik1
  219.       En_impuls = 0
  220.       Flaga1s = 0
  221.    End If
  222. '****************************************************************
  223.    Wynik = Str(pomiar3)
  224.    Wynik = Fusing(pomiar3 , "###.#")
  225.    Wynik1 = Val(wynik)
  226. Loop
  227. End
  228. '****************************************************************
  229. Const Pina_0_int_flag = 0
  230.  
  231. Port_a_int0__isr:
  232.  
  233.    Set Porta_intflags.pina_0_int_flag
  234.    If pina.0 = 0 Then
  235.       If pina.1 = 0 Then
  236.          Incr En_impuls
  237.       End If
  238.    End If
  239.  
  240. Return
  241.  

W porównaniu do fabrycznego obrotomierza który posiadam przy obrotach rzędu 500 obr/min program pokazuje kilka obrotów więcej.
pozdrawiam Jacek.
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Atxmega przerwania

Post autor: niveasoft » 14 mar 2022, 9:16

Przy ustawianiu Timera ZAWSZE się odejmuje jeden takt zegara. Przy 32MHz i 1ms timer powinien mieć 124 a nie 125. Może to to.
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Atxmega przerwania

Post autor: Jacek » 14 mar 2022, 9:19

Dzięki Bartku jak wrócę do lekarza to załaduje na nowo do xmegi poprawiony program.
pozdrawiam Jacek.
ODPOWIEDZ