Witam
Panowie , a możecie podpowiedzieć jak taki enkoder zmajstrować w oparciu o atmega 8 ?
Próbowałem zgłębiać przykłady Bartka ze strony domowej , tylko nie wiem jak wysłać te impulsy na port .
Moje nisko budżetowe cnc powoli powstaje
Na początek chciałbym sterować tym ustrojstwem ręcznie nim zacznę z Linux cnc ( jest już zainstalowany na starym laptopie ) .
Encodery jeszcze raz
- Henryk
- Posty: 348
- Rejestracja: 22 sty 2018, 17:20
Encodery jeszcze raz
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
- niveasoft
- Posty: 1216
- Rejestracja: 17 sie 2015, 12:13
- Kontakt:
Re: Xmega sprzętowa obsługa enkodera -to takie proste
Tak dopiero teraz zauważyłem, że na stronie obiecałem zamieścić mój uniwersalny kod do enkoderów (taki kuloodporny), ale na Forum chyba go nie ma
Co ciekawe widziałem ten kod już na Elektrodzie - jakiś klient go tam sobie beztrosko umieścił.
Kod najlepiej się sprawdza na przerwaniach PCINT więc Mega8 odpada. Chcac mieć trzy enkodery najlepiej każdy oprogramować na oddzielnym porcie PORTB, PORTC i PORTD. Tak więc najmniejsza to chyba Mega88 a potem najtańsza Mega328P...
Kod zamieszczę później.
Co ciekawe widziałem ten kod już na Elektrodzie - jakiś klient go tam sobie beztrosko umieścił.
Kod najlepiej się sprawdza na przerwaniach PCINT więc Mega8 odpada. Chcac mieć trzy enkodery najlepiej każdy oprogramować na oddzielnym porcie PORTB, PORTC i PORTD. Tak więc najmniejsza to chyba Mega88 a potem najtańsza Mega328P...
Kod zamieszczę później.
- Henryk
- Posty: 348
- Rejestracja: 22 sty 2018, 17:20
Re: Xmega sprzętowa obsługa enkodera -to takie proste
Mega 328P mam
Na chwilę obecną obszedłem temat podczerwienią , prostym " baranim " sposobem .
Działa , tylko silnik kreci powoli
Na chwilę obecną obszedłem temat podczerwienią , prostym " baranim " sposobem .
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m8def.dat"
- $crystal = 8000000
- $hwstack = 64
- $swstack = 36
- $framesize = 64
- 'Config Lcd = 20 * 4
- Config Portb = &B11111111 : Portb = &B11111111
- Config Portd = &B11110011 : Portd = &B11111111
- 'Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
- 'Cursor Off
- 'Cls
- Config Timer1 = Timer , Prescale = 1024 , Clear_timer = 1
- Compare1a = 77 '10ms @8MHz/1024
- Config Timer0 = Timer , Prescale = 256 '8000000/256=31250 Hz
- Config Int1 = Falling 'Interruption on Falling
- Stop Timer0
- Enable Timer0
- Enable Int1
- Enable Interrupts
- On Timer0 Tikers 'work on timer
- On Int1 Infrared
- Led_0 Alias Portb.0
- Led_1 Alias Portb.1
- Led_2 Alias Portb.2
- Led_3 Alias Portb.3
- Led_4 Alias Portb.4
- Led_5 Alias Portb.5
- Led_6 Alias Portb.6
- Led_7 Alias Portb.7
- 'work on interruption
- 'Dim Got As Byte
- dim spid as word
- Dim Tik As Word 'counter of teaks of timer
- Dim Byt As Byte 'counter accepted bit
- Dim Repeat_flag As Byte 'flag of repetition
- Dim Start_flag As Byte 'flag of start condition
- Dim Address_1 As Byte 'direct byte of address
- Dim Command_1 As Byte 'direct byte of command
- Dim Address_0 As Byte 'indirect byte of address
- Dim Command_0 As Byte 'indirect byte of command
- Dim Summa As Word
- Dim Address_nec As Byte , Command_nec As Byte
- spid = 50
- '################################################################################################################
- Do 'Main cycle
- 'If Got = 1 Then
- 'Cls
- 'Locate 1 , 1
- ' Lcd "Adr:" ; Address_nec
- ' Locate 2 , 1
- 'Lcd "Com:" ; Command_nec 'Lcd ADDRESS and COMMAND
- ' Reset Got
- ' End If
- If Address_nec <> 1 Then 'jeśli Wpisać "If Address=0 Then" to zawęzimy tylko do telewizorów
- Select Case Command_nec
- Case 32: 'przycisk X w LEWO
- Led_0 =0
- Pulseout Portb , 1 , spid
- Waitms 5
- Case 96: 'przycisk X w PRAWO
- set Led_0
- Pulseout Portb , 1 , spid
- Waitms 5
- Case 216: 'przycisk Y w TYL
- Led_2=0
- Pulseout Portb , 3 , spid
- Waitms 5
- Case 88: 'przycisk Y w PRZOD
- set Led_2
- Pulseout Portb , 3 , spid
- Waitms 10
- Case 16: 'przycisk CH1 - Z W DOL
- Led_4=0
- Pulseout Portb , 5 , spid
- Waitms 5
- Case 40: 'przycisk CH3 - Z W GORE
- SET Led_4
- Pulseout Portb , 5 , spid
- Waitms 5
- Case 80: 'przycisk pilota - 7
- Led_6=0
- Pulseout Portb , 7 , spid
- Waitms 10
- Case 104: 'przycisk pilota - 8
- SET Led_6
- Waitms 5
- CASE 8: 'mode - wolny
- waitms 5
- case 160: 'menu -wolny
- waitms 5
- Case 72:
- Set Led_0
- Set Led_1
- Set Led_2
- Set Led_3
- Set Led_4
- Set Led_5
- Set Led_6
- Set Led_7
- End Select
- End If
- Loop
- End 'End of main cycle
- '################################################################################################################
- Tikers: 'work on timer
- Timer0 = 253 '31250/(256-253)=10416,66 Hz (96 een)
- Incr Tik
- If Tik >= 1200 Then 'if 1200 teaks, have thrown all in source condition
- Tik = 0
- Repeat_flag = 0
- Start_flag = 0
- Address_1 = 255
- Command_1 = 255
- Address_0 = 0
- Command_0 = 0
- Address_nec = 255
- Command_nec = 255
- Stop Timer0
- End If
- Return
- '################################################################################################################
- Infrared: 'work on interruption
- Start Timer0
- If Tik >= 139 And Tik < 150 Then 'if has happenned from 139 before 150 teaks - "START"
- Address_nec = 1
- Repeat_flag = 0
- Start_flag = 1
- Address_1 = 255
- Command_1 = 255
- Address_0 = 0
- Command_0 = 0
- End If
- If Tik >= 116 And Tik < 139 Then 'if has happenned from 116 before 138 teaks - "REPETITION"
- Address_nec = 0
- Repeat_flag = 1
- Start_flag = 0
- End If
- If Tik >= 22 And Tik < 116 And Start_flag = 1 Then 'if has happenned from 22 before 115 teaks - have taken "1"
- Incr Byt
- If Byt < 9 Then
- Shift Address_1 , Left
- Address_1 = Address_1 + 1
- End If
- If Byt >= 9 And Byt < 17 Then
- Shift Address_0 , Left
- Address_0 = Address_0 + 1
- End If
- If Byt >= 17 And Byt < 25 Then
- Shift Command_1 , Left
- Command_1 = Command_1 + 1
- End If
- If Byt >= 25 Then
- Shift Command_0 , Left
- Command_0 = Command_0 + 1
- End If
- End If
- If Tik >= 10 And Tik < 22 And Start_flag = 1 Then 'if has happenned from 10 before 21 teaks - have taken "0"
- Incr Byt
- If Byt < 9 Then
- Shift Address_1 , Left
- End If
- If Byt >= 9 And Byt < 17 Then
- Shift Address_0 , Left
- End If
- If Byt >= 17 And Byt < 25 Then
- Shift Command_1 , Left
- End If
- If Byt >= 25 Then
- Shift Command_0 , Left
- End If
- End If
- Tik = 0
- If Byt = 32 Then
- Address_nec = Address_1
- Command_nec = Command_1
- 'Got = 1
- Address_1 = 255
- Command_1 = 255
- Byt = 0
- Repeat_flag = 0
- Start_flag = 0
- Stop Timer0
- End If
- Return
- Jacek
- Posty: 384
- Rejestracja: 25 kwie 2016, 19:14
Enkodery jeszcze raz
Witam napisałem taki program do testu obrotomierza tokarki
podprogramy
nie pamiętam z skąd mam obsługę enkodera ale to działa https://www.youtube.com/watch?v=qehq8E07sno
chciałem zrobić jeszcze pomiar kata obrotu - no ale przeszedłem na xmegę - ale będę chciał to zaincludować w projekcie sterownika tokarki ELS
pozdrawiam Jacek.
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m32def.dat"
- $crystal = 16000000
- $hwstack = 255
- $swstack = 128
- $framesize = 128
- Config Submode = New
- '--------------------------------------------------------------------
- $projecttime = 2
- $version 0 , 0 , 218
- Dim Firmware As String * 32
- Firmware = "Obrotomierz TYTAN 750"
- 'Debug Off
- Debug On
- '-------------------------------------------------------------------
- 'KONFIGURACJA TIMERA
- Config Timer1 = Timer , Prescale = 8
- On Timer1 Przertimer1
- Enable Timer1
- '--------------------------------------------------------------------
- 'KONFIGURACFJA ENKODERA
- 'Config Int0 = Falling
- 'On Int0 Enkoder
- 'Enable Int0
- '--------------------------------------------------------------------
- 'Enable Interrupts
- '--------------------------------------------------------------------
- 'KONFIGURACJA LCD
- Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 , Db7 = Porta.3 , E = Porta.4 , Rs = Porta.5 'mirley UPT M16
- Config Lcd = 16 * 4
- '--------------------------------------------------------------------
- 'KONFIGURACJA PORTÓW
- Config Portd.2 = Input : Portd.2 = 1 'enkoder kanał A
- Config Portd.3 = Input : Portd.3 = 1 'enkoder kanał B
- Config Portd.6 = Output : Portd.6 = 1 'LED Live
- Config Portb.0 = Input ': Pinb.0 = 1 'sw_menu
- Config Portb.1 = Input : 'sw_zero_kąt
- Portb = &B11111111
- '--------------------------------------------------------------------
- 'ALIASY PORTÓW
- Kanal_a Alias Pind.2
- Kanal_b Alias Pind.3
- Led_live Alias Portd.6
- Sw_menu Alias Pinb.0
- Sw_zero_kat Alias Pinb.1
- '--------------------------------------------------------------------
- 'ZMIENNE ENKODERA
- Dim En_impuls As Long 'zmienna przechowywujaca impulsy z enkodera
- '--------------------------------------------------------------------
- 'ZMIENNE CZASU
- Dim Timer_tikx10 As Byte 'zmienna liczaca przepełnienie timera
- Dim Timertikx100 As Byte 'zmienna liczaca przepełnienie timera x10
- Dim Timertikx200 As Byte 'zmienna liczaca przepełnienie timera x 20
- Dim Timertikx500 As Byte 'zmienna liczaca przepełnienie timera x 50
- Dim Timer_tik_flag As Byte
- Flaga10ms Alias Timer_tik_flag.0
- Flaga100ms Alias Timer_tik_flag.1
- Flaga500ms Alias Timer_tik_flag.2
- Flaga1s Alias Timer_tik_flag.3
- Flaga2s Alias Timer_tik_flag.4
- Flaga2_5s Alias Timer_tik_flag.5
- 'zostaly jeszce trzy wolne flagi
- ' a uzylem tylko jednego bajtu
- '####################################################################
- 'ZMIENNE POMIARU OBROTÓW
- Dim Pomiar1 As Single 'zmienna pomocnicza1
- Dim Pomiar2 As Single 'zmienna pomocnicza2
- Dim Pomiar3 As Single 'zmienna pomocnicza3
- Dim Wynik As String * 5 'zmienna pomocnicza4
- Dim Wynik1 As Long
- '-----------------------------------------------------------------------
- 'ZMIENNE POMIARU KĄTA
- Dim Kat_ As Word
- Dim Kat_1 As Single
- '-----------------------------------------------------------------------
- 'ZMIENNE MENU
- Dim Poz_menu As Byte 'zmienna menu
- Dim Wyswietl_ As Byte 'zmiennawyboru wyświetlania
- '----------------------------------------------------------------------------
- 'ZMIENNE PRZYCISKU ENKODERA
- Dim Sw_cnt As Word
- Dim Lock As Byte
- '----------------------------------------------------------------------------
- $include "subs\mruganie.inc"
- $include "subs\wyswietl.inc"
- '$include "subs\pomiar.inc"
- '-------------------------------------------------------------------
- 'Enable Interrupts
- '----------------------------------------------------------------------------
- 'KONFIGURACFJA ENKODERA
- Config Int0 = Falling
- On Int0 Enkoder
- Enable Interrupts
- Enable Int0
- Waitms 500
- Cursor Off
- Cursor Noblink
- Cls
- Poz_menu = 0
- '----------------------------------------------------------------------------
- Do
- '====================================================================
- If Timer_tikx10 >= 10 Then 'jeśli uplyneło 100ms to
- Flaga100ms = 1 'ustaw flage upłyneło 100ms
- Incr Timertikx100 'zwiększaj Timertikx100
- Timer_tikx10 = 0 'zeruj liczenie
- End If 'koniec warunku
- If Timertikx100 >= 10 Then 'jeśli uplynela sekunda
- Flaga1s = 1 'ustaw flage upłyneła sekunda
- Incr Timertikx200 'zwiększaj Timertikx200
- Incr Timertikx500
- Timertikx100 = 0 'zeruj liczenie
- End If 'koniec warunku
- If Timertikx200 >= 2 Then 'jeśli upłyneły dwie sekundy
- Flaga2s = 1 'ustaw flagę upłyneły dwie sekundy
- Timertikx200 = 0 'zeruj liczenie
- End If 'koniec warunku
- If Timertikx500 >= 5 Then
- Flaga500ms = 1
- Timertikx500 = 0
- End If
- '=====================================================================
- If Flaga10ms = 1 Then 'jeśli Flaga10ms jest równa 1
- Flaga10ms = 0 'wyzeruj Flaga10ms 'dopisano 19.06.2018
- End If 'koniec warunku
- '---------------------------------------------------------------------------------------------------
- If Flaga100ms = 1 Then 'jeśli Flaga100ms jest równa 1
- Flaga100ms = 0 'wyzeruj Flaga100ms
- End If 'koniec warunku
- '--------------------------------------------------------------------------------------------------
- If Flaga500ms = 1 Then 'jeśli Flaga500ms jest równa 1
- Flaga500ms = 0 'wyzeruj Flaga500ms
- End If 'koniec warunku
- '---------------------------------------------------------------------------------------------------
- If Flaga1s = 1 Then 'jeśli Flaga1s jest równa 1
- Mruganie
- Wyswietl
- 'Pomiar
- Pomiar1 = En_impuls / 1000 '720
- Pomiar2 = Pomiar1 * 60
- Pomiar3 = Pomiar2
- En_impuls = 0
- Flaga1s = 0 'wyzeruj Flaga1s
- End If 'koniec warunku
- '---------------------------------------------------------------------------------------------------
- If Flaga2s = 1 Then 'jeśli Flaga2s jest równa 1
- Flaga2s = 0 'wyzeruj Flaga
- End If
- 'koniec warunku
- If Sw_menu = 0 Then
- Poz_menu = Poz_menu + 1
- End If
- If Poz_menu = 0 Then
- Wyswietl_ = 0
- End If
- If Poz_menu = 1 Then
- Wyswietl_ = 1
- End If
- If Poz_menu = 2 Then
- Poz_menu = 0
- End If
- If Sw_zero_kat = 0 Then
- Kat_1 = 0
- End If
- If Kat_ > 720 Then
- Kat_ = 0
- End If
- Kat_1 = Kat_ / 2
- Loop
- End
- '-----------------------------------------------------------------------------------------------------
- ' podprogram przerwań Timer1
- Przertimer1:
- Timer1 = 45536 'wstawienie do Timer1 wartości 45536
- Incr Timer_tikx10
- If Timer_tikx10 = 1 Then
- Set Flaga10ms
- End If
- Return 'powrót
- '-----------------------------------------------------------------------------------------------------
- Enkoder:
- Disable Int0
- 'Waitms 1
- If Kanal_a = 0 Then
- If Kanal_b = 0 Then
- Incr En_impuls
- Incr Kat_
- Else
- Decr Kat_
- End If
- End If
- Enable Int0
- Return
- '------------------------------
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- 'mruganie Led_live
- Sub Mruganie
- Toggle Led_live
- End Sub
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- 'wyświetlanie na LCD
- Sub Wyswietl
- Wynik = Str(pomiar3)
- Wynik = Fusing(pomiar3 , "###.#")
- Wynik1 = Val(wynik)
- 'koniec warunku
- 'If Sw_menu = 0 Then
- ' Poz_menu = Poz_menu + 1
- 'End If
- 'If Poz_menu = 0 Then
- ' Wyswietl_ = 0
- 'End If
- 'If Poz_menu = 1 Then
- ' Wyswietl_ = 1
- 'End If
- 'If Poz_menu = 2 Then
- ' Poz_menu = 0
- 'End If
- Select Case Wyswietl_
- Case 0
- Locate 4 , 1 : Lcd "poz_menu " ; Poz_menu : :
- 'Poz_menu = 0
- 'Cls
- Locate 1 , 1 : Lcd "OBROTY WRZECIONA"
- If Wynik1 > 999 Then
- Locate 2 , 3 : Lcd ; Wynik1 '; Wynik1
- Locate 2 , 7 : Lcd " OBR/MIN "
- End If
- If Wynik1 < 1000 Then
- Locate 2 , 3 : Lcd "0" ; Wynik1
- Locate 2 , 7 : Lcd " OBR/MIN "
- End If
- If Wynik1 < 100 Then
- Locate 2 , 3 : Lcd "00" ; Wynik1 '; Wynik1
- Locate 2 , 7 : Lcd " OBR/MIN "
- End If
- If Wynik1 < 10 Then
- Locate 2 , 3 : Lcd "000" ; Wynik1 '; Wynik1
- Locate 2 , 7 : Lcd " OBR/MIN "
- End If
- Locate 3 , 1 : Lcd " "
- Case 1:
- Locate 4 , 1 : Lcd "poz_menu " ; Poz_menu
- 'Poz_menu = 1
- 'Cls
- 'Kat_1 = Kat_ / 2
- If Kat_1 > 360 Then
- Kat_1 = 0
- End If
- Locate 1 , 1 : Lcd " POMIAR KATA "
- Locate 2 , 1 : Lcd " WRZECIONA "
- Locate 3 , 1 : Lcd "KAT " ; Kat_1 ; " "
- End Select
- End Sub
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- 'przeliczanie obrotów
- Sub Pomiar
- Pomiar1 = En_impuls / 1000 ' 720
- En_impuls = 0
- Pomiar2 = Pomiar1 * 60
- End Sub
chciałem zrobić jeszcze pomiar kata obrotu - no ale przeszedłem na xmegę - ale będę chciał to zaincludować w projekcie sterownika tokarki ELS
pozdrawiam Jacek.
- niveasoft
- Posty: 1216
- Rejestracja: 17 sie 2015, 12:13
- Kontakt:
Re: Encodery jeszcze raz
Okay. Wydzieliłem temat bo to nie Xmega i tego się trzymajmy
Zobacz jak można mieć trzy enkodery na raz. Na pewno da się to uruchomić na Mega328P i lepiej nawet przenieść piny z PD0 i PD1 na jakies inne bo tam jest akurat USART który zawsze się przydaje
LINK viewtopic.php?f=13&t=360
Zobacz jak można mieć trzy enkodery na raz. Na pewno da się to uruchomić na Mega328P i lepiej nawet przenieść piny z PD0 i PD1 na jakies inne bo tam jest akurat USART który zawsze się przydaje
LINK viewtopic.php?f=13&t=360
- Henryk
- Posty: 348
- Rejestracja: 22 sty 2018, 17:20
Re: Encodery jeszcze raz
Dziękuje za ten przykład z linku
Przyznam się bez nacisków , nie łapię jak połączyć te enkodery , ale to już nie problem .
Sprawę rozwiązał zwykły regulowany generator na 555 i joystik do wyboru osi którą che sterować
Przyznam się bez nacisków , nie łapię jak połączyć te enkodery , ale to już nie problem .
Sprawę rozwiązał zwykły regulowany generator na 555 i joystik do wyboru osi którą che sterować