Help with AD9833 SPI module. no response from microcontroller. - Page 1
Forum section: electronics / projects

author: Arty30
author_rank: Regular Contributor
timestamp: June 05, 2025, 06:08:01 pm
content: Hello all, I'm working on building a homemade function generator following the plans found onhttps://electro-dan.co.uk/blog/48/a-frequency-function-generator-using-ad9833-and-raspberry-pi-pico. I like the plans and I'm straying a little by integrating a DS0138 O-scope that I've barely used in 6 years. I did the first fire up yesterday and all was well except for no waveform from the 9833. I did some snooping and I believe I had correct comms over SPI from my pico to 9833. I quickly whipped up a test breadboard to isolate just the 9833 module and I now have nice looking sine wave, but I still have no control over it as it just runs immediately on power up. I verified SPI commands again so at this point I'm scratching my head. I wish I got a two pack so I could try a different module. if anyone has any ideas I would love to hear them.Thanks.Arty.

author: shabaz
author_rank: Frequent Contributor
timestamp: June 05, 2025, 07:44:28 pm
content: You didn't mention whether the buttons still respond (I.e. do you still see activity on the LCD screen when the buttons are pressed) or whether it appears the software has totally stopped working.You'd need to do more troubleshooting, for instance, confirm that the software is behaving as expected (run a serial console on your PC and check to see if text appears) and you may need to insert some print statements into the code to try to follow what's going on (the code is in MicroPython so you don't need to recompile anything, just edit the code and re-upload it).Sometimes the actual version of MicroPython can make a difference.Are you using the same Pi Pico version as the author did, or a different version?It would be good to see if the SPI activity is as expected. But that may be difficult if you have limited test equipment (although there are workarounds, but I think some print statement debug may get you far anyway).Plus, it's good to work incrementally, I.e. just test without any amplifier and PSU for now, just running off the USB power.Also some photos would help, in case any physical construction error is easy to spot from there.

author: Arty30
author_rank: Regular Contributor
timestamp: June 05, 2025, 11:11:03 pm
content: Apologies, I need more details. The rest of the system is working as intended. I can continuously change waveform and frequency, the program does not crash. I also used my Digilent Analog discovery 2 device with the logic analyzer to monitor the SPI bus and I see data that I believe to be correct, including a reset command on power up, and frequency change command afterwards. I can continuously send commands from the keypad to no effect. As I poorly explained earlier I also took just the Pico and the AD9833 and set it up on a breadboard with bare minimum code and verified the same communication from the Pico, still to no effect. The only difference I have is now I do have a waveform from the module, just with no control over it. It appears that the module just runs automatically? I still need to test my amplifier, which may be the cause of no waveform initially.Its always the digital stuff that gets me, I did kill the op-amp somehow before powerup, maybe the module suffered the same?Arty.

author: shabaz
author_rank: Frequent Contributor
timestamp: June 06, 2025, 12:18:37 am
content: There's just too many variables to be able to narrow this down unfortunately, it will need more investigation. The code running on the Pico on the breadboard doesn't know there is no keyboard or LCD screen attached, so it should behave identically in the full implementation and the breadboard minimal version. Since it doesn't behave the same, that needs to be examined, for instance, there may be a wiring issue (e.g. intermittent jumper wires) that prevented operation with the full implementation. Or, you mentioned the op-amp was destroyed, but whatever caused that, may have damaged other things too.If it were me, I'd try to get it running in the minimal version first. You mention you do see a signal. In the config.xt file, there is a value 1000.0 which corresponds to 1 kHz (you'd need to confirm with a 'scope if that's the frequency you see). You could change that value in the config.txt file, and see what happens.Also in the main code (main.py file), you can see the default frequency there is 1 kHz which might override if the config.txt file is not readable, so it's worth changing that too if the config.txt file change doesn't work.

author: Arty30
author_rank: Regular Contributor
timestamp: June 06, 2025, 03:39:27 pm
content: Thanks for your input, I can confirm that the frequency that it runs at just on startup is not 1kHz, it is roughly 100kHz. I may get another module since they are relatively inexpensive and I really want to rule it out and assume that the problem is me or my code.

author: MarkF
author_rank: Super Contributor
timestamp: June 07, 2025, 10:56:41 am
content: Post your test code so we have something to analyze.Especially the SPI setup and configuration and the code you're sending to change the freq.- Are you using the correct SPI mode for the AD9833? (My code comments indicate SPI Mode 2 for AD9834.)- Are you correctly writing 16 bits for each command?- Is your SPI clock within the max freq of the AD9833?A few notes:- Your op-amp will not be able to output much power (especially into a 50ohm load). I limited my output to 2Vp-p. Otherwise the op-amp will over heat. If I spin a new version of my PCB, I will go with an op-amp in a through-hole DIP package instead of a SMD chip. Simply to try to dissipate the heat.- I believe the AD9834 to be a better choice because the amplitude adjustment is accessible and it has a complementary output. It's a little more complex but gives you some interesting options for additional waveforms. The advantage of the complementary output is that you can adjust the gain WITHOUT effecting the DC offset. You can checkout myAD9834 based Function Generator. I show the schematic, filter design and several waveform captures there.- With a separate output for the sign-bit, I was able to provide frequency sweep and PWM waveforms. These are digital output levels and not adjustable in my design. Although, there is jitter on the square wave (sign-bit) output. You are able to set the AD9834 sign-bit output to a high impedance state in order to directly multiplex it with a PWM pin from the host MCU. (The separate digital output also allows for a trigger sync pulse when generating a frequency sweep.)

author: passedpawn
author_rank: Contributor
timestamp: June 16, 2025, 02:55:00 am
content: Try probing all SPI signals at the same time. I once had the same problem. I checked each SPI signal one at a time, and did witness each signal toggling. When I obsserved them altogether, it turns out that I was releasing the CS signal before the message was finished transmitting.

author: passedpawn
author_rank: Contributor
timestamp: June 16, 2025, 02:58:07 am
content: I also have lots of code related to this function generator. Nothing for the PI, it's all ANSI C for various microcontrollers. I drove two of them into a mixer to do some interesting AM modulation as well as sweeps etc.