Controlling PLL with SPI

22 Nov 2010

 

Hello,

Above all I would like to apologize for the quality of my English. I'm french.

I'm a beginner and want to do some work with my mbed 1768 : I want to control ADF4360 (PLL) in order to generate a specified frequency (850Mhz). I manage to generate it from the software included with the card.

Here you can find the datasheet.

A printscreen of the software and the register which is send to ADF4360

 

In my spectrum analyzer, it works good. 850Mhz appears well.

I tried to do it without PC and with Mbed1768 and it doesn't work.I have not enough knowledge in electronic.

Here is what I send to my ADF4360 :

#include "mbed.h"


SPI spi(p5,p6,p7);


int main() {
    
    spi.format(16,2);
    spi.frequency(1000000);
    spi.write(0x846A);

}
and nothing appears in my spectrum analyzer.

That's why i need your help, maybe you can direct me to a working track. I would be most grateful to you for this.

Best regards,

 

 

 

 

 

 

 

 

 

 

22 Nov 2010

Most SPI interfaces also need a "chip select" signal (known as CS) and your program doesn't appear to have this.

Looking at the datasheet Pin 19 appears to be LE (latch enable) and the timing diagram shows the data aligned to this signal.

Connect the Mbed pin p8 to this LE pin 19 and then do this:-

#include "mbed.h"


DigitalOut le(p8);
SPI spi(p5,p6,p7);


int main() {

    le = 1;
    spi.format(16,0);
    spi.frequency(1000000);

    le = 0;
    spi.write(0x846A);
    le = 1;
}

Notice also that we use format(16,0) and not 16,2

Mode 2 latches the data on the falling edge of the clock but the data sheet timing shows it latches on the rising edge.

22 Nov 2010 . Edited: 22 Nov 2010

Also, looking further, you need to send 24bits (3 bytes) to write to one of the 3 latches.

so you will need to do something like this:-

uint32_t data;  // holds the three bytes, top 8 unused.
le = 0;
spi.write(data >> 16 & 0xFF);
spi.write(data >> 8 & 0xFF);
spi.write(data & 0xFF);
le = 1;

Page 13 of the data sheet shows the structure of the 24bit "word" you need to send.

http://www.dynamics.co.nz/media/DOCUMENTS/DATA_SHEETS/ADF4360_7_a.pdf

22 Nov 2010

thanks for your help.

If i connect Mbed p8 to LE pin 19, where am i suppose to connect p5 et p6 ( P7 on clock i suppose) ?

My ADF has 3 pins : CLK, DATA and LE.

 

22 Nov 2010

p5 goes to DATA, p7 goes to CLK and p8 to LE

do you have a datasheet for the device/module you are using? All I could find was the actual chip datasheet and it seems you are using a module of some sort

22 Nov 2010

No, i have not. All i have it's the datasheet from the .pdf file.

 

If i want to send 0x1092A by spi (24bit), what is the code please? i cannot understand yours.

uint32_t data;  // holds the three bytes, top 8 unused.
le = 0;
spi.write(data >> 16 & ????);
spi.write(data >> 8 & ????);
spi.write(data & ????);
le = 1;
p6 is connected to nothing?

thanks for your help

22 Nov 2010 . Edited: 22 Nov 2010
uint32_t data = 0x1092A;  
le = 0;
spi.write(data >> 16 & 0xFF);
spi.write(data >> 8 & 0xFF);
spi.write(data & 0xFF);
le = 1;

Yes, p6 is not connected as the device doesn't have a miso signal/pin so it's write only.

If you understand the parts that make up the 3 24bit latches that make up the ADF4360 then I just made this that may help you:- MODADF4360

22 Nov 2010 . Edited: 22 Nov 2010

 

A lot of thanks for you help.

As a tell you, i am a mbed beginner.

 

 

 #include "mbed.h"
 #include "MODADF4360.h"

 DigitalOut led1(LED1);
 ADF4360 adf(p5, p6, p7, p8);

 int main() {

     // Setup all the parts of the Control Latch
     adf.prescalerValue(1);
     adf.cpGain(1);
     adf.powerDown1(0);
     adf.powerDown2(0);
     adf.currentSetting2(111); //  is it wright?
     adf.currentSetting1(111); // 
     adf.outputPowerLevel(0);
     adf.muteTillLockDetect(0);
     adf.cpGain(0);
     adf.cpOutput(0);
     adf.phaseDetectPol(1);
     adf.muxControl(000);
     adf.counterReset(0);
     adf.corePowerLevel(0);
     //... set all the parts you need, then...
     
     // Once all the parts ate set, write them to the device.
     adf.controlLatchWrite();

     // repeat for N and R latches.

     while(1) {
         led1 = !led1;
         wait(1);
     }
 }

 

 

 

 

 

is it the wright way to put the 1st latch as the printscreen i have posted before?

as there a possibility to have a code like this : adf.ControlLatch(0x"24bitword");

adf.Ncounter(0x.....);

adf.Rcounter(0x.....); ???

 

 

 

 

 

22 Nov 2010

No, use numerics, eg for binary 111 you would do adf.currentSetting2(7);

 

The bit fields of each latch are broken down into "mini integers"

22 Nov 2010

ok, i fix that, but still nothing appears in my spectrum analyzer.

 

Here's my code :

#include "mbed.h"
#include "MODADF4360.h"

DigitalOut led1(LED1);
ADF4360 adf(p5, p6, p7, p8);

