Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UIT2_MovingAverage UIT2_AllpassReverb UIT2_CombReverb UIT2_FIR_LPF_Symmetry ... more
DAC_MCP4922.hpp
- Committer:
- MikamiUitOpen
- Date:
- 2014-10-20
- Revision:
- 0:6e0ed5adfe47
- Child:
- 2:2a3b4ed3eb58
File content as of revision 0:6e0ed5adfe47:
//------------------------------------------------------ // 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/09/29, 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(); // LDAC to H void LdacH() { ld_.write(1); } // LDAC to L void LdacL() { ld_.write(0); } // 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_; // for slave select 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