PLL Code

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

Sorry to bother you, guys!
I have a working project that involves ATMEGA8 and ADF4117 PLL synthesizer.

I need to change the registers inside the synthesizer to give me different divider/prescaller ratios. I know what registers are needed, but I do not have the source code for the existing working ATMEGA8, so I need to reprogram it.

The problem is that I do not know how to write the code to use SPI to reprogram the ADF4117 registers.

If someone can shed some light on my issue, would be very appreciated !

YO9ICT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A quick peek at the data sheet shows that this device implements 4 registers.
You clock in a 19 bit register value MSB first, followed by a two bit register selector.

The gist of the procedure would be something like this...

Given a value V to write into register N...
long data = ( V << 2) | N;

Configure the SPI hardware for mode 0, MSB first.

Pull 'LE' low.

Write byte 2, byte 1, then byte zero of 'data' to SPDR, waiting for SPIF to be set after each write.

Raise 'LE'. Done.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your answer!

As I see in the datasheet, I need to write 4 times the 19 bit registers, the last 2 bits are the selectors. Also, the datasheet helps me choosing the appropiate value for all the 4 registers.

In theory, it is understandable.
In practice, I do not know where to start from.

Is there any sample code that I can modify to do my thing?

YO9ICT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did not see any sample code. You might dig around the AD web site and find something, but I doubt it will be avr code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SPI can only send in 8-bit blocks.

One of the things that may help you is that AD tends to arrange the function so that the LAST 19 bits (when the enable bit gets changed) is what it stores. So, send 24 bits, make the first bits are dummy - don't contain anything significant. Make the last 19 bits the data bits.

This may involve some data shifting as you construct the message or it might involve something else like a struct where you can easily access things both at a bit level and a byte level.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just found a code for the ADF4118 (near identical to my ADF4117) here:

http://www.circuitsonline.net/fo...

 /*
 * Test_SPI_naar_ADF4118.c
 *
 */ 
 
#include 
#include 
 
int main(void)
{
DDRB  |= (1<<PORTB2) | (1<<PORTB3) | (1<<PORTB5);	// SCK, MOSI and SS as outputs
PORTB |= (1<<PORTB2);				        // Set SS HIGH before activating SPI	
SPCR  |= (1<<SPE) | (1<<MSTR) | (1<<SPR0);		// Enable SPI; Set as Master; Clock = Fosc/16 
 
_delay_ms(1);
 
PORTB &= ~(1<<PORTB2);			// Set Slave Select LOW
SPDR = 0x82;				// Send data to slave
while(!(SPSR & (1<<SPIF)));		// Wait for transmission to complete
PORTB |= (1<<PORTB2);			// Data is latched on rising-edge of SS
 
PORTB &= ~(1<<PORTB2);			// Set Slave Select LOW
SPDR = 0x02;				// Send first byte to slave
while(!(SPSR & (1<<SPIF)));		// Wait for transmission to complete
SPDR = 0x00;				// Send second byte to slave
while(!(SPSR & (1<<SPIF)));		// Wait for transmission to complete
PORTB |= (1<<PORTB2);			// Data is latched on rising-edge of SS
 
PORTB &= ~(1<<PORTB2);			// Set Slave Select LOW
SPDR = 0x10;				// Send first byte to slave
while(!(SPSR & (1<<SPIF)));		// Wait for transmission to complete
SPDR = 0x34;				// Send second byte to slave
while(!(SPSR & (1<<SPIF)));		// Wait for transmission to complete
SPDR = 0xe5;				// Send third byte to slave
while(!(SPSR & (1<<SPIF)));		// Wait for transmission to complete
PORTB |= (1<<PORTB2);			// Data is latched on rising-edge of SS
 
SPCR &= ~(1<<SPE);			// Disable SPI interface
 
while(1);
}

But I see only 3 cycles...maybe someone can shed some light here.

Thanks

YO9ICT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks to me like it is writing two "messages" of 3 bytes = 24 bits each.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes Jim, it looks to me the same.

But why ? The PLL synthesizer need 4 "messages" of 21 bits each. Considering the SPI cannot send less than one byte at a time, I need to send 4 "messages" of 24 bits each, so the first 3 bits need to be dummy bites. So 4 * 3 bytes.

So I need to send something like this:
To initialization register : 0xXX then 0xXX then 0xXX
To function register : 0xXX then 0xXX then 0xXX
To AB register : 0xXX then 0xXX then 0xXX
To reference register : 0xXX then 0xXX then 0xXX

Given this, what are the modifications that need to be made to the above code?

Another quick question:I need to program the PLL once after each powerup or I need a "continuous" programming?

YO9ICT