Close

Controlling 3 servos with STM8S103F3 (made simple)

A project log for eForth for cheap STM8S gadgets

Turn cheap modules from AliExpress into interactive development kits!

thomasThomas 07/24/2017 at 19:110 Comments

Library functions, and the upload utility in e4thcom with its #include feature make programming a STM8S103F3 demo board much simpler.

Here is an example:

#include utils/rammark.fs
RAMmark
#include regs/opt.fs
NVM
#include hw/opt.fs
\ set option bits to enable PC5 TIM1_CC1, and PC6 TIM1_CC2
: OptInit ( -- )
  OPT2 DUP C@ $01 OR SWAP OPT!
;
RAMdrop
RAMmark
#include regs/timer1.fs
NVM
#include hw/pwm.fs
\ timer1 init to 1MHz clock and 20ms period
: ServoInit ( -- )
  15 T1PwmInit
  20000 T1Reload
  1500 PWM1  \ PC6 pin 16
  1500 PWM2  \ PC5 pin 15
  1500 PWM3  \ PC3 pin 13
;
RAMdrop
\ Done!
\ run OptInit to configure GPIO functions **once**
\ run ServoInit
\ set servos with y PWMx | y: 1000..2000 [µs], x: 1..3

This demo works with STM8EF v2.2.13.snapshot (the include files are in the lib folder).

Steps for using it:

Refer to the e4thcom docs for more information.

Discussions