====== BASCOM Servo mit Timer ansteuern (PMW) ======
' PWM mit Timer: Servoansteuerung. 2 Servos unabhängig ansteuern.
' In: -
' Out: b.1 PWM-Signal 1 (f_PWM ca. 61 Hz -> T_PWM ca. 16 ms)
' Out: b.2 PWM-Signal 2 (f_PWM ca. 61 Hz -> T_PWM ca. 16 ms)
'
$regfile = "m8def.dat" 'Chip: ATmega8
$crystal = 1000000 'Frequenz: 1 MHz
$swstack = 50
$hwstack = 50
$framesize = 50
Config Portb.1 = Output
Config Portb.2 = Output 'fuer PWM/Analogausgabe
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 8
Servo1 Alias Pwm1a
Servo2 Alias Pwm1b
Dim Position As Word
Const Links = 895 '2 ms
Const Rechts = 960 '1 ms
Do
Servo1 = Rechts
Servo2 = Rechts
Wait 2
Servo1 = Links
Servo2 = Links
For Position = Links To Rechts Step 5
Servo2 = Position
Waitms 100
Next Position
Loop
End
{{tag>BASCOM Elektronik Mikrocontroller Programmierung }}
====== BASCOM SERVO mit ATtiny13======
Der Servo fährt zwischen zwei Punkten hin und her.
$regfile = "ATtiny13.dat"
$crystal = 9600000
$hwstack = 10 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 20 ' default use 40 for the frame space
Config Servos = 1 , Servo1 = Portb.1 , Reload = 5
Config Pinb.1 = Output
Enable Interrupts
Do
Servo(1) = 65
Waitms 300
Servo(1) = 230
Waitms 200
Loop
End