Hi, es ist nur ein Versuch für spätere Projekte, und um ein wenig die Syntax von BASCOM für AVRs kennen zu lernen.
Auf der Bastelumgebung sind die meisten Bauteile für meine Vorhaben vorhanden und festgeschraubt, geklebt..., also wurde sie mit einem kleinen Projekt eingeweiht.
Der Attyni85 ist für den Servo der mit einem Poti angesteuert wird und einem Motor bei dem die Drehzahl mit einem Poti verändert wird zuständig, da ich auch ein paar Werte auf einem Display sehen möchte wurde das Signal vom Servo-Poti an einen Atmega8 weitergereicht der die Servowerte und Potiwerte anzeigt.
Alles anzeigen
Alles anzeigen
Und ein Video gibt es auch:
Poti-Servo-Motor-Display
Grüßle, Naubaddi
Auf der Bastelumgebung sind die meisten Bauteile für meine Vorhaben vorhanden und festgeschraubt, geklebt..., also wurde sie mit einem kleinen Projekt eingeweiht.
Der Attyni85 ist für den Servo der mit einem Poti angesteuert wird und einem Motor bei dem die Drehzahl mit einem Poti verändert wird zuständig, da ich auch ein paar Werte auf einem Display sehen möchte wurde das Signal vom Servo-Poti an einen Atmega8 weitergereicht der die Servowerte und Potiwerte anzeigt.
Quellcode
- ' Compiler: Bascom 2.0.7.5
- '
- ' Dateiname: Potis-Servo-Motor A85.avr
- ' Funktion: mit einem Poti einen Servo ansteuern oder von einem Motor die Drehzahl verändern
- ' Datum: Start 10.03.2020, Stand 10.03.2020
- ' Von: Naubaddi
- '
- ' ATtiny85 (B.5 Reset)
- '
- ' +---v---+
- ' PCINT5/RESET/ADC0/dW B.5 |1 8| VCC
- ' PCINT3/XTAL1/CLKI/OC1B/ADC3 B.3 |2 7| B.2 SCK/USCK/SCL/ADC1/T0/INT0/PCINT2
- ' PCINT4/XTAL2/CLKO/OC1B/ADC2 B.4 |3 6| B.1 MISO/DO/AIN1/OC0B/OC1A/PCINT1
- ' GND |4 5| B.0 MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0
- ' +-------+
- '
- ' --- Mikrocontroler Daten... ----------------------------------------------------------------------------------
- $regfile = "attiny85.dat"
- $crystal = 8000000
- $hwstack = 16
- $swstack = 16
- $framesize = 16
- ' &HFF, &H62, &HDF, &HFF ' 1MHz
- $PROG &HFF, &HE2, &HDF, &HFF ' 8MHz
- ' --- Deklarationen... -----------------------------------------------------------------------------------------
- config servos = 1 , servo1 = portb.0 , reload = 10
- config portb.0 = output ' Servo
- config portb.1 = output ' Motor
- config adc = single , prescaler = auto , reference = avcc
- config portb.3 = input ' Servo-Poti
- config portb.4 = input ' Motor-Poti
- enable interrupts
- ' --- Variablen, Alias... --------------------------------------------------------------------------------------
- dim Poti_Servo as word
- dim Servowert as byte
- dim Servo_alt as byte
- dim Dummer as word
- dim Poti_Motor as word
- dim an as word
- dim aus as word
- ' --- Vorbelegung der Variablen und Alias... -------------------------------------------------------------------
- const Faktor = 11.130 ' Servobereich 53-145 = 92 (1024Bit : 92 = 11.130)
- Motor alias portb.1 ' der Ausgang Nr. 1 für den Motor
- an = 0 ' die an-Zeit für den Motor
- aus = 1023 ' die aus-Zeit für den Motor
- ' --- Programm Anfang ------------------------------------------------------------------------------------------
- do
- Poti_Motor = getadc(2)
- an = Poti_Motor
- aus = 1023 - Poti_Motor
- Motor = 1
- waitus an
- Motor = 0
- waitus aus
- Poti_Servo = getadc(3)
- Dummer = Poti_Servo / Faktor
- Servowert = Dummer + 54
- if Servowert <> Servo_alt then
- Servo_alt = Servowert
- Servo(1) = Servowert
- endif
- loop
- ' --- Programm Ende --------------------------------------------------------------------------------------------
- end
- ' --------------------------------------------------------------------------------------------------------------
Quellcode
- ' Compiler: Bascom 2.0.7.5
- ' Dateiname: Poti-Servo-Display A8.avr
- ' Funktion: mit einem Poti einen Servo ansteuern und die Werte auf einem Display anzeigen
- ' Datum: Start 23.01.2020, Stand 11.03.2020
- ' Von: Naubaddi foto-schubser@arcor.de
- '
- ' Atmega8 (C.6 RESET)
- '
- ' +----v----+
- ' RESET C.6 | 1 28| C.5 ADC5/SCL
- ' RXD D.0 | 2 27| C.4 ADC4/SDA
- ' TXD D.1 | 3 26| C.3 ADC3
- ' INT0 D.2 | 4 25| C.2 ADC2
- ' INT1 D.3 | 5 24| C.1 ADC1
- ' XCK/T0 D.4 | 6 23| C.0 ADC0
- ' VCC | 7 22| GND
- ' GND | 8 21| AREF
- ' XTAL1/TOSC1 B.6 | 9 20| AVCC
- ' XTAL2/TOSC2 B.7 |10 19| B.5 SCK
- ' T1 D.5 |11 18| B.4 MISO
- ' AIN0 D.6 |12 17| B.3 MOSI/OC2
- ' AIN1 D.7 |13 16| B.2 SS/OC1B
- ' ICP1 B.0 |14 15| B.1 OC1A
- ' +---------+
- '
- ' --- Mikrocontroler Daten... ----------------------------------------------------------------------------------
- $regfile = "m8def.dat"
- $crystal = 8000000
- $hwstack = 40
- $swstack = 40
- $framesize = 40
- ' &HFF, &HE1, &HD9, &HFF ' 1MHz
- $PROG &HFF, &HE4, &HD9, &HFF ' 8MHz
- ' --- Deklarationen... -----------------------------------------------------------------------------------------
- config lcdpin = pin , Db4 = portd.4 , Db5 = portd.5 , Db6 = portd.6 , Db7 = portd.7 , E = portd.2 , Rs = portd.3
- config lcd = 20 * 4
- config portd = output
- cursor off
- cls
- config servos = 1 , servo1 = portb.0 , reload = 10
- config portb = output
- enable interrupts
- config adc = single , prescaler = auto , reference = avcc
- config portc.0 = input
- ' --- Variablen, Alias... --------------------------------------------------------------------------------------
- const Faktor = 10.779 ' Servobereich 51-145 = 94 ergibt 1024Bit : 94 = 10.779
- dim Potiwert as word
- dim Servowert as byte
- dim Servo_alt as byte
- dim dumm as single
- ' --- Vorbelegung der Variablen, Alias... ----------------------------------------------------------------------
- locate 1,1
- lcd "Poti :"
- locate 2,1
- lcd "--------------------"
- locate 3,1
- lcd "Servo:"
- locate 4,1
- lcd "--------------------"
- ' --- Programm Anfang ------------------------------------------------------------------------------------------
- do
- Potiwert = getadc(0)
- locate 1,7
- Select case Potiwert
- case 0 to 9
- lcd " " ; Potiwert
- case 10 to 99
- lcd " " ; Potiwert
- case 100 to 999
- lcd " " ; Potiwert
- case 1000 to 9999
- lcd Potiwert
- end select
- dumm = Potiwert / Faktor
- Servowert = dumm + 51
- if Servowert <> Servo_alt then
- Servo_alt = Servowert
- locate 3,8
- Select case Servowert
- case 51 to 94
- lcd " " ; Servowert ; " Links "
- case 100 to 146
- lcd Servowert ; " Rechts"
- case 95 to 99
- lcd " " ; Servowert ; " Mitte "
- end select
- Servo(1) = Servowert
- endif
- loop
- ' --- Programm Ende --------------------------------------------------------------------------------------------
- end
- ' --------------------------------------------------------------------------------------------------------------
Poti-Servo-Motor-Display
Grüßle, Naubaddi
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Naubaddi ()