たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

ESP32のD/Aコンバータを調査・検証

ESP32のデジタル→アナログ コンバーターを調査・検証してみる。予定

  • スペック
    • 口数: 2口
    • 分解能: 8bit
    • 動作周波数:
    • 変換原理: 抵抗ストリング型
  • How to use
    • 対応GPIO: 25番 & 26番
    • 他のD/A変換法:
    • ESP-IDF
      • DAC-GPIOはなんと関数は1つ、シンプルぅ
      • I2C-GPIOをDACへルーティング可能。サイン波とか簡単に入力可能?
  • 検証結果

スペック

口数と分解能

2つの8bit DACを搭載.

Two 8-bit DAC channels can be used…
https://espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf#page31

変換原理

DACは integrated resistor strings and a bufferから構成される.
つまり、バッファを持つ抵抗ストリング型と予想される.
The design structure is composed of integrated resistor strings and a buffer.

How to use

対応GPIO

25番(channel 1) & 26番(channel 2)

connected to GPIO25 (Channel 1) and GPIO26 (Channel 2).
Digital To Analog Converter — ESP-IDF Programming Guide v2.0-rc1-343-g65baf50 documentation

他のD/A変換法

For other analog output options, see the Sigma-delta Modulation module and the LED Control module. Both these modules produce high frequency PWM output, which can be hardware low-pass filtered in order to generate a lower frequency analog output.
Digital To Analog Converter — ESP-IDF Programming Guide v2.0-rc1-343-g65baf50 documentation

ESP-IDF

DAC直叩き

Header Files
components/driver/include/driver/dac.h

 esp_err_t dac_out_voltage(dac_channel_t channel, uint8_t dac_value)

I2Sルーティング

ESP32にはI2S対応ペリフェラルが2つ。

ESP32 contains two I2S peripherals.
I2S — ESP-IDF Programming Guide v2.0-rc1-343-g65baf50 documentation

DMA(ダイレクト メモリ アクセス)に対応、CPUを介さずにメモリ上のデータをDAC-GPIOへ送れる模様.

The I2S peripheral supports DMA meaning it can stream sample data without requiring each sample to be read or written by the CPU.

I2S output can also be routed directly to the Digital/Analog Converter output channels (GPIO 25 & GPIO 26) to produce analog output directly, rather than via an external I2S codec.
I2S — ESP-IDF Programming Guide v2.0-rc1-343-g65baf50 documentation

検証

esp32でマイコンの勉強

マイコン初心者がesp32をモデルに勉強

ESP32とは

中Espressif Systems社が設計、台TSMCが製造するマイクロコントローラー.
Wi-fiとBLEを備えながら非常に安価(¥700)なことで有名.

cpu

米Tensilica(製)、240 MHz駆動のプロセッサコアを2つ搭載.

240 MHz dual core Tensilica
espressif.com

Tensilica(テンシリカ)は、シリコンバレーを本拠地とする半導体IPコア分野の企業である。

組み込みWi-FiチップであるESP8266とESP32は、XtensaをメインのCPUコアとして使用している。
Tensilica - Wikipedia

メモリ

揮発性メモリ: Integrated 520 KB SRAM ESP32 Overview | Espressif Systems
不揮発性メモリ: 16 MByte flash

I/O

無線

マイコンとOS

私がよくわかってないところ。
The Internet of Things with ESP32
qiita.com

Once you’ve compiled your project, the “build” directory will contain a binary file with a name like “my_app.bin”. This is an ESP32 image binary that can be loaded by the bootloader.
github.com

The ESP32 module comes preloaded with a ROM image with an AT command set, just like the ESP8266 did. If you want to waste 95% of this chip’s potential by using it as a glorified serial-to-WiFi modem, you’re all set! But you all want to dig in, right? Right!
hackaday.com

ESP-IDFはfreeRTOSベース.
www.esp32.com

ESP-IDFでの起動からプログラム実行までの詳細な流れ、これは必読ぽい.
General Notes About ESP-IDF Programming — ESP-IDF Programming Guide v2.0-rc1-379-g7522b53 documentation

リセット後、まずリセットベクタコードが実行.

After SoC reset, PRO CPU will start running immediately, executing reset vector code

リセットベクタコードはESP32チップ maskROMのアドレス0x40000400にある。編集不可.

Reset vector code is located at address 0x40000400 in the mask ROM of the ESP32 chip and can not be modified.
General Notes About ESP-IDF Programming — ESP-IDF Programming Guide v2.0-rc1-379-g7522b53 documentation

リセットベクタからStartup codeを呼び出し、ブートモードを決定する.

