going mad trying to get adf4350 to work - Page 1
Forum section: electronics / rf-microwave

author: drspastic
author_rank: Contributor
timestamp: February 24, 2025, 01:25:14 pm
content: this is aimed at people who have succeeded in using the adf43x boards with arduino code!!!here are the boards i have tried:https://www.aliexpress.com/item/1005006127000674.htmlhttps://www.aliexpress.com/item/1005007436153280.htmlhere is my esp32 code that i hoped would produce an output, the library ishttps://github.com/darkbyte-ru/ADF4350-yes its unfinished but should work i think:Code://first the PLL stuff#include <SPI.h>#include <ADF4350.h>#define PLL_LE_PIN 25#define PLL_LD_PIN 14ADF4350 PLL(PLL_LE_PIN);#define BME_SCK 33//#define BME_MISO 32#define BME_MOSI 26#define BME_CS 19#define PDRF 12// which is supposed to have set the spi pins#define PLL_REFERENCE_FREQ 10 //MHz clock//set up the pins that will eventually activate the output#define vfoaEN 13#define vfobEN 15//now the display stuff#include <Adafruit_GFX.h>#include <Adafruit_ST7735.h>#include <ezButton.h>//the rotary encoders#define CLK_PIN 34#define DT_PIN 35#define SW_PIN 32#define CLK_PIN2 4#define DT_PIN2 16#define SW_PIN2 17#define DIRECTION_CW 0#define DIRECTION_CCW 1//more display pins#define TFT_CS 5#define TFT_RST 2#define TFT_DC 0#define TFT_BL 22//initial vfo valueslong long vfoa = 300000;long long vfob = 2400000;long long adjustmentA = 1;long long adjustmentB = 1;int direction;int direction2;int prev_CLK_state, prev_CLK_state2;bool updateVFOA = false, updateVFOB = false;Adafruit_ST7735 tft(TFT_CS, TFT_DC, TFT_RST);ezButton button(SW_PIN);ezButton button2(SW_PIN2);void highlightDigitRightJustified(long long value, long long adjustment, int y, uint16_t normalColor, uint16_t highlightColor) {char buffer; // Ensure buffer size is large enough for leading zerossprintf(buffer, "%007lld", value); // Format frequency as 7 digits with leading zeros(reduced from 10)// Calculate the total text width (12 pixels per character for text size 2)int textWidth = strlen(buffer) * 12;//was 12 but texsize 3 was getting trimmed// Starting X position for right justification (160 is screen width) revised to 100int xStart = 90 - textWidth;// Find the index of the digit to highlightint digitIndex = 6 - log10(adjustment); // Determine which digit corresponds to the adjustment// Render the frequency string with highlightingfor (int i = 0, pos = 0; i < strlen(buffer); i++) {// Highlight the correct digitif (pos == digitIndex) {tft.setTextColor(highlightColor, ST77XX_BLACK);} else {tft.setTextColor(normalColor, ST77XX_BLACK);}tft.setCursor(xStart + pos * 12, y);//was12tft.print(buffer);pos++;}}void updateDisplayVFOA() {// tft.setTextSize(3);tft.fillRect(0, 20, 160, 20, ST77XX_BLACK); // Clear the areahighlightDigitRightJustified(vfoa, adjustmentA, 20, ST77XX_GREEN, ST77XX_RED);// Correctly justify "KHz" under the VFOA displaytft.setTextSize(2);tft.setCursor(124, 20); // Position "KHz" to be right-aligned was 40tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);tft.print("KHz");}void updateDisplayVFOB() {tft.fillRect(0, 70, 160, 20, ST77XX_BLACK); // Clear the areahighlightDigitRightJustified(vfob, adjustmentB, 70, ST77XX_YELLOW, ST77XX_RED);// Correctly justify "KHz" under the VFOB displaytft.setTextSize(2);tft.setCursor(124, 70); // Position "KHz" to be right-aligned was 90tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);tft.print("KHz");tft.setCursor(124, 100); // Position pll Lock//tft.print( "LOCK" );//tft.print(PLL_LD);}void setup() {//init ADF4350 with 25MHz reference and tune to 433000 KHz just for testingSerial.begin(115200);PLL.initialize(vfoa, PLL_REFERENCE_FREQ);pinMode(BME_CS, OUTPUT);pinMode(PLL_LD_PIN, INPUT);pinMode(PDRF,OUTPUT);digitalWrite(PDRF,HIGH);digitalWrite(BME_CS,HIGH);//default power is 0, which means -4dBmPLL.setRfPower(0);//display setuptft.initR(INITR_BLACKTAB);//its green tab but this works bestpinMode(CLK_PIN, INPUT);pinMode(DT_PIN, INPUT);pinMode(CLK_PIN2, INPUT);pinMode(DT_PIN2, INPUT);pinMode(TFT_BL, OUTPUT);digitalWrite(TFT_BL, HIGH);//buttons and rotary encodersbutton.setDebounceTime(50);button2.setDebounceTime(50);prev_CLK_state = digitalRead(CLK_PIN);prev_CLK_state2 = digitalRead(CLK_PIN2);//more display stufftft.setRotation(1);tft.fillScreen(ST77XX_BLACK);tft.setTextSize(2);//was 2 damn i want 3 but it wont format rightupdateDisplayVFOA();updateDisplayVFOB();}void loop() {button.loop();button2.loop();//lock indicatorint PLL_LD = digitalRead(PLL_LD_PIN);//lock indicatortft.setCursor(50, 100); // Position pll Locktft.print( "LOCK" );tft.setCursor(124, 100); // Position pll Locktft.print(PLL_LD);PLL.initialize(vfoa, PLL_REFERENCE_FREQ);digitalWrite(BME_CS,HIGH);int CLK_state = digitalRead(CLK_PIN);if (CLK_state != prev_CLK_state && CLK_state == HIGH) {if (digitalRead(DT_PIN) == HIGH) {vfoa -= adjustmentA;direction = DIRECTION_CCW;} else {vfoa += adjustmentA;direction = DIRECTION_CW;}updateVFOA = true;}prev_CLK_state = CLK_state;int CLK_state2 = digitalRead(CLK_PIN2);if (CLK_state2 != prev_CLK_state2 && CLK_state2 == HIGH) {if (digitalRead(DT_PIN2) == HIGH) {vfob -= adjustmentB;direction2 = DIRECTION_CCW;} else {vfob += adjustmentB;direction2 = DIRECTION_CW;}updateVFOB = true;}prev_CLK_state2 = CLK_state2;if (updateVFOA) {updateVFOA = false;updateDisplayVFOA();}if (updateVFOB) {updateVFOB = false;updateDisplayVFOB();}//these i took 3 zeroes off to register only in khz and not loop to hz which is no longer on screenif (button.isPressed()) {adjustmentA *= 10;if (adjustmentA > 1000000) {adjustmentA = 1;}updateVFOA = true;}if (button2.isPressed()) {adjustmentB *= 10;if (adjustmentB > 1000000) {adjustmentB = 1;}updateVFOB = true;}}and heres someone elseshttps://gist.github.com/racerxdl/448f334aaa1cee954cf41c75167e4cc1code i tried, and im not sure what com pin is for, i used the default spi pins clk mosi and cs:Code:#include <SPI.h>#include <ADF4350.h>#define COM_PIN D0ADF4350 PLL(COM_PIN);void setup(){SPI.begin();SPI.setClockDivider(SPI_CLOCK_DIV4);SPI.setDataMode(SPI_MODE0);delay(1000);PLL.initialize(220, 10);delay(200);PLL.setAuxPower(0);PLL.setRfPower(0);delay(100);PLL.auxEnable(true);delay(100);}void loop() {// for (int i = 0; i < 4; i++) {// delay(1000);// PLL.setAuxPower(i);// PLL.setRfPower(i);// }delay(1000);PLL.setFreq(220);PLL.setAuxPower(0);PLL.setRfPower(0);delay(1000);PLL.setFreq(230);PLL.setAuxPower(0);PLL.setRfPower(0);}i tried to pull up ce pin, tried pull down...on the small board tried with rf powerdown held up or down. all i get is a little noise. ocaisionaly the bigger board has its lock led come on but dim and i cant make it satble with pull up/down on pins.on my long code you see i set the spi pins to the ones i used for the adf435x board. the esp is also connected to colour lcd and 2 rotary encoders.and here is the wiring:Code:esp encoder a32 sw35 dt34 clkencoder bsw 4dt 16clk 17lcdled 22sck 18sda 23a0 0reset 2cs 5adf4350ce 19 xclk 33 x clock orangele 25 x link enable yellowdata 26 x data greenmout 27 multiplex outld 14 lock detectpdrf 12 power down rf white13 vfoa out15 vfob out//esp32lite default spi pins22 scl19 miso23 mosi18 sck5 ssthis is really starting to wind me up. can someone put me straight please, or give me an example that will definately work so i have a starting point. esp32 or esp8266 because 3.3v! i dont own any actual arduino. i dont have the gear to plug the boards into a pc and i dont own a copy of windows!sorry to sound like a karen, but otherwise i expect all sort of suggestions that are totally irrelevent to the project.

