Last active
November 17, 2017 05:48
-
-
Save TG9541/321e58dd4c837bb3625d93bf845562f3 to your computer and use it in GitHub Desktop.
STM8S103F3 RC servo control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\ 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to 2.2.19 / e4thcom