 |
 |
| View previous topic :: View next topic |
| Author |
Message |
patan_mustafa
Joined: 10 Dec 2006 Posts: 3
|
| ADF4351 Frequency Generator Code |
Posted: Sun Feb 09, 2025 12:54 am |
|
|
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);
}
}
|
|
|
 |
djsb
Joined: 29 Jan 2011 Posts: 57
|
|
Posted: Thu Nov 19, 2026 1:54 pm |
|
|
| Where is the rest of the code? And it would be nice if the cost was commented. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20163
|
|
Posted: Sun Nov 29, 2026 12:23 pm |
|
|
It's the routine to drive this chip. Generates the frequency asked for.
It is entirely up to you to write the value into 'frequency', based on the
setup of your chip, and then just call the set_freq routine. I must admit
I think I'd rather have this routine accept an int32 value, and do the
maths for you to get the value to send to the chip, but it is a good basic
start to driving this frequency generator. |
|
 |
|
|
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
|