Class library for internal ADC and DAC connected by SPI. This library support clock generator using TIM3 for switched-capacitor filter to smooth output signal of DAC. This library includes derivative class to support interrupt occured in end of AD conversion. Validated for ST Nucleo F401RE, F411RE. 内蔵 ADC と,SPI 接続の DAC のためのクラスライブラリ.DAC の出力信号を平滑化するためのスイッチトキャパシタフィルタ用のクロックは TIM3 を使用.ST Nucleo F401RE,F411RE で動作を確認.
Dependents: UITDSP_ADDA_Example UIT2_MovingAv_Intr UIT2_VariableFIR UIT2_VowelSynthesizer ... more
DAC_MCP4922Dual.hpp@7:14cdca8b48f8, 2015-04-19 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Apr 19 09:39:28 2015 +0000
- Revision:
- 7:14cdca8b48f8
- Parent:
- 5:ff25db28bc64
8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:2cdd5c91d975 | 1 | //------------------------------------------------------ |
MikamiUitOpen | 2:0cf4cc40ee02 | 2 | // Class for dual channel DAC in MCP4922 |
MikamiUitOpen | 7:14cdca8b48f8 | 3 | // 2015/04/01, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:2cdd5c91d975 | 4 | //------------------------------------------------------ |
MikamiUitOpen | 0:2cdd5c91d975 | 5 | |
MikamiUitOpen | 0:2cdd5c91d975 | 6 | #ifndef DAC_MCP4922_DUAL_HPP |
MikamiUitOpen | 0:2cdd5c91d975 | 7 | #define DAC_MCP4922_DUAL_HPP |
MikamiUitOpen | 0:2cdd5c91d975 | 8 | |
MikamiUitOpen | 0:2cdd5c91d975 | 9 | #include "DAC_MCP4922.hpp" |
MikamiUitOpen | 0:2cdd5c91d975 | 10 | |
MikamiUitOpen | 0:2cdd5c91d975 | 11 | namespace Mikami |
MikamiUitOpen | 2:0cf4cc40ee02 | 12 | |
MikamiUitOpen | 0:2cdd5c91d975 | 13 | { |
MikamiUitOpen | 2:0cf4cc40ee02 | 14 | class DAC_MCP4922Dual : public DAC_MCP4922 |
MikamiUitOpen | 0:2cdd5c91d975 | 15 | { |
MikamiUitOpen | 0:2cdd5c91d975 | 16 | public: |
MikamiUitOpen | 2:0cf4cc40ee02 | 17 | DAC_MCP4922Dual( |
MikamiUitOpen | 2:0cf4cc40ee02 | 18 | PinName mosi = SPI_MOSI, // D11 |
MikamiUitOpen | 2:0cf4cc40ee02 | 19 | PinName sclk = SPI_SCK, // D13 |
MikamiUitOpen | 2:0cf4cc40ee02 | 20 | PinName cs = SPI_CS, // D10 |
MikamiUitOpen | 2:0cf4cc40ee02 | 21 | PinName ldac = SPI_MISO) // D12 |
MikamiUitOpen | 2:0cf4cc40ee02 | 22 | : DAC_MCP4922(DAC_A, mosi, sclk, cs, ldac) {} |
MikamiUitOpen | 2:0cf4cc40ee02 | 23 | |
MikamiUitOpen | 2:0cf4cc40ee02 | 24 | |
MikamiUitOpen | 0:2cdd5c91d975 | 25 | void Write(float valA, float valB) |
MikamiUitOpen | 0:2cdd5c91d975 | 26 | { |
MikamiUitOpen | 2:0cf4cc40ee02 | 27 | SetCR(DAC_A); |
MikamiUitOpen | 2:0cf4cc40ee02 | 28 | DAC_MCP4922::Write(valA); // Write to DAC A |
MikamiUitOpen | 2:0cf4cc40ee02 | 29 | SetCR(DAC_B); |
MikamiUitOpen | 2:0cf4cc40ee02 | 30 | DAC_MCP4922::Write(valB); // Write to DAC B |
MikamiUitOpen | 2:0cf4cc40ee02 | 31 | Wait(); |
MikamiUitOpen | 2:0cf4cc40ee02 | 32 | while (IsBusy()) {} |
MikamiUitOpen | 2:0cf4cc40ee02 | 33 | Ldac(); |
MikamiUitOpen | 0:2cdd5c91d975 | 34 | } |
MikamiUitOpen | 0:2cdd5c91d975 | 35 | |
MikamiUitOpen | 0:2cdd5c91d975 | 36 | void Write(uint16_t valA, uint16_t valB) |
MikamiUitOpen | 0:2cdd5c91d975 | 37 | { |
MikamiUitOpen | 2:0cf4cc40ee02 | 38 | SetCR(DAC_A); |
MikamiUitOpen | 2:0cf4cc40ee02 | 39 | DAC_MCP4922::Write(valA); // Write to DAC A |
MikamiUitOpen | 2:0cf4cc40ee02 | 40 | SetCR(DAC_B); |
MikamiUitOpen | 2:0cf4cc40ee02 | 41 | DAC_MCP4922::Write(valB); // Write to DAC B |
MikamiUitOpen | 2:0cf4cc40ee02 | 42 | Wait(); |
MikamiUitOpen | 2:0cf4cc40ee02 | 43 | while (IsBusy()) {} |
MikamiUitOpen | 2:0cf4cc40ee02 | 44 | Ldac(); |
MikamiUitOpen | 0:2cdd5c91d975 | 45 | } |
MikamiUitOpen | 5:ff25db28bc64 | 46 | |
MikamiUitOpen | 5:ff25db28bc64 | 47 | private: |
MikamiUitOpen | 5:ff25db28bc64 | 48 | void Wait() // Little wait |
MikamiUitOpen | 5:ff25db28bc64 | 49 | { __NOP(); __NOP(); __NOP(); } |
MikamiUitOpen | 0:2cdd5c91d975 | 50 | }; |
MikamiUitOpen | 0:2cdd5c91d975 | 51 | } |
MikamiUitOpen | 0:2cdd5c91d975 | 52 | #endif // DAC_MCP4922_DUAL_HPP |