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:
2014-10-22
Revision:
2:2a3b4ed3eb58
Parent:
0:6e0ed5adfe47
Child:
3:77bc5550dc10

File content as of revision 2:2a3b4ed3eb58:

//------------------------------------------------------
// Class for single DAC in MCP4922 -- Header
//      Fast version
//
// Default pin assign
//      D11  SPI Master Out Slave In
//      D13  SPI Serial Clock
//      D12  SPI Slave Select
//      D10  to MCP4922 LDAC pin
//
// 2014/10/22, Copyright (c) 2014 MIKAMI, Naoki
//------------------------------------------------------

#ifndef DAC_MCP4922_HPP
#define DAC_MCP4922_HPP

#include "mbed.h"
#include "tim4_slaveSelect.hpp"

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

        // Constructor
        DAC_MCP4922(
            DAC dac,
            PinName mosi = SPI_MOSI,    // D11
            PinName sclk = SPI_SCK,     // D13
            PinName cs   = SPI_CS,      // D10
            PinName ldac = SPI_MISO,    // D12
            int hz = 21000000);         // 21 MHz

        // -1.0f <= value <= 1.0f
        void Write(float value);
        // 0 <= value <= 4095
        void Write(uint16_t value);
        
        // generate LDAC negative-going pulse
        void Ldac();

        // Check busy
        bool IsBusy()
        { return (mySpi_->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY; }

    private:
        uint16_t wcr_;  // write command register
        SPI spi_;       // SPI object of mbed
        Tim4_ss* ss_;
        DigitalOut ld_; // for LDAC

        // Pointer of I2C
        SPI_TypeDef* mySpi_;

        // for inhibition of copy constructor
        DAC_MCP4922(const DAC_MCP4922&);
        // for inhibition of substitute operator
        DAC_MCP4922& operator=(const DAC_MCP4922&);     
        
        // for internal use
        void WriteDac(uint16_t value);
    };
}
#endif  // DAC_MCP4922_HPP