Startup code called from the reset vector determines the boot mode

普通のresetの場合、

configure SPI flash based on EFUSE values, and attempt to load the code from flash.

SPI flashについて
要は、内部のflashEOMを指してる.
qiita.com

ESP-IDFでは、フラッシュROMアドレス0x1000以降に2nd stage bootloaderのバイナリイメージがある.

In ESP-IDF, the binary image which resides at offset 0x1000 in flash is the second stage bootloader.

2nd stage bootloaderのコードはcomponents/bootloader

econd stage bootloader is used in ESP-IDF to add flexibility to flash layout (using partition tables), and allow for various flows associated with flash encryption, secure boot, and over-the-air updates (OTA) to take place.

ドライバー、マイコンのソフトウェア階層

なんてわかりやすい資料だ、感動
ednjapan.com

A/D converter

SAR式ADCを2つ搭載。18個のピンを入力候補として持てる.

ESP32 integrates two 12-bit SAR ADCs and supports measurements on 18 channels (analog enabled pins).
http://esp-idf.readthedocs.io/en/latest/api/peripherals/adc.html

ULP-coprocessor (Ultra low power? 超低消費電力 副処理装置)を利用可能.
スリープモードでADCを監視し、閾値でCPUを起こすような動作が可能.

4.2 Analog-to-Digital Converter (ADC)
ESP32 integrates 12-bit SAR ADCs and supports measurements on 18 channels (analog enabled pins). Some of these pins can be used to build a programmable gain amplifier which is used for the measurement of small analog signals. The ULP-coprocessor in ESP32 is also designed to measure the voltages while operating in the sleep mode, to enable low power consumption; the CPU can be woken up by a threshold setting and/or via other triggers. With the appropriate setting, the ADCs and the amplifier can be configured to measure voltages for a maximum of 18 pins.
https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf#page30

A/Dコンバーター値の読み取り

ワンショットしか取れないが、どうするんだろ…?

int adc1_get_voltage(adc1_channel_t channel)

電子機器製造

プリント基板ベースの電子機器がどうやって作られるか

www.kumikomi.net

www.denshikikiseizou.com

PCB manufacture service

スイッチサイエンスPCB

やたら安い、大丈夫か心配になるくらい.
https://www.switch-science.com/pcborder/

Fusion PCB

もっと安い…末恐ろしい…
www.seeedstudio.com

Smart-Prototyping

やす…すぎる…
送料込み、15日で届いて¥100/枚… www.smart-prototyping.com

PCB組み立て/実装

PCBA: Print Circuit Board Assembly

qiita.com

比較

pcbshopper.com

年収400万の人を雇うために必要な金額

高度情報化社会では、商品につく値段の多くは人件費に由来している. 電子機器はなおのことである.
では、人を1人雇うのに、実際幾らかかるのか?

かかる人件費

従業員モデル

30歳 年俸手取り400万円

費用

会社を存続させる

会社を存続させるためには幾らかかるのか.

法人住民税

法人住民税 均等割が損益関わらずかかる
必要最低額は だいたい¥70,000
1事業所、50人以下の場合
さいたま市: ¥50,000 さいたま市/法人市民税の概要
東京都23区: ¥70,000 http://www.tax.metro.tokyo.jp/kazei/kintou_zeiritu.pdf
さいたま市が一見安いが、市に追加して県も払う. 結局、均等割分は7万円

休業と廃業

休業と廃業は全然違う.
休業は収益事業をストップした状態.
廃業は会社を無くした状態.
休業は休業届とかが無い.
廃業は廃業に関する様々な登記が必要.

休業届はないんだけど、書類書いて休業すると法人住民税 均等割が免除され得る.
法人住民税が収益事業に対する課税である事が一因ぽい。
明文化された免除規定ではないけど収益事業無いなら地方自治体として徴税しないよ、みたいな感じだと思ってる.
kobarin.hatenablog.com

甘やかしても成長しない

教育論ではなくて、個人/組織/経営の話.

https://twitter.com/kentakeuchi2003/status/557305005313511425

toyokeizai.net

toyokeizai.net

甘やかす ≒ ゲタを履かせる
対象の能力・現状を超えるゲタを履かせる

計画→実施→維持→収束
ゲタを永遠と履かせられない場合に大きな問題が発生
対象の維持キャパシティを超える計画/実施をさせれば、当然破綻する.
走り出すところだけゲタ履かせると、維持ができない。なぜなら身の丈に合わない計画になっちゃうから.

具体的化:
補助金
一時給付
素晴らしい計画だけ渡す

反論:
少し背伸びさせると伸びる、みたいな話