int main() {

    // Setup all the parts of the Control Latch
    adf.prescalerValue(2);
    adf.cpGain(1);
    adf.powerDown1(0);
    adf.powerDown2(0);
    adf.currentSetting2(7); //  is it wright?
    adf.currentSetting1(7); //
    adf.outputPowerLevel(0);
    adf.muteTillLockDetect(0);
    adf.cpGain(0);
    adf.cpOutput(0);
    adf.phaseDetectPol(1);
    adf.muxControl(0);
    adf.counterReset(0);
    adf.corePowerLevel(0);
    // Once all the parts ate set, write them to the device.
    adf.controlLatchWrite();

    //Setup all the parts of the NCounter Latch
    adf.divideBy2Select(0);
    adf.divideBy2(0);
    adf.nCPGain(0);
    adf.counterB(132);
    adf.counterA(26);
    //
    adf.counterNWrite();


    //Setup all the parts of the RCounter Latch
    adf.bandSelectClock(3);
    adf.testModeBit(0);    
    adf.lockDetect(1);
    adf.antiBacklash(0);
    adf.counterRef(50);
    //
    adf.counterRWrite();

    while (1) {
        led1 = !led1;
        wait(1);
    }
}
did i miss something ?

 

Is there a possibility to have a code like this ?

 

adf.ControlLatch(0x"8FC100");

adf.Ncounter(0x846A);

adf.Rcounter(0x3400C9);

 

 

Thanks again for your help.

 

22 Nov 2010
adf.ControlLatch(0x"8FC100");

adf.Ncounter(0x846A);

adf.Rcounter(0x3400C9);

Yes,

Divide up your three bytes and send "raw" like posted eariler. For example, without using the lib I made:-

#include "mbed.h"

SPI adf(p5, p6, p7);
DigitalOut le(p8);

// Writes the three bytes in data to teh ADF device.
void adfWrite(uint32_t data) {
    le = 0;             
    adf.write(data >> 16 & 0xFF); 
    adf.write(data >> 8 & 0xFF);
    adf.write(data & 0xFF);   
    le = 1;
}

int main() {
    le = 1;
    adf.format(8,0);
    adf.frequency(1000000);

    adfWrite(0x8FC100);
    adfWrite(0x846A);
    adfWrite(0x3400C9);

}

 

 

 

 

22 Nov 2010

We can see on an oscilloscop that the 3 "words" are well sent but still nothing appears in the spectrum analyzer.

The same register sent by PC works fine. I think code and connection are OK. I'm a little lost btw.

22 Nov 2010

If your scope is dual beam can you check on one trace the LE signal and the other the DATA. Ensure LE goes low, 3 bytes get sent, then LE should go high. Check on both PC and mbed and compare.

I don't have the ADF4360 hardware here to play with and try out for myself so it's rather hard to debug code.

22 Nov 2010

One more thing, how is the PC conectted to your device? PCs generally don't have an SPI interface so there must be something between teh PC and your device ??

22 Nov 2010

We are going to make this tests.

Pc is connected by serial port, according to this :

 

 

22 Nov 2010

You said "serial port" which is not SPI. But the disgram says "PC Printer port" which, under software, can mimic an SPI port. I guess it's the later.

22 Nov 2010

Also, I see you connected p5, p7 and p8 according to your diagram. Do rthe eval board and the Mbed share the same GND? (0v)

22 Nov 2010

 

this is the test with data/LE :

 


and now, the test with data/clk :

 

 

 

thanks for all, waiting for your answer.

22 Nov 2010

Are these tests with teh Mbed? If so, in teh first one, LE appears to be low all the time. It should start out high, go low just before the first byte and remain low until the end of the third byte whereupon it should return high

22 Nov 2010

user Andy Kirkham wrote:
Are these tests with teh Mbed?
Yes.

user Andy Kirkham wrote:
LE appears to be low all the time

Our oscilloscop has a x10 rate.

 

Is that our main problem? should we change pin?

22 Nov 2010

well, get rid off any obvious probles:-

#include "mbed.h"
DigitalOut P8(p8);
int main () {
    while(1) {
        P8 = 1;
        wait_us(1);
        P8 = 0;
        wait_us(1);
    }
}

Does that make p8 toggle on your oscilloscope?

Try to approach the problem by seeing what does and doesn't work, writting little test programs like this if needs be. Your scope seems to show DATA sending out the 3bytes. So SPI appears to be working. Just I don't see LE working. Is Mbed actually sending LE or is teh scope not seeing it? Be methodical and think about each bit as you write code and think ahead of what you then expect to see on the scope.

 

 

 

25 Nov 2010

Hello,

 

p8 works fine, we made tests.

 

 

 

 

 

This is what we got with your code.In yellow, LE seems to be good. In blue DATA abd clock too. We think that it's what we should expect but adf4360 doesnt work again. Do you think that the problem comes from the ADF ?

 

 

Have a good day

25 Nov 2010

Sure is a puzzler. Is there any way I can get hold of one of these eval boards? I found this from farnell but a bit expensive.

25 Nov 2010

I will ask our teacher where he got our eval boards.

We are students working in a project.

We think that our tests with oscilloscope show that the 3 bytes are well sent. It may be a problem with the ADF ?

 

 

 

25 Nov 2010

Try slowing down the SCLK frequency to something really low like 200kHz instead of 4MHz. Also, since you have now shown that the format looks ok, remove any test probes from the SCLK line and just look at CS and DATA in future. I have found loading teh sclk signal can effect the spi timing.

If the ADF board works with the PC program but not with the Mbed then it suggests your ADF is ok. One last point, you are sending 3bytes (24bits). You are sending nine bytes really right? I mean, there are 3 24bit registers to load, Control, N and R.

[ Edit: oh, I can see all 9bytes in the trace you posted ]

29 Nov 2010

Hello,

We did some test and we found our problems. It was a connection problem. We can explain it if someone is interested. We certainely need your help in the future. Thank you again for your all help.