MAXREFDES161# is a high-performance frequency synthesizer capable of generating frequencies from 23.5MHz to 6GHz. The on-board level translators allow the board to be compatible with +3.3V and +5V microcontroller platforms. Moreover, the low-noise low dropout regulators (LDOs) provide clean power supplies for optimal performance. The board is designed specifically for the Arduino form-factor pinout.

Dependencies:   MAX2871 mbed

Committer:
bhavanapotturi
Date:
Mon Jul 30 14:19:56 2018 +0000
Revision:
0:69e25b5e9580
added definitions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhavanapotturi 0:69e25b5e9580 1 #include "mbed.h"
bhavanapotturi 0:69e25b5e9580 2 #include <stdio.h>
bhavanapotturi 0:69e25b5e9580 3
bhavanapotturi 0:69e25b5e9580 4 #include "MAX2871.h"
bhavanapotturi 0:69e25b5e9580 5
bhavanapotturi 0:69e25b5e9580 6 int main() {
bhavanapotturi 0:69e25b5e9580 7
bhavanapotturi 0:69e25b5e9580 8 #define D6 P0_6
bhavanapotturi 0:69e25b5e9580 9 #define D8 P1_4
bhavanapotturi 0:69e25b5e9580 10 #define D9 P1_5
bhavanapotturi 0:69e25b5e9580 11 #define D10 P1_3
bhavanapotturi 0:69e25b5e9580 12 #define D11 P1_1
bhavanapotturi 0:69e25b5e9580 13 #define D12 P1_2
bhavanapotturi 0:69e25b5e9580 14 #define D13 P1_0
bhavanapotturi 0:69e25b5e9580 15
bhavanapotturi 0:69e25b5e9580 16
bhavanapotturi 0:69e25b5e9580 17 SPI spi(D11,D12,D13); //mosi, miso, sclk
bhavanapotturi 0:69e25b5e9580 18 Serial pc(USBTX,USBRX,9600); //tx, rx, baud
bhavanapotturi 0:69e25b5e9580 19
bhavanapotturi 0:69e25b5e9580 20 DigitalOut le(D10,1); //Latch enable pin for MAX2871
bhavanapotturi 0:69e25b5e9580 21 DigitalIn ld(D6); //Lock detect output pin
bhavanapotturi 0:69e25b5e9580 22 DigitalOut led(LED_BLUE,1); //blue LED on MAX32600MBED board
bhavanapotturi 0:69e25b5e9580 23
bhavanapotturi 0:69e25b5e9580 24 DigitalOut rfouten(D8,1); //RF output enable pin
bhavanapotturi 0:69e25b5e9580 25 DigitalOut ce(D9,1); //Chip enable pin
bhavanapotturi 0:69e25b5e9580 26
bhavanapotturi 0:69e25b5e9580 27 double freq_entry; //variable to store user frequency input
bhavanapotturi 0:69e25b5e9580 28 char buffer[256]; //array to hold string input from terminal
bhavanapotturi 0:69e25b5e9580 29
bhavanapotturi 0:69e25b5e9580 30 double v_tune, temperature; //stores TUNE voltage and die temperature of MAX2871
bhavanapotturi 0:69e25b5e9580 31 uint32_t vco; //stores active VCO in use
bhavanapotturi 0:69e25b5e9580 32 double freq_rfouta; //variable to calculate ouput frequency from register settings
bhavanapotturi 0:69e25b5e9580 33
bhavanapotturi 0:69e25b5e9580 34 spi.format(8,0); //CPOL = CPHA = 0, 8 bits per frame
bhavanapotturi 0:69e25b5e9580 35 spi.frequency(1000000); //1 MHz SPI clock
bhavanapotturi 0:69e25b5e9580 36
bhavanapotturi 0:69e25b5e9580 37 MAX2871 max2871(spi,D10); //create object of class MAX2871, assign latch enable pin
bhavanapotturi 0:69e25b5e9580 38
bhavanapotturi 0:69e25b5e9580 39 max2871.powerOn(true); //set all hardware enable pins and deassert software shutdown bits
bhavanapotturi 0:69e25b5e9580 40
bhavanapotturi 0:69e25b5e9580 41 max2871.setPFD(50.0,2); //inputs are reference frequency and R divider to set phase/frequency detector comparison frequency
bhavanapotturi 0:69e25b5e9580 42
bhavanapotturi 0:69e25b5e9580 43 //The routine in the while(1) loop will ask the user to input a desired
bhavanapotturi 0:69e25b5e9580 44 //output frequency, check that it is in range, calculate the corresponding
bhavanapotturi 0:69e25b5e9580 45 //register settings, update the MAX2871 registers, and then independently
bhavanapotturi 0:69e25b5e9580 46 //use the programmed values to re-calculate the output frequency chosen
bhavanapotturi 0:69e25b5e9580 47 while(1){
bhavanapotturi 0:69e25b5e9580 48 pc.printf("\n\rEnter a frequency in MHz:");
bhavanapotturi 0:69e25b5e9580 49 fgets(buffer,256,stdin);
bhavanapotturi 0:69e25b5e9580 50 pc.printf("Line: %s\n", buffer); //store entry as string until newline entered
bhavanapotturi 0:69e25b5e9580 51 freq_entry = floor(1000*atof(buffer))/1000; //convert string to a float with 1kHz precision
bhavanapotturi 0:69e25b5e9580 52 if((freq_entry < 23.5) || (freq_entry > 6000.0)) //check the entered frequency is in MAX2871 range
bhavanapotturi 0:69e25b5e9580 53 pc.printf("\n\rNot a valid frequency entry.");
bhavanapotturi 0:69e25b5e9580 54 else
bhavanapotturi 0:69e25b5e9580 55 {
bhavanapotturi 0:69e25b5e9580 56 pc.printf("\n\rTarget: %.3f MHz",freq_entry); //report the frequency derived from user's input
bhavanapotturi 0:69e25b5e9580 57 max2871.setRFOUTA(freq_entry); //update MAX2871 registers for new frequency
bhavanapotturi 0:69e25b5e9580 58
bhavanapotturi 0:69e25b5e9580 59 while(!ld) //blink an LED while waiting for MAX2871 lock detect signal to assert
bhavanapotturi 0:69e25b5e9580 60 {
bhavanapotturi 0:69e25b5e9580 61 led = !led;
bhavanapotturi 0:69e25b5e9580 62 wait_ms(30);
bhavanapotturi 0:69e25b5e9580 63 }
bhavanapotturi 0:69e25b5e9580 64 led = 1;
bhavanapotturi 0:69e25b5e9580 65
bhavanapotturi 0:69e25b5e9580 66 vco = max2871.readVCO(); //read the active VCO from MAX2871
bhavanapotturi 0:69e25b5e9580 67 v_tune = max2871.readADC(); //read the digitized TUNE voltage
bhavanapotturi 0:69e25b5e9580 68 freq_rfouta = max2871.getRFOUTA(); //calculate the output frequency of channel A
bhavanapotturi 0:69e25b5e9580 69 temperature = max2871.readTEMP(); //read die temperature from MAX2871
bhavanapotturi 0:69e25b5e9580 70
bhavanapotturi 0:69e25b5e9580 71 //print the achieved output frequency and MAX2871 diagnostics
bhavanapotturi 0:69e25b5e9580 72 pc.printf("\n\rActual: %.3f MHz",freq_rfouta);
bhavanapotturi 0:69e25b5e9580 73 pc.printf("\n\rVTUNE: %.3f V, VCO: %d, TEMP: %f",v_tune,vco,temperature);
bhavanapotturi 0:69e25b5e9580 74 }
bhavanapotturi 0:69e25b5e9580 75 }
bhavanapotturi 0:69e25b5e9580 76 }