Class library for internal ADC and DAC connected by SPI. ADC is triggered by TIM2. 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. Slave select of SPI for DAC is generated using TIM4. Validated for ST Nucleo F401RE, F411RE. New version. 内蔵 ADC と,SPI 接続の DAC のためのクラスライブラリ.ADC の変換開始トリガは TIM2 で発生.DAC の出力信号を平滑化するためのスイッチトキャパシタフィルタ用のクロックは TIM3 を使用.DAC の SPI 用スレーブ選択信号は TIM4 で発生.ST Nucleo F401RE,F411RE で動作を確認.新バージョン

Dependents:   UIT2_MovingAverage UIT2_AllpassReverb UIT2_CombReverb UIT2_FIR_LPF_Symmetry ... more

DAC_MCP4922.hpp

Committer:
MikamiUitOpen
Date:
2015-02-02
Revision:
21:3731753ebf24
Parent:
20:c49f3b565a87

File content as of revision 21:3731753ebf24:

//------------------------------------------------------
// Class for single DAC in MCP4922 -- Header
//      Fast version
//
// 2015/02/03, Copyright (c) 2015 MIKAMI, Naoki
//------------------------------------------------------

#ifndef DAC_MCP4922_HPP
#define DAC_MCP4922_HPP

#include "DAC_MCP4921.hpp"

namespace Mikami
{
    class DAC_MCP4922 : public DAC_MCP4921
    {
    public:
        enum DAC { DAC_A = 0, DAC_B = 0x8000 };

        // Constructor
        DAC_MCP4922(
            DAC dac = DAC_A,            // channel A
            PinName mosi = SPI_MOSI,    // D11
            PinName sclk = SPI_SCK,     // D13
            PinName cs   = SPI_CS,      // D10
            PinName ldac = SPI_MISO)    // D12
                : DAC_MCP4921(mosi, sclk, cs, ldac),
                  wcr_(dac | 0x3000) {}

    protected:
        void SetCR(DAC dac) { wcr_ = dac  | 0x3000; }
        
    private:
        uint16_t wcr_;  // write command register

        // for inhibition of copy constructor
        DAC_MCP4922(const DAC_MCP4922&);
        // for inhibition of substitute operator
        DAC_MCP4922& operator=(const DAC_MCP4922&);     
        
        // for internal use
        virtual void WriteDac(uint16_t value)
        {
            while (IsBusy()) {}
            SlaveSelect();
            WriteSpi(value | wcr_);
        }
    };
}
#endif  // DAC_MCP4922_HPP