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
Revision 21:3731753ebf24, committed 2015-02-02
- Comitter:
- MikamiUitOpen
- Date:
- Mon Feb 02 23:33:01 2015 +0000
- Parent:
- 20:c49f3b565a87
- Commit message:
- 22
Changed in this revision
DAC_MCP4922.hpp | Show annotated file Show diff for this revision Revisions of this file |
DAC_MCP4922Dual.hpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/DAC_MCP4922.hpp Mon Feb 02 08:10:55 2015 +0000 +++ b/DAC_MCP4922.hpp Mon Feb 02 23:33:01 2015 +0000 @@ -2,7 +2,7 @@ // Class for single DAC in MCP4922 -- Header // Fast version // -// 2015/02/02, Copyright (c) 2015 MIKAMI, Naoki +// 2015/02/03, Copyright (c) 2015 MIKAMI, Naoki //------------------------------------------------------ #ifndef DAC_MCP4922_HPP @@ -27,6 +27,9 @@ : DAC_MCP4921(mosi, sclk, cs, ldac), wcr_(dac | 0x3000) {} + protected: + void SetCR(DAC dac) { wcr_ = dac | 0x3000; } + private: uint16_t wcr_; // write command register @@ -45,3 +48,4 @@ }; } #endif // DAC_MCP4922_HPP +
--- a/DAC_MCP4922Dual.hpp Mon Feb 02 08:10:55 2015 +0000 +++ b/DAC_MCP4922Dual.hpp Mon Feb 02 23:33:01 2015 +0000 @@ -1,7 +1,6 @@ //------------------------------------------------------ // Class for dual channel DAC in MCP4922 -// This class does not support clock for SCF -// 2015/01/30, Copyright (c) 2015 MIKAMI, Naoki +// 2015/02/03, Copyright (c) 2015 MIKAMI, Naoki //------------------------------------------------------ #ifndef DAC_MCP4922_DUAL_HPP @@ -12,34 +11,38 @@ namespace Mikami { - class DAC_MCP4922Dual + class DAC_MCP4922Dual : public DAC_MCP4922 { public: - DAC_MCP4922Dual() - : myDac1_(DAC_MCP4922::DAC_A), - myDac2_(DAC_MCP4922::DAC_B) {} - + DAC_MCP4922Dual( + PinName mosi = SPI_MOSI, // D11 + PinName sclk = SPI_SCK, // D13 + PinName cs = SPI_CS, // D10 + PinName ldac = SPI_MISO) // D12 + : DAC_MCP4922(DAC_A, mosi, sclk, cs, ldac) {} + + void Write(float valA, float valB) { - myDac1_.Write(valA); // Write to DAC A - myDac2_.Write(valB); // Write to DAC B - myDac2_.Wait(); - while (myDac2_.IsBusy()) {} - myDac1_.Ldac(); + SetCR(DAC_A); + DAC_MCP4922::Write(valA); // Write to DAC A + SetCR(DAC_B); + DAC_MCP4922::Write(valB); // Write to DAC B + Wait(); + while (IsBusy()) {} + Ldac(); } void Write(uint16_t valA, uint16_t valB) { - myDac1_.Write(valA); // Write to DAC A - myDac2_.Write(valB); // Write to DAC B - myDac2_.Wait(); - while (myDac2_.IsBusy()) {} - myDac1_.Ldac(); // dual load + SetCR(DAC_A); + DAC_MCP4922::Write(valA); // Write to DAC A + SetCR(DAC_B); + DAC_MCP4922::Write(valB); // Write to DAC B + Wait(); + while (IsBusy()) {} + Ldac(); } - - private: - DAC_MCP4922 myDac1_; - DAC_MCP4922 myDac2_; }; } #endif // DAC_MCP4922_DUAL_HPP