author: shabaz
author_rank: Frequent Contributor
timestamp: February 24, 2025, 01:42:57 pm
content: Without your identical setup, you would need to do some testing.Some code was provided to you on another thread:https://gist.github.com/shabaz123/ff486699ef471132e940f55f26f74a66It was tested to the extent of seeing if the outputs looked approximately correct on a logic analyzer (in the absence of your actual setup).Since that didn't work for you, and if you're not in a position to troubleshoot, I suggest you start small, write some code to write just a fixed frequency to one board, then to two boards. That will confirm your two boards are electrically functioning, and that their connections are sound, and that you're able to observe the output.Once you're there, then you can consider adding the rotary encoders.Just get your two ADF boards functioning first.

author: drspastic
author_rank: Contributor
timestamp: February 24, 2025, 04:04:32 pm
content: ok so before i do that, what should the pins NOT used by spi be strapped to?CE which i assumed was needing +3.3vother pins muxout and lock detect which is output so i can ignorepdrf power down rf which i assume is 3.3v to activate the rf output.i just want to make sure its wired right first.then i will try again the 8266 program again which only produces rf, and i have this esp32 code from darkbyte, where the library came from:Code:#include <SPI.h>#include <ADF4350.h>#define PLL_LE_PIN 8ADF4350 PLL(PLL_LE_PIN);void setup(){//init ADF4350 with 10MHz reference and tune to 432.000MHzPLL.initialize(432000, 10);}which i can try on a spare esp32c3 as i dont need any inputs or display, but i still need to ensure the default spi pins are correct.but why is the LE pin specified and is it not the same as CE pin of spi inteface? i know MOSI is data from esp32 to adfxxxx board and i know clock. MISO isnt used because there is no data to read. SS labeled as spi pin on the photo above must be CE then?its a damn pity they cant just write a simple instruction and demo code when they sell these boards. and also be nice if people stick to naming conventions ie make their mind up if clock is SCK CK CLK CL or whatever. when theres lots of wires and labels it can add to confusion.PS. another radio ham suggested some of the spi and control lines may need a pullup/down resistor. i dont know more than that. i think that might be something that can be done internally with code on esp32 but i never tried before. or is it better to solder real resistors to the board, and if so where?PPS. LE is listed everywhere as link enable, but is this the same as latch enable? is this to hold the information written to the registers?Update: so i just found more info, and tried a attiny85 sketch that doesnt use a library. still no output on either board. i can see pulses going on at clock data and mosi. not sure what to do now. i cant just keep buying boards in the hope one works. but they cant be all duff. i definately didnt blow them up. 3.3v from bench supply, antistatic bench, etc

