LoginSignup
0
0

More than 1 year has passed since last update.

STM32G031でPWMの測定を作てみた。

Posted at

x シリアルを使うから上級者用

目的
シェフの気まぐれ
内部タイマーを使いusでオン時間を測る

結果
The time taken was 84 seconds
The time taken was 84560 seconds
The time taken was 84 seconds
The time taken was 84517 seconds
The time taken was 84 seconds
The time taken was 84523 seconds
The time taken was 84 seconds
The time taken was 84537 seconds
The time taken was 84 seconds
The time taken was 84521 seconds
The time taken was 84 seconds
The time taken was 84532 seconds
The time taken was 84 seconds
The time taken was 84514 seconds
The time taken was 84 seconds
The time taken was 84521 seconds
The time taken was 84 seconds
The time taken was 84493 seconds
The time taken was 84 seconds
The time taken was 84512 seconds
The time taken was 84 seconds
The time taken was 84508 seconds
The time taken was 84 seconds



#include <Arduino.h>

#define in_pwm   PA11 // 5pin

//10の割り算 0から1028までは、正しい。主に0から999
#define DVI10(n) ((n*205)>>11)

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


//初期化
void setup() {

  delay(3000); //not Delete

  Serial.begin(9600);

  pinMode(in_pwm, INPUT); //pa11

} //setup

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

  int pwmco2;

  //PWMでデータ取得
  pwmco2=pulseIn(in_pwm,HIGH,2000000);
  printf("The time taken was %d seconds\r\n", pwmco2  );
  printf("The time taken was %d seconds\r\n", DVI1000(pwmco2)  );

  //0.1秒の待ち
  delay(100);

} //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