BASCOM Servo mit Timer ansteuern (PMW)

  1. ' PWM mit Timer: Servoansteuerung. 2 Servos unabhängig ansteuern.
  2. ' In: -
  3. ' Out: b.1 PWM-Signal 1 (f_PWM ca. 61 Hz -> T_PWM ca. 16 ms)
  4. ' Out: b.2 PWM-Signal 2 (f_PWM ca. 61 Hz -> T_PWM ca. 16 ms)
  5. '
  6. $regfile = "m8def.dat" 'Chip: ATmega8
  7. $crystal = 1000000 'Frequenz: 1 MHz
  8.  
  9. $swstack = 50
  10. $hwstack = 50
  11. $framesize = 50
  12.  
  13. Config Portb.1 = Output
  14. Config Portb.2 = Output 'fuer PWM/Analogausgabe
  15. Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 8
  16.  
  17. Servo1 Alias Pwm1a
  18. Servo2 Alias Pwm1b
  19.  
  20. Dim Position As Word
  21.  
  22. Const Links = 895 '2 ms
  23. Const Rechts = 960 '1 ms
  24.  
  25. Do
  26.  
  27. Servo1 = Rechts
  28. Servo2 = Rechts
  29. Wait 2
  30.  
  31. Servo1 = Links
  32. Servo2 = Links
  33.  
  34. For Position = Links To Rechts Step 5
  35. Servo2 = Position
  36. Waitms 100
  37. Next Position
  38.  
  39. Loop
  40. End

BASCOM SERVO mit ATtiny13

Der Servo fährt zwischen zwei Punkten hin und her.

  1. $regfile = "ATtiny13.dat"
  2. $crystal = 9600000
  3. $hwstack = 10 ' default use 32 for the hardware stack
  4. $swstack = 10 ' default use 10 for the SW stack
  5. $framesize = 20 ' default use 40 for the frame space
  6. Config Servos = 1 , Servo1 = Portb.1 , Reload = 5
  7. Config Pinb.1 = Output
  8. Enable Interrupts
  9. Do
  10. Servo(1) = 65
  11. Waitms 300
  12. Servo(1) = 230
  13. Waitms 200
  14. Loop
  15. End