author: shabaz
author_rank: Frequent Contributor
timestamp: February 24, 2025, 06:52:25 pm
content: I can't comment on the various recommendations on pin connections you may have received from elsewhere, but when I looked at the code for you, I made some notes about what the pin connections should be, if you use the library which I used for the code. I'd recommend using that, I believe it works (at least, the output looked about right to me on the logic analyzer).If you use that code, then you can use the information in the comments at the top of the code, to guide you on the pin connections. If you use a different library or different suggestions then all bets are off, those connection recommendations in my code therefore won't work in that case.I'll paste the detail here but it's in the code:QuoteNote: I suggested leaving CE and PDRF connections alone, but you may wish to set them high (i.e. 3.3V) - I don't know if the board by default has them high, but you can hard-wire those to 3.3V if you wish, through (say) a 1 kohm resistor just for a bit of flexibility.I used an ESP32-S3 based board, because that's all I had to test with. You'll possibly need to change some of the connections if you're using a different ESP32 board (and then, of course, change the code pin assignments in the #define statements, to suit).

author: paul@yahrprobert.com
author_rank: Regular Contributor
timestamp: February 25, 2025, 03:49:50 am
content: Hi,I have written code that runs on an ATMEGA32U4 that successfully programs an ADF5355. It has a very similar register layout to your ADF4350, also an identical set of programming pins and protocol.When faced with getting spi to work on such a project I always chicken out and just do "bit banging", especially in a case like this where speed is of no concern when just initializing the chip. The below code writes to a register on the chip. I write in straight C, using avrlibc and avrdude to compile and program, no arduino stuff.In the code below there are macros that set and clear the pins for LE, CLK, and DATA. This has been working successfully on my chip for a year or two. I've also written very similar code for the ADF41513 and ADF4169.A few things to remember: you have to program the registers in order, with register 0 being the last one you write. This is all spelled out in the data sheet. Also note from the data sheet that the bottom 3 bits of each register contain the register number that you're trying to program. Even if you will end up using your MCU's spi machinery to program the chip, I think it might help to get the bit banging approach working first to get a known set of registers working.Code:void write_register( byte *data){byte ibyte,x, ibit;SET_LE;nop();nop();CLR_LE;nop();for(ibyte=0;ibyte<4;ibyte++){x=*(data+ibyte);for(ibit=0;ibit<8;ibit++){//do the highest bit firstif(x & (byte)0x80){SET_DATA;}else{CLR_DATA;}//shift left for next bitx=x<<1;nop();SET_CLK;nop();CLR_CLK;nop();CLR_DATA;nop();}}nop();SET_LE;nop();nop();CLR_LE;}

author: drspastic
author_rank: Contributor
timestamp: February 25, 2025, 06:56:55 pm
content: from where did you get your adf4350.h library. there are several in github all named the same of course which may be obvious to seasoned programmers but confuses me to say the least. i really dont want anything from this thread than to see an output wave on my scope or hear it on my radio. no controllers or display, no feedback from pll lock, the board has an led for that.as for atmega code in c, well that just threw in the bin the whole idea of the pll im using, the mcu im using, the language and ide im using, and i dont understand any of it. thats like you bring me a tesla to fix and i recommend you drive a nissan micra.

author: shabaz
author_rank: Frequent Contributor
timestamp: February 25, 2025, 07:49:02 pm
content: I used the library from here:https://github.com/darkbyte-ru/ADF4350I had placed a copy of it in the zipped up folder that I provided a link to in your other thread.Basically, you need the ADF4350.cpp and ADF4350.h files from that GitHub repository to be in the same folder as your Arduino .ino file.

author: paul@yahrprobert.com
author_rank: Regular Contributor
timestamp: February 25, 2025, 11:31:24 pm
content: With the atmega code, what I'm trying to convey is that you don't necessarily need a library for the device or any particular processor. All you need is the data sheet for your device, any processor, and control of the CLK, DATA, and LE pins. I know, too much trouble, but that's all I have.

author: drspastic
author_rank: Contributor
timestamp: February 26, 2025, 02:17:56 pm
content: @shabaz. i am loading library from zip in the menu. everything should be in the right place@paul. i understand that but i am not used to these chips and i just needed to veryfy if they work. i read the datasheet.i tried this on attiny85 (digispark) and i know now what lines to pull up or down. no driver involved.https://github.com/ok1cdj/ADF4351-basic-LOits written for attiny13 but compatible with attiny85, and on advice of the author i reduced digispark clock speed to 8mhz which is closest to the attiny13 default 9 and a bit.still no joy out of either board so im going to have to sack them off for a bit. i have ordered 2 new adf4350 chips and i will solder them into the boards and start again. i just got unlucky. there has been a lot of people getting boards with 5v regulators instead of 3.3v but i checked mine under the microscope and both have correct chips, and i ran them from 3.3 on lab supply only. its going to be fiddly changing the chips but then i will have 2 good boards and maybe i will rework my ui code to use both at the same time for full duplex.