First version of the MAX2871 shield library. Includes demo program with terminal for setting frequency on channel A.
Dependents: MAX2871-Synthesizer
Fork of MAX2871_Shield_MAXREFDES161 by
Diff: MAX2871.h
- Revision:
- 2:b47819dab536
- Parent:
- 1:40b397b31d13
--- a/MAX2871.h Mon Jul 31 23:57:09 2017 +0000 +++ b/MAX2871.h Tue Jan 09 16:05:51 2018 +0000 @@ -104,13 +104,26 @@ class MAX2871 { public: - ///Register 0 bits + + //MAX2871 Registers + enum Registers_e + { + REG0 = 0x00, + REG1 = 0x01, + REG2 = 0x02, + REG3 = 0x03, + REG4 = 0x04, + REG5 = 0x05, + REG6 = 0x06 + }; + + //Register 0 bits union REG0_u { - ///Access all bits + //Access all bits uint32_t all; - ///Access individual bits + //Access individual bits struct BitField_s { uint32_t addr : 3; @@ -120,13 +133,13 @@ }bits; }; - ///Register 1 bits + //Register 1 bits union REG1_u { - ///Access all bits + //Access all bits uint32_t all; - ///Access individual bits + //Access individual bits struct BitField_s { uint32_t addr : 3; @@ -138,13 +151,13 @@ }bits; }; - ///Register 2 bits + //Register 2 bits union REG2_u { - ///Access all bits + //Access all bits uint32_t all; - ///Access individual bits + //Access individual bits struct BitField_s { uint32_t addr : 3; @@ -165,13 +178,13 @@ }bits; }; - ///Register 3 bits + //Register 3 bits union REG3_u { - ///Access all bits + //Access all bits uint32_t all; - ///Access individual bits + //Access individual bits struct BitField_s { uint32_t addr : 3; @@ -186,13 +199,13 @@ }bits; }; - ///Register 4 bits + //Register 4 bits union REG4_u { - ///Access all bits + //Access all bits uint32_t all; - ///Access individual bits + //Access individual bits struct BitField_s { uint32_t addr : 3; @@ -214,13 +227,13 @@ }bits; }; - ///Register 5 bits + //Register 5 bits union REG5_u { - ///Access all bits + //Access all bits uint32_t all; - ///Access individual bits + //Access individual bits struct BitField_s { uint32_t addr : 3; @@ -239,13 +252,13 @@ }bits; }; - ///Register 6 bits + //Register 6 bits union REG6_u { - ///Access all bits + //Access all bits uint32_t all; - ///Access individual bits + //Access individual bits struct BitField_s { uint32_t addr : 3; @@ -260,16 +273,6 @@ }bits; }; - REG0_u reg0; - REG1_u reg1; - REG2_u reg2; - REG3_u reg3; - REG4_u reg4; - REG5_u reg5; - REG6_u reg6; - - float f_reference; - ///@brief MAX2871 Constructor ///@param spiBus - Reference to spi interface ///@param le - Pin used for latch enable @@ -278,37 +281,69 @@ ///@brief MAX2871 Destructor ~MAX2871(); - ///@brief Write given register.\n + ///@brief Writes raw 32-bit data pattern. The MAX2871 accepts 32-bit words at a time; 29 data bits and 3 address bits. /// ///On Entry: - ///@param[in] reg - Register to write - ///@param[in] data - Data to write + ///@param[in] data - 32-bit word to write to the MAX2871. Bits[31:3] contain the register data, and Bits[2:0] contain the register address. /// ///@returns None - void writeRegister(const uint32_t data); + void write(const uint32_t data); - ///@brief Read Register 6 and update reg6 member.\n + ///@brief Read Register 6 and update reg6 member variable. The MAX2871 only has one readable register - Register 6. + /// + ///@returns 32-bit word whose lowest bits are '110' indicating register address 6. + uint32_t readRegister6(); + + ///@brief Updates MAX2871 settings to achieve target output frequency on channel A.\n + /// + ///On Entry: + ///@param[in] freq - Frequency in MHz /// ///@returns None - void readRegister6(); + void setRFOUTA(const double freq); - ///@brief Update all registers.\n + ///@brief Provide frequency input to REF_IN pin.\n + /// + ///On Entry: + ///@param[in] ref_in - Frequency in MHz /// ///@returns None - void update(); + void setPFD(const double ref_in, const uint16_t rdiv); - ///@brief Updates MAX2871 settings to achieve frequency output.\n + double getPFD(); + + ///@brief Read ADC voltage.\n /// ///On Entry: - ///@param[in] freq - Frequency in MHz /// - ///@returns None - void frequency(const float freq); + ///@returns ADC reading in Volts + double readADC(); + + uint32_t readVCO(); + + void powerOn(const bool pwr); + + double getRFOUTA(); + + double readTEMP(); + + void updateAll(); private: SPI &m_spiBus; DigitalOut m_le; + + REG0_u reg0; + REG1_u reg1; + REG2_u reg2; + REG3_u reg3; + REG4_u reg4; + REG5_u reg5; + REG6_u reg6; + + double f_pfd; + double f_rfouta; }; #endif /* _MAX2871_H_ */