0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

STM32G031でPWMを使ってSG90のセンターの1450usをだす。

Posted at

目的
PWMのテスト

o_con788.jpg

o_con789.jpg

o_con790.jpg




//PWM_servo_test22_031_1

#include <Arduino.h>

//1000の割り算 だいたい正しい。
#define DIV1000(n) ((n+((n*25)>>10))>>10)

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

#define DD PA11    // potentiometer connected to analog pin x


//初期化
void setup() {

  pinMode(DD, OUTPUT);   // sets the LED pin as output
  analogWriteFrequency(50);   //周波数
  analogWriteResolution(16);  //分解能

}//setup


//メインループ
void loop() {

  int ii; //ループカウンター

  //for (ii = 500; ii < 2400; ii=ii+100) {

  ii = 1450;
  analogWrite(DD, DIV1000(SN(ii))  );   // analogRead values go from 0
  // to 4095, pwmWrite values
  // from 0 to 65535, so scale rough
  delay(1000); //1000mS

  //}//for

}//loop





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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?