LoginSignup
0
0

More than 1 year has passed since last update.

STM32G031のPWMを使う

Last updated at Posted at 2022-08-20

x 超超重要 なぜか秋月STM32G031J6M6がうり切れていた。注意!!(2022/8/27現在)

x 過去ログを見よ!!

x Mbedでのボード設定は、NUCLEO-G031K8
x ここで言うSTM32G031は、秋月で売っているSTM32G031J6M6の事

目的
STM32G031J6M6で遊ぶ
使ってみたかった
LED等を繋げる
sg90でためしていないけど

o_con697.jpg

参考




//pwm_test1_031_1

#include "mbed.h"


//data SG90
// 2400us 2.4ms
#define s_max  2400
// 500us 0.5ms
#define s_min  500 
#define s_r    (2400-500)
#define s_c    ((2400-500)/256)
#define SN(n6) (500+(((2400-500)/256)*n6))


//PWMのピンの設定
PwmOut servo(PA_11); //5PIN   //031


//メイン関数
int main() {

    //周期の設定    
    //servo.period(0.020);          // servo requires a 20ms period
    servo.period_ms (20);

    //無限ループ
    while (1) {

        //0から256までループ
        //for(float offset=0.0; offset<0.001; offset+=0.0001) {
        for(int offset=0; offset<256; offset++) {

            //pc.printf(" -S=%d\t%d\r\n", offset , SN(offset) ); //767

            //オン時間の設定
            //servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms     
            servo.pulsewidth_us( SN(offset) );

            //250ミリ秒まつ
            //wait_us(250*1000);
            wait_us(4*1000);
        }//for
    }//while
}//main






0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0