CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ADF4351 Frequency Generator Code

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
patan_mustafa



Joined: 10 Dec 2006
Posts: 3

View user's profile Send private message Send e-mail Visit poster's website

ADF4351 Frequency Generator Code
PostPosted: Sun Feb 09, 2025 12:54 am     Reply with quote






I write this code to bring up my ADF4351 setup with PIC16F1933. You can check your circuit with a fm radio while setting frequency between 88.0MHz-108.0MHz if you do not have an oscilloscope. You must hear a blank audio your at frequency setting. I connect adf output with a 1Mohm resistor to radio antenna

Code:

 
#define ADF_CE    PIN_C3
#define ADF_LE    PIN_C4
#define ADF_DATA  PIN_C5
#define ADF_CLK   PIN_C6
#define ADF_MUX   PIN_C7

void write_to_adf4351(int32 a){
signed int i;
   output_low(ADF_LE);  for(i=31;i>=0;i--){  output_low(ADF_CLK);   output_bit(ADF_DATA, bit_test(a,i));  delay_ms(1);   output_high(ADF_CLK);  }   output_high(ADF_LE);
}

int divider=0;
int16 mod=10,keypad_value;
int32 intmask    =0b01111111111111111000000000000000, intmasknot =0b10000000000000000111111111111111;
int32 fracmask   =0b00000000000000000111111111111000, fracmasknot=0b11111111111111111000000000000111;
int32 frequency=35000, ref_in=10000, kademe,integer=0,frac=0;
int32 reg[6]={0x00700000,0x08000151,0x00004EC2,0x000004B3,0x00C5003C,0x00C00005};
float fstep=0;

// FREQUENCY value for 35.0MHZ is frequency=35000 @10MHz Ref in
void set_freq(void){
   if(frequency>=10000 && frequency<=4400000){
         if(      frequency >=  10000 && frequency <=  17500){ divider=64; bit_set(  reg[4],22); bit_set(  reg[4],21); bit_clear(reg[4],20); mod=156; frequency=frequency*4; }
         else if( frequency >   17500 && frequency <   34375){ divider=32; bit_set(  reg[4],22); bit_clear(reg[4],21); bit_set(  reg[4],20); mod=312; frequency=frequency*4; }
         else if( frequency >=  34375 && frequency <=  70000){ divider=64; bit_set(  reg[4],22); bit_set(  reg[4],21); bit_clear(reg[4],20); mod=156; }
         else if( frequency >   68750 && frequency <= 140000){ divider=32; bit_set(  reg[4],22); bit_clear(reg[4],21); bit_set(  reg[4],20); mod=312; }
         else if( frequency >  137500 && frequency <= 275000){ divider=16; bit_set(  reg[4],22); bit_clear(reg[4],21); bit_clear(reg[4],20); mod=625; }
         else if( frequency >  275000 && frequency <= 550000){ divider=8;  bit_clear(reg[4],22); bit_set(  reg[4],21); bit_set(  reg[4],20); mod=1250;}
         else if( frequency >  550000 && frequency < 1100000){ divider=4;  bit_clear(reg[4],22); bit_set(  reg[4],21); bit_clear(reg[4],20); mod=2500;}
         else if( frequency >=1100000 && frequency < 2200000){ divider=2;  bit_clear(reg[4],22); bit_clear(reg[4],21); bit_set(  reg[4],20); mod=4095;}
         else if( frequency >=2200000 && frequency < 4400000){ divider=1;  bit_clear(reg[4],22); bit_clear(reg[4],21); bit_clear(reg[4],20); mod=10;}
               
         fstep=(float)ref_in/divider;
         integer=(int32)frequency/fstep;
         frac=frequency-(integer*fstep);
         integer=(integer<< 15); integer=(integer)&intmask;  reg[0]=(reg[0])&intmasknot;  reg[0]=(integer)|reg[0];
         frac   =(frac   << 3 ); frac   =(frac   )&fracmask; reg[0]=(reg[0])&fracmasknot; reg[0]=(frac   )|reg[0];
         mod    =(mod    << 3 ); mod    =(mod    )&fracmask; reg[1]=(reg[1])&fracmasknot; reg[1]=(mod    )|reg[1];               
         write_to_adf4351(reg[5]); delay_ms(1);
         write_to_adf4351(reg[4]); delay_ms(1);
         write_to_adf4351(reg[3]); delay_ms(1);
         write_to_adf4351(reg[2]); delay_ms(1);
         write_to_adf4351(reg[1]); delay_ms(1);
         write_to_adf4351(reg[0]); delay_ms(3);
   }       
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group