How can I set the frequency of VCO?

Hi,
I have written a code to set the frequency of VCO (ADF4360-0):

bool flag = true;

bool usrp_standard_rx::set_freq(double frequenza)
{
vector a;
frequenza += -4e6;

a = compute_regs(frequenza);

if(a.at(0)==0)
return false;

write_all(a.at(0),a.at(1),a.at(2));
return true;

}

vector usrp_standard_rx::compute_regs(double frequenza)
{
vector a;
double phdet_freq = 64e6 / 16; //uso i parametri di flex2400
int desider_n = round(frequenza1/phdet_freq);
float actual_freq = phdet_freq
desider_n;
double B = floor(desider_n/16);
double A = desider_n - 16*B;
int B_DIV = (int)B;
int A_DIV = (int)A;

if(B_DIV < A_DIV)
{
a.at(0)=0;
a.at(1)=0;
a.at(2)=0;
a.at(3)=0;
return a;
}

int R = (0<<22) | (3<<20) | (0<<19) | (1<<18) | (0<<16) | (16<<2);

int control = (1<<22) | (0<<20) | (7<<17) | (7<<14) | (0<<12) |
(1<<11) |
(0<<10) | (0<<9) | (1<<8) | (1<<5) | (0<<4) | (1<<2);

int N = (0<<23) | (0<<22) | (0<<21) | (B_DIV<<8) | (0<<7) |
(A_DIV<<2);

a.push_back®;
a.push_back(control);
a.push_back(N);
//a.push_back(actual_freq/2);

return a;
}

void usrp_standard_rx::write_all(int R,int control,int N)
{

write_R®;
write_control(control);
if(flag)
{
sleep(1);
flag = false;
}
write_N(N);
}

void usrp_standard_rx::write_R(int R)
{
write_it((R & ~0x3) | 1);
}

void usrp_standard_rx::write_N(int N)
{
write_it((N & ~0x3) | 2);
}

void usrp_standard_rx::write_control(int control)
{
write_it((control & ~0x3) | 0);
}

void usrp_standard_rx::write_it(int v)
{
char buffer [33];
int uno = ((v>>16) & 0xff);
int due = ((v>>8) & 0xff);
int tre = (v & 0xff);

if(uno == 0)
snprintf(buffer,33,"%c%c",due,tre);
else{

if(due == 0)
snprintf(buffer,33,"%c%c",uno,tre);
else{

if(tre == 0)
snprintf(buffer,33,"%c%c",uno,due);
else
snprintf(buffer,33,"%c%c%c",uno,due,tre);
}
}

int spi_enable = SPI_ENABLE_RX_A;
int spi_format = SPI_FMT_MSB | SPI_FMT_HDR_0;
_write_spi(0,spi_enable,spi_format,buffer);

}

Is this code correct?
If this code isn’t correct, how can I set and calculate the value of
frequency
of VCO or already is there a method in C++ to set it?

Thank you very much.

Calogero

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs