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.
main.cpp
00001 #include "mbed.h" 00002 #include <stdio.h> 00003 00004 #include "MAX2871.h" 00005 00006 int main() { 00007 00008 #define D6 P0_6 00009 #define D8 P1_4 00010 #define D9 P1_5 00011 #define D10 P1_3 00012 #define D11 P1_1 00013 #define D12 P1_2 00014 #define D13 P1_0 00015 00016 00017 SPI spi(D11,D12,D13); //mosi, miso, sclk 00018 Serial pc(USBTX,USBRX,9600); //tx, rx, baud 00019 00020 DigitalOut le(D10,1); //Latch enable pin for MAX2871 00021 DigitalIn ld(D6); //Lock detect output pin 00022 DigitalOut led(LED_BLUE,1); //blue LED on MAX32600MBED board 00023 00024 DigitalOut rfouten(D8,1); //RF output enable pin 00025 DigitalOut ce(D9,1); //Chip enable pin 00026 00027 double freq_entry; //variable to store user frequency input 00028 char buffer[256]; //array to hold string input from terminal 00029 00030 double v_tune, temperature; //stores TUNE voltage and die temperature of MAX2871 00031 uint32_t vco; //stores active VCO in use 00032 double freq_rfouta; //variable to calculate ouput frequency from register settings 00033 00034 spi.format(8,0); //CPOL = CPHA = 0, 8 bits per frame 00035 spi.frequency(1000000); //1 MHz SPI clock 00036 00037 MAX2871 max2871(spi,D10); //create object of class MAX2871, assign latch enable pin 00038 00039 max2871.powerOn(true); //set all hardware enable pins and deassert software shutdown bits 00040 00041 max2871.setPFD(50.0,2); //inputs are reference frequency and R divider to set phase/frequency detector comparison frequency 00042 00043 //The routine in the while(1) loop will ask the user to input a desired 00044 //output frequency, check that it is in range, calculate the corresponding 00045 //register settings, update the MAX2871 registers, and then independently 00046 //use the programmed values to re-calculate the output frequency chosen 00047 while(1){ 00048 pc.printf("\n\rEnter a frequency in MHz:"); 00049 fgets(buffer,256,stdin); 00050 pc.printf("Line: %s\n", buffer); //store entry as string until newline entered 00051 freq_entry = floor(1000*atof(buffer))/1000; //convert string to a float with 1kHz precision 00052 if((freq_entry < 23.5) || (freq_entry > 6000.0)) //check the entered frequency is in MAX2871 range 00053 pc.printf("\n\rNot a valid frequency entry."); 00054 else 00055 { 00056 pc.printf("\n\rTarget: %.3f MHz",freq_entry); //report the frequency derived from user's input 00057 max2871.setRFOUTA(freq_entry); //update MAX2871 registers for new frequency 00058 00059 while(!ld) //blink an LED while waiting for MAX2871 lock detect signal to assert 00060 { 00061 led = !led; 00062 wait_ms(30); 00063 } 00064 led = 1; 00065 00066 vco = max2871.readVCO(); //read the active VCO from MAX2871 00067 v_tune = max2871.readADC(); //read the digitized TUNE voltage 00068 freq_rfouta = max2871.getRFOUTA(); //calculate the output frequency of channel A 00069 temperature = max2871.readTEMP(); //read die temperature from MAX2871 00070 00071 //print the achieved output frequency and MAX2871 diagnostics 00072 pc.printf("\n\rActual: %.3f MHz",freq_rfouta); 00073 pc.printf("\n\rVTUNE: %.3f V, VCO: %d, TEMP: %f",v_tune,vco,temperature); 00074 } 00075 } 00076 }
Generated on Wed Jul 13 2022 01:50:54 by
1.7.2