Skip to content

Instantly share code, notes, and snippets.

@TG9541
Last active November 17, 2017 05:48
Show Gist options
  • Save TG9541/321e58dd4c837bb3625d93bf845562f3 to your computer and use it in GitHub Desktop.
Save TG9541/321e58dd4c837bb3625d93bf845562f3 to your computer and use it in GitHub Desktop.
STM8S103F3 RC servo control
\ STM8 eForth interactive RC-servo demo
\ set compilation target for STARTTEMP / ENDTEMP
: TARGET NVM ;
#require hw/pwm.fs
#require OPT!
#include STARTTEMP
\res MCU: STM8S103
\res export OPT2
TARGET
\ set option bits to enable PC5 TIM1_CC1, and PC6 TIM1_CC2
: OptInit ( -- )
OPT2 DUP C@ $01 OR SWAP OPT!
;
\ timer1 init to 1MHz clock and 20ms period
: ServoInit ( -- )
15 T1PwmInit
20000 T1Reload
\ init servos to 50%
1500 PWM1 \ PC6 pin 16
1500 PWM2 \ PC7 pin 17
1500 PWM3 \ PC3 pin 13
;
ENDTEMP
\ Done!
\ run OptInit to configure GPIO functions **once**
\ run ServoInit
\ set servos with y PWMx | y: 1000..2000 [µs], x: 1..3
@TG9541
Copy link
Author

TG9541 commented Nov 16, 2017

Updated to 2.2.19 / e4thcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment