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.

Nucleo F303K8 OPAMPを使ってみる w/STM32CubeIDE

Posted at

とにかく使ってみる

RM0316にあるPGAモード,内部ゲイン設定をテストします。VPだけ入力すればよく,ローサイドの電流検出に便利そうですね。

image.png

ここではDACから1Vを出し,固定ゲインで2倍にして2Vを得てみます。

iocで有効にします。

image.png

DAC1も有効にします。こちらは省略します。

PIN Arduino STM32
 6    A6     PA7 OPAMP2_VINP --+
 7    A5     PA6 OPAMP2_VOUT   |
 8    A2     PA5 DAC1_OUT2     |
 9    A3     PA4 DAC1_OUT1 ----+
...

DAC1_OUT1 を OPAMP2_VINPに接続します。Nucleoでは上記のように 6 - 9 ピンを接続します。

main.c
  /* USER CODE BEGIN 2 */
  HAL_OPAMP_Start(&hopamp2);

#define V1R0 0xfff*10/33
  HAL_DAC_SetValue(&hdac1, DAC1_CHANNEL_1, DAC_ALIGN_12B_R, V1R0);
  HAL_DAC_Start(&hdac1, DAC1_CHANNEL_1);
  /* USER CODE END 2 */

あっけないほど簡単です。テスターで Nucleoの 6ピン (= 9ピン) に 1V 7ピンに2V出ていることを確認しました。

OPAMP出力をADに接続する

RM0316によれば,ADC2 channel 3 と接続しているとのことですので,有効にしてADで読んでみます。

image.png

上のソースに追加です。

main.c
  HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED);

  HAL_ADC_Start(&hadc2);

  HAL_ADC_PollForConversion(&hadc2, HAL_MAX_DELAY);

  uint32_t raw_AD_value=HAL_ADC_GetValue(&hadc2);
  uint32_t convert_to_voltage=raw_AD_value * 3300 / 0xfff;

1991mV 約2Vが得られました。

image.png

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?