#help-with-radio
1 messages · Page 2 of 1
Fairly low-level, so a little assembly-language-ish, direct register access to chip peripherals, stuff like that.
The FFT is relatively easy, though, as there are libraries for that.
Didn't you say advanced coding above
That's what I thought, such as FFT pack from SciPy
Assembly language for what
Yes, but I mean to get the RP2040 talking to the ADC. That's the advanced part.
Oh
Right
Makes sense
The RP2040 has to grab data from ADC
Doesn't seem impossible
Probably youtube tutorials for it
Or books
You'll find tutorials about how to use ADCs in general, but not necessarily how to interface to your specific chip or how to reads at millions of samples per second.
Again, not impossible, just tricky.
Yeah, seems pretty tough
As the ADC has to comply with the RP2040
It's more like "your software has to MAKE the RP2040 comply with the ADC".
Yes
I found tutorials and resources for 500kHz sampling
But I need 2MHz at least
Doesn't the RP2040 have its own ADCs. ADC overview
The RP2040 has an internal SAR (Successive Approximation Register) ADC. The ADC uses an independent 48MHz clock, and a sample takes 96 cycles of this clock to complete (2us).
Yeah, as you noted it's not fast enough for Nyquist.
Yep
I need a far higher speed ADC
Something like 20MSPS
@granite spear so the logic is that the ADC converts voltages to what exactly
And then the RP2040 has to take those and store them
It converts to numbers/data. An 8-bit ADC will give you a value between 0 and 255 for how big the voltage is versus some reference level.
Yes got it
That seems....trivial
Why can't RP2040 just grab one number and add to file
So trivial right
Because it takes a few cycles to write to the file.
Any time you use the word "just" in an engineering design, it should set off red flags in your head. 😜
It's like asking, "Why can't you just throw a 1000 mph fastball? You just pick up the ball and throw it hard, right?"
Things that are otherwise easy become tricky when you have to do them millions of times per second.
“Just”, “that’s simple”, “that’s easy” all kind of fall into the territory lol
I guess
I don't think I fully understand the coding required at the moment
i didn't realize this discussion has been going on for weeks, but given the short time frame here, I am wondering about basically building a radio and sampling platform from scratch. If I were trying to do this in a hurry, I would start with a simple SDR, like an RTL-SDR dongle, get the baseband data it outputs, and just record it. If I'm worried about how much data that will be, I would sweep a narrower band across the frequencies of interest. I would probably do this with something like a Pi Zero that could act as a USB host to the RTL-SDR dongle, and record the data on the Pi Zero SD card.
I am probably missing something like the power budget here. My understanding is that just recording is good enough, because you will be recovering the balloon with its data.
Yeah, that's a perfectly reasonable approach to consider. The project started just wanting a couple of signal-strength measurements but has grown in its requirements.
Probably naive question: why do DSPs have general-purpose processors, when DDSs don’t?
@untold needle ^ up a few posts
Classic engineering problem, scope creep 🙂
if the data can be recorded, then what to do with the data can be decided later
maybe also some filtering can be done to drop uninteresting intervals of data
I would say that a DDS chip is part of a larger system: what you want it to do is controlled by some smarter software running somewhere else. It might be easier for the control processor if a DDS could be programmed to do simple stuff like moving around in frequency autonomously, but the requirements vary widely. Also the silicon process needed for the DDS may not be such a good match for dropping in a processor core.
do you see any problems in the current plan though, I'll outline it as follow:
Antenna --> Oscillator --> Mixer --> Filters --> Log detector --> High-speed ADC --> RP2040--> Fourier analysis on ground level
Too true, this is likely to be the final project as we only have a month left essentially
the problem I see is the limited time you have to implement this, and that any changes later require knowledge of this particular design
that is why I suggested a building block approach with an existing radio and an existing compute engine
we have a tight weight limit and current draw to
too*
what is the current draw, over what period of time? Are you counting the battery in the weight limit or is that outside the 300g I saw earlier
yup, that is small, too small for something like an RPi zero
not too small for an RP2040
plus I'm not afraid of working 5-6 hour days
and we have like 6 people
is the radio already built?
only me and one other guy are particularly useful
the radio part
transmitter?
is this a class project or a research project ... no, the receiver you outlined above, before the data acquisition
Well we have build a yagi antenna and are connecting it to a function generator for the transmitter
its an international competition basically
the receiver above
we have all components but not build yet no
almost all components
log detector is yet to arrive but should in 2-4 days
ok, so long term maintainability is not a requirement 🙂
yep
long term maintainability is our last priority
I am not afraid to put in the work
its more about what work I need to d
do
there are just a lot of parts to this, so I was trying to minimize that, but i would say good luck!! the more off-the-shelf with existing designs you can make it, the more time you save
yeah no, thanks a lot for your efforts, if you have any more tips/ideas I would be grateful
Thanks!
It’s more of a joke in engineering that no matter how hard you try, the scope of a project shifts. It’s not meant to be a slight of any kind, just a reality of engineering projects. (Take it from an engineer 😛 )
Most of the questions in this discord happens because the engineering scope of the asker changed
like they bought a basic mcu but as their knowledge grow they want to do more things which involved buying other parts or another mcu
I've been musing on a somewhat related project, and it occurred to me that I could implement the digital part of DDS in an FPGA and just stream the data to an outboard DAC via SPI or parallel. And there are CPU cores for FPGAs. However, I have the distinct luxury of being free of any particular deadline.
Is a raspberry pi a good thing to use to connect to / manage things like ADCs and DSPs?
Since the Pi is running a multitasking operating system, it's generally not a good choice for when you want accurate timing (which is often the case with ADCs). However, DSPs are CPUs in their own right, so you can just send them instructions and they'll run them (I built a board a while ago that basically did that, the board plugged into a computer, the DSP ran the show, and the real work was done by specialized ARM based CPUs).
Thanks!
@primal warren @granite spear do you reackon SciPy FFTpack is fast enough to siphon through 20-30 million samples on 8 computers in a decent amount of time < 1 hour or will I have to use something faster like PyFFTW
I think ill go with pyfftw
Yeah, you shouldn't have any problem there. O(n log n) is fairly fast on a desktop computer when it's running at GHz speeds. I'd expect it to run "while u wait" on one machine, probably less than a minute.
So it doesn't matter SciPy or PyFFTW
Note that you can try this part of the project out ahead of time if you want, by creating fake data and trying to analyze it, before you even have a balloon or a radio built.
Either should be fine, yeah.
Also from what I'm reading, in SciPy and pyfftw only require like 30-40 lines of code
It requires more lines of code to get the data than to fft it
Yep, that's what I'd expect. The FFT itself will just be a function call.
Yep
Thank God there are modules for it
That's to run the FFT, I guess to plot it like 40 lines total combined
Could just use matplotlib?
Yep, that'd be a good choice. You can do the whole thing in like a Jupyter notebook environment if you're familiar with that.
I'm more familiar with pycharm plus I have pycharm Pro due to me being a student
I have github copilot too
👍
And chat gpt as backhup
The Holy trinity of programming
Chat gpt isn't that good to be fair
Heh heh, that matches well with Larry Wall's quote that the three cardinal virtues of a programmer are laziness, impatience, and hubris. 😁
Fourier analysis and FFT is probably the single greatest algorithm ever
use the api version (playground) that has a choice of models and parameters it's much better and less judgemental but still affected by the I am right right about this and will make up urls and facts to prove it syndrome
chatgpt is general purpose for entertainment. Playground has 18$ of credit costs me about 0.10$ in credits per day for all my newbie questions...
To illustrate what I say I kept looking for the made-up references it provided me and kept telling it it was wrong and making stuff up up at one point it asked me to respect its beliefs 🤦
perl ! The Camel Book was legend.
Noah would be confused because of oreilly books today
"Do I also have to save 2 books of the same type from oreilly too?"
@granite spear I've finished the fourier in python and am now basically need to just add a few noise filters and that is complete
I also found this for high-sped ADC with RP2040
also I'm concerned that micropython may not be fast enough to sample that fast, I think it can but I am unsure, just wondering, as that means I will have to learn C in that case.
@granite spear this looks so cool
created my own fake noisy signal, extracted the real one using FFT then inverse FFT, then found out frequenices of real one. Was exactly 51 lines of code.
I used pyfftw so it is fast as well
now added axis labels which I thought was a smart idea
Note that this link is discussing the larger Raspberry Pi Linux boards, not the RP2040 "Pico" chip. And yes, I expect that you'll need to use C for this to get the sampling speeds you want.
right yes, oh no, I hate C, I dont even know it for a start.
Sorry. I did warn you that this would involve some relatively advanced coding. 😅
As you can see above, the fourier was quite trivial.
are there any microcontrollers for which python would work
Not really, unless someone has specifically implemented a C driver for the ADC you're using and provided a Python library for it.
From what I'm looking at, writing to a file at above 1MHz is very hard
You don't necessarily need to write the file that fast, since you're only taking short runs of data once a minute... if it takes you 10 seconds to write all the data out before the next sampling run, no problem.
Actually there miiiiight be a way to do this in Python, as there is access to the RP2040's PIO features through it: https://learn.adafruit.com/intro-to-rp2040-pio-with-circuitpython/overview
You are the GOAT
less
we will take 5-10ms of data one every 2-3 minutes
@granite spear I've invited a few of my project team members here
such as @weak niche and @twilit drum
Yo
Hi
Hello
cool stuff here
Hello
@granite spear we are planning to get this ADC https://www.digikey.co.uk/en/products/detail/analog-devices-inc-maxim-integrated/MAX1426EAI/2137405. Its 10MSPS and 10 bit but I'm not sure how we could connect this to one of the pico pins. Thanks a lot.
That particular chip is a parallel output chip, so it supplies its results on a pin per bit: if you want to use all 10 bits, you'll have to connect (at least) 10 pins.
Oh no, that doesn't work, what type of chip are we looking for?
The RPI pico has 26 GPIO pins, does this also mean that if we only want to use 8 bits, we only have to connect 8 pins? So maybe it does work
Yes, this was the approach skerr was suggesting. The RP2040 has a nice "PIO" feature where it can read multiple pins at high speed, so it can deal with parallel-output ADCs like that. This is why it's in "possible, but a little tricky" territory. You'll probably need a few extra pins beyond that to control the ADC too, but you should have enough pins for that plus the SD Card, etc.
The disadvantage of a parallel interface is it uses a lot of pins, the advantage is it's fast. And I was thinking you might not need all 8 bit, which is why I added that qualifier. Then again, if you're buying chips for a project, and you only plan to use 8 bits, you can often save money (and other resources) by using an 8-bit converter.
does this mean it draws a lot of current thoguh
though
I'm not sure what you're getting at. While having a lot of pins does account for a little bit of current draw (to power the pin drivers), in general fast ADCs are going to be power hungry.
The number of pins doesn't really affect the power draw one way or another in most cases. With fewer pins, they'd have to go faster, which also costs energy, so it evens out, but generally the I/O isn't where the power goes anyway.
well the one above that is 10MSPS is only 0.3mA current draw
thats fine though, thanks.
Need to research RPI pico PIO pins
since thats what we have
so do I have to connect 8 pins of the ADC to 8 GPIO pins
That's what I was thinking
Yes, and probably a couple more too, depending on the ADC. For example, the MAX chip above needs a clock signal to tell it when to take a sample.
I realised this now, I was a bit slow
but then how do I tell the ADC through the pins to give its data to my pico
I'd have to read the datasheet to be sure, but I'd expect that after each clock, the ADC would present the value on the data pins for the Pico to read. So the clock signal says "give me a sample", and then you read the sample a short time later (on the next clock, probably).
I think it takes several clocks to do a conversion, but it looks like you don't have to do anything to start/request a conversion, just read data from the pins
Yeah, it looks like it pipelines 5 or 6 samples, so you're reading a little bit back in time, but it's still "one clock = one sample" overall.
Different ADCs will behave slightly differently, if you end up choosing another chip.
pipelines? Well this doesn't seem too terrible, does this mean I'm taking 1s and 0s from 8 different pins and then basically storing that in RAM then saving it to some sort of file on the pico?
right
Yep, that's the basic picture.
is it in any particular order, I know thats probably hard to say without looking at the datasheet
mmm, somehow this doesn't seem ridiculously difficult but still lots of scope for error
Yes, it's a binary number. So if it wants to send you the number 5 for the voltage it samples, it would be 00000101.
surely there is some sort of reference voltage or something
I mean I guess the pico can calculate that
yes but how do I know which order its in
like it could return me two 1s and 6 0s in any order
and I wouldnt know what it is
it could be 10100000 or 01010000
Yes, that's something you will often need to provide to the chip, to tell it how to measure. "I want to measure voltages between 0.0 and 2.0V, so here's a 0.0V and a 2.0V signal for you. Now give me a number 0-255 for the voltage you see between those limits."
ah, so a bit trickier
The order comes from the pin labels. The bits would go in order like D0, D1, D2, etc.
oh silly me
thanks
so this software shouldn't be an ungodly level of difficulty
It has to take a 0 or 1 from 8 different GPIO pins in a certain order and save them to some file
I mean, I do have to warn you that if you're asking questions about how binary numbers work, writing the code for this is not going to be easy.
This is highly subjective and I don’t think I should give this a response. If you’re comfortable with assembly, this is certainly manageable.
Oh I know how binary works
we did that in computing class ages ago
I know how binary works well
unsigned and signed integers
8-bit, 10-bit
assembly, can't I use micropython or circuitpython?
The outer shell is certainly python-able, but the PIO state machines are built in assembly-esque syntax.
Now I'm confused, aren't I just taking the data from the GPIO pins
oh I see
You are, but python gpio reads may limit your rate of sample-recording. I don’t know what speeds you need or how many samples the adc can save, but you mentioned PIO so I assumed that you need it to be faster than the rate Python would spit them out.
approx 10MHz
not even approx
it will be 10MHz
yeah you are right, it will required PIO I think
10MHz is quite fast
Yeah, sounds like a job for PIO or C.
I'm not even sure C is fast enough, though potentially
It’s pretty borderline. I would assume PIO would be the more reliable method here.
yes I think so, I will try both though.
Ah I found an issue, how do I test that the ADC is talking to the RPI pico without using a PCB, do I just have to breadboard it or something
Breadboard is usually the way to go, if you’re not ready to solder wires yet.
Yep. Your ADC might not be available in a breadboard-friendly package, though. The one you linked to above is surface-mount.
mm thats a problem
not sure how to go about that
what if its surface mount though
there are quite a few adapters aren't there?
for some SMD packages, you can buy breakout boards that you can plug into a breadboard, if you're up to the soldering
soldering isn't a problem really
plus the pico we have is with headers already
well, fine-pitch soldering if you're using a generic breadboard adapter to solder the SMD package to
28 pin breakout board ouch
at least it's not QFN or BGA
High-Speed ADCs are pretty complicated components
compared to mixers and oscillators at least
Thankfully a lot of high speed ADCs are in TSSOP or similar packages
https://uk.farnell.com/texas-instruments/tlc7528cn/ic-8bit-dac-multiplying-dual-7528/dp/3005721 this looks quite nice too
Note that this is a DAC rather than an ADC... it outputs an analog signal you write to it instead of sampling something you want to read.
yes, the one we are getting is in TSSOP, though I'm not sure how that helps
I guess TSSOP breakout boards are more universal
@granite spear can you check this part of the circuit
This is Antenna --> LO --> Mixer --> 2 Filters --> Log Detector
now that I come to think of it, do I even need a log detector with Fourier, the pico and the ADC???
And then how do I tell which band pass filter it has passed through, because if I can't do that, it might as well just go straight to the ADC which does simplify the circuit to be fair
oh, I have another question, what comes to the raspberry pi GPIO pin, is it a high or low, or an integer like a 0 or 1 for part of the binary
is it just 8 separate 0s or 1s, or is it 8 highs and lows
Yes, its a high or low for each pin I believe
Each pin will send either, that’s correct
so I use PIO to check if each of the 8 pins is high or low
The corresponding value together makes up an 8 bit value that you then can easy convert into an integer.
yes I know this
I need to figure out how to check if a pin is high or low using PIO
Yup, you use PIO to capture the state of each pin simultaneously
no clue how to do that
😂
though it seems like something that I can google
https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__gpio.html is this the same as PIO?
Yup
wait, so I can use this then?
ah, but is C fast enough
it will be going at something like 10-15MHz sampling
C is the fastest in the hardware world
isnt C++ faster
C++ is a higher abstraction of C, so no
o
right
But those conveniences come at a cost
wait doesn't this just work then?
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#define PIN 2
int main() {
// Initialize the Pico's standard library
stdio_init_all();
// Set up the GPIO pin as an input
gpio_init(PIN);
gpio_set_dir(PIN, GPIO_IN);
// Loop forever
while (1) {
// Check the state of the GPIO pin
if (gpio_get(PIN)) {
printf("Pin is high\n");
} else {
printf("Pin is low\n");
}
}
}
What do you mean?
this checks if a pin is high or low
and prints it to the console
this cod
code
or at least I think it does
It probably would, I’m not near my computer or a Pico to try at the moment
I thought this was going to be more difficult
I will note that it’s generally a better practice to store the pin value in a local variable.
ah yes
To be fair, I am quite bad at C
Thanks for your help, you've helped a lot so far.
C/C++ is my day job and I’m not great at is
compared to me, you are a wizard
I am terrible
chat gpt is probably better than me
I’m proof that you can be not great at something and still make the big bucks because the world needs software engineers
Or engineers in general really
how big are we talking........I'm joking, although you are being far too modest
I'm talking to chat gpt and its adjusting the code
to check 8 pins at the same time
I’d work off something like this example
right
Raspberry Pi invests a lot of money in making the SDK good by including examples so they’re great jumping off points.
this looks very complex and long.
What does it do that my/chat gpt's code doesn't
Yeah, it probably will be.
ouch
Sets up a PIO program, configures all pin states, adds the PIO program to the pio peripheral, manages the state machine.
isn't that the same as the program I sent
this one looks so hard
PIO takes a lot to get going properly
this looks crazy
That’s what makes it fast 😉
so I need to adjust this to save it to a file
oh no
I don't even understand it
gulp
Anywho, need to finish my coffee and get logged in to work. Remember that we only grow by doing things wrong a few times. And yes, this will be hard but there are people here willing to help.
As long as you put in the effort and also ask the questions, you’re going to do great
I've been asking too many questions almost
Nah
571 questions
The only thing I managed to do fully by myself(pretty much) was the fourier analysis in a language I knew(python)
this PIO state machine stuff is hard
There’s not really a question limit
Doing new things can be hard, but that’s what makes them worth doing.
true
I need to understand this PIO code
Anyway, build that example and then slowly remove lines from it and see how it works/doesn’t work. Deconstructive analysis is a great way to learn
It’s heavily commented too, so lean into those to derive understanding
I guess so
yes, that is what I am looking at
hopefully EdKeyes pops along
And reference that read the docs page too
yes
You might get some practice writing PIO programs using circuitpython as well
python yes
I love python
I wish it was faster
I understand some of it thanks to the commenting
@half plover Chat GPT is giving me suggestions on how to modify the code to do only 8 pins and write a decimal value to a file. It seems quite reliable so far
Id take charGPT with a grain of salt
Better to follow the docs
Or known good examples. ChatGPT is only a tool for aggregating what it thinks is relevant.
To modify the code to record the states of 8 pins and save it to a file called binary.txt in decimal form, converting them from binary to decimal, you will need to make a few modifications to the code. Here are the steps you can follow:
Modify the constants CAPTURE_PIN_BASE and CAPTURE_PIN_COUNT to reflect the base pin number and number of pins you want to capture. For example, if you want to capture pins 0-7, set CAPTURE_PIN_BASE to 0 and CAPTURE_PIN_COUNT to 8.
Modify the function print_capture_buf to convert each set of captured pins to a decimal value, and write that value to a file. You can use the following code as a starting point:
scss
Copy code
void write_capture_buf(const uint32_t *buf, uint pin_base, uint pin_count, uint32_t n_samples) {
FILE *fp = fopen("binary.txt", "w");
if (fp == NULL) {
printf("Failed to open file\n");
return;
}
for (int sample = 0; sample < n_samples; ++sample) {
uint32_t value = 0;
for (int pin = 0; pin < pin_count; ++pin) {
uint bit_index = pin + sample * pin_count;
uint word_index = bit_index / bits_packed_per_word(pin_count);
uint word_mask = 1u << (bit_index % bits_packed_per_word(pin_count) + 32 - bits_packed_per_word(pin_count));
if (buf[word_index] & word_mask) {
value |= (1 << pin);
}
}
fprintf(fp, "%d\n", value);
}
fclose(fp);
}
This function creates a file called binary.txt and writes the decimal value of each captured pin set to the file, one value per line.
Modify the main function to call write_capture_buf after the capture is complete.
It’s fun, but I wouldn’t rely on it to be your source of truth when writing this.
Or THINKS it gives good suggestions
while its code might be wrong
Eh, I would still lean far more heavily on resources like stack exchange or documentation for your code.
the suggestions seem decent-ish
I guess yes
It doesn’t actually know anything — just a lot of clever guessing
yes, it is a predictive algorithm isn't it?
In my experience, ChatGPT is not a tool a programmer should use for their work.
You are likely correct
Yeah — it tries to predict what’s right, but it has no idea if it’s right
I guess I can just change the code based on what the comments say
like it prints all the binary values
I need to save them to a list
based on the original github coder
I agree with skerr, better to check previous human work
yes
this is the original
I need to change certain functions
like instead of printing, I need to save it as decimal form to a file
I need @granite spear, the man himself
Does it need to be saved as decimal? I imagine you could save a lot of cpu cycles and power if you converted it in post processing.
Storage, too.
doesn't need to save as decimal necessarily no
so I guess let me change my statement
I need to save it as an 8-bit binary integer in a file rather than printing it and I need to do it for 8 pins rather than however many they have done it for @worn bridge
I know which function I need to change
to make it save as a file
Looks like CAPTURE_PIN_COUNT will adjust the number of pins to sample
thats what ChatGPT said as well, change that to 8 and capture_pin
capture_pin_base to 0
The rest is just modifying/replacing the print_capture_buf() function to whatever format you want and have the pico write whatever that output is to a file
yes that is what I thought as well, I just needed human confirmation as opposed to ChatGPT
Thanks a lot!
I greatly appreciate your help, I mean that with no sarcasm at all, this server has been the backbone of this project
what I wrote in #welcome re ChatGPT:
ChatGPT can give plausible-looking answers to questions. But you can't trust ChatGPT as a source of knowledge. It doesn't "know" anything. It could be right, or it could be completely wrong (and appear confident), and you can't tell. It's just cobbling together phrases from a large language model, and it doesn't do attribution. It's like asking a parrot with a very large memory a question. We recommend you use a search engine instead.
Yes, I agree with this, it is a helpful tool but only for direction as opposed to actual substance like code itself.
if it would at least do attribution, you could go to the original sources. The Bing Chat thing recently demonstrated does do attribution.
mm right. I mean ChatGPT has its uses but its still quite far off being a reliable source of information.
It’s more a toy right now
I got bored with it pretty quickly
I poke it now and then
same
Its funny to play chess against it, it plays many illegal moves.
Probably more fun to play against a monkey…
this is true, I only play chess for fun though, I used to play competitively, but that was many years ago
mmm, I found another problem
@half plover the ADC can't handle negative voltages(<0.3V) so how do I offset that issue
because since the frequency is a sine wave
some points will be below the X axis
Raise your reference voltage
what do you mean by this?
TSSOP
Okay
I am connecting that to the RP2040 through PIO
but I need to avoid negative voltages below -0.3V or preferably anything below 0V
yes, and I'm not sure how to stop the negative voltages...maybe an Op Amp but I'm not certain
You can pass your ADC input through a voltage divider
but its negative
Okay, let me explain through an image
ok
this just splits VCC in half yes
I know how voltage dividers work from my electronics classes
👍🏻
ok but what happens to the signal
so VCC is 5 volts in this case
so it splits it to 2.5V
wait so 2.5V just gets added to every voltage?
In a way yes
so -2 would become 0.5
this basically just shifts the graph upwards, which is perfect
Yup
If you’re power conscious, consider larger resistors
we might apply for a current draw waiver
at the moment, current draw limit is 200 or 250mA
i cant remember
we are accounting for the pico taking up 100mA, the ADC taking 50mA and the rest is 50mA
this is off a 5V DC supply
Yeah, makes sense
slightly confused how that works
V = IR
voltage is constant
Oh
increasing resistance decreases current
I see.
Right
I = V/R
You could probably use 2x 1k resistors for a nice small milliamp power draw
2.5mA
12.5mW
mhmm, that idea of yours was quite genius
are you sure this works @half plover since I've never seen this idea before, most people opt for an op amp, I wonder why when your solution is so much more elegant and efficient.
I tried this with some sample voltages and it works perfectly after adding 2.5 to every voltage
it gives me back the same frequencies as expected
highest = 4.449083245V
lowest = 0.550916755V
I’ve used it on some optical ADC projects that saw voltage swing wildly
That solution is so elegant electronically
wow
its actually beautiful
just put it through a voltage divider and move the sine wave upwards on a graph
Yup lol.
In your final design, make sure to use as good of resistors as possible
Like 0.5% or 0.1% tolerance
It’ll make sure your readings are more accurate, less variance in resistance and whatnot
ouch, my electronics professor has access to mainly E24 and E12
though I'm sure he has some 1% ones too
idk if he has 0.5 and 0.1%, he probably does but idk
Use the best you can get, just make sure they’re identical in value and tolerance
Yes, so that it goes to as close as 2.5 as possible
wait can't I just use
Vout = Vin*R2/R1+R2
product over sum
If they’re symmetrical you know center is 1/2 VCC
yes but with 1% tolerance, there is a range of possible centre values
its still minute though
so it shouldn't make the biggest different
difference
Right
Also, I've been wondering, how are you so knowledgeable in the field of radio
Like, without your help and several others, this project would be nowhere
some of this stuff is like post-uni
you only start fourier analysis in uni
and nyquist limit is only talked about pretty late
Lots of projects, experimentation, working for a Visible Light Communications startup
this project is probably my biggest yet
Also I have an undergrad degree in computer engineering
also why is the word 'd a m n' censored
It’s generally not consider child friendly as we have younger makers on this discord
That's pretty cool, and I take it your favourite language is C/C++
I'm probably towards the younger/median age without getting into specifics
Hardly lol, I use python as often as I can
really?
I mean C is pretty useful
its fast
thats basically its main positive
I only know python
It is, but I usually don’t need it for my projects. I use it at work mostly (C/C++)
i guess some HTML
I did a C course once but I've forgotten most of it
apart from clang
and compiling code
I hate that you have to do that
It’s all useful, love it or hate it, it’s good to know.
finding out how to add stuff to a file in C is going to be painful
void print_capture_buf(const uint32_t *buf, uint pin_base, uint pin_count, uint32_t n_samples) {
// Display the capture buffer in text form, like this:
// 00: ------------
// 01: --------___----
printf("Capture:\n");
// Each FIFO record may be only partially filled with bits, depending on
// whether pin_count is a factor of 32.
uint record_size_bits = bits_packed_per_word(pin_count);
for (int pin = 0; pin < pin_count; ++pin) {
printf("%02d: ", pin + pin_base);
for (int sample = 0; sample < n_samples; ++sample) {
uint bit_index = pin + sample * pin_count;
uint word_index = bit_index / record_size_bits;
// Data is left-justified in each FIFO entry, hence the (32 - record_size_bits) offset
uint word_mask = 1u << (bit_index % record_size_bits + 32 - record_size_bits);
printf(buf[word_index] & word_mask ? "-" : "");
}
printf("\n");
}
}
I mean this is what I have to change
I don't know why they are saving it as text to be honest
@half plover ok, I tried modifying it
Does this work?
oh wiat
wait
This
Best way to know is to build it and try 🙂
right
what is your feeling though?
Hard to say at this moment, I don’t see anything glaringly obvious.
what do you think of my new code
this one
I tried if an insufficient amount of bits are provided, just fill in the rest with 0 spam
well it isn't my code
I got a guy in my project team who knows a bit of C to rewrite it
I changed it
@granite spear I'm not sure if you know C though I wouldn't doubt it, do you think this code works to save an 8-bit integer to a file called binary.txt based on 8 pins being high or low.
This is the base code which I have modified
I think it's okay, yeah, though pin_base isn't used anywhere that I can see. The bit packing is a little unusual, but it seems to match what the logic analyzer is doing. pin_count would need to be 8 or less to fit the output into the byte-sized output.
let me chec
you are right, I don't actually see pin_base anywhere, I don't know why it is there
@granite spear i feel like coding this on the pico would be hard
this is the clock pin of the ADC
also falling edge implies I have to create some sort of astable circuit
It'll require a modification to the PIO code, since you'll want to output the clock signal in sync with sampling the input pins.
oh lord
ouch
wait so what would that entail, is there any sort of example or anything as well as other options for it. Also surely I can use micropython for this, as I only have to have the ADC turn on for 5ms every 5 minutes
I thought you were using C above?
yes
because speed is required
Oh right, is there no way to do both?
Not easily, yeah. Your application would typically either be all Micropython or all C.
Ah right, ok then, so I will have to use C
that's going to be hard
what do I have to adjust in that PIO code
I don't know the details, but the general idea would be to have the PIO execute a loop like:1. Set clock pin high 2. Capture the 8 input pins 3. Set clock pin low 4. RepeatSo you get one capture per clock cycle.
Precisely how to do that with the PIO is something I haven't played with before, but it should be within its capabilities.
but I want it it to be on for 5ms capturing samples at 15MHz(max ADC speed) then off for 5 minutes
also, what is this business of the 'falling edge' of the clock input
That would be controlled at a higher level, where you tell it how many samples to capture. The loop above is just to get one 15MHz sample.
oh ok
but how does it know to capture only for 5ms
The clock pin has to flip on and off at 15MHz to tell the ADC to take samples that fast.
To capture for 5ms, you'd tell it "please record 75,000 samples then stop".
ok
I assume the logic analyzer code has a way to specify that.
yes it does
mhmm yes
it does
at the beginning
but then how to make it turn of for 5ms
as it doesnt know that
either
That would be part of your higher level application loop... record for 5 ms, save all the data, sleep for 5 minutes, repeat.
oh i see
just shove it in a while True loop
or a for i in range loop
and add a time.sleep(300)
well that would be in python
but do that in C
Yep, the same sort of loop structures and delay calls are available in C too.
could I use asynchrous routines
like this
You could, but I suspect that would just needlessly complicate your code.
well it still needs to continue saving the data to a file, or does the code i created earlier do that as soon as the sample is collected
and how else would I do it
I'm not sure how your overall code is structured, but you would typically have a main loop that would call functions to perform those actions, likec while (1) { take_adc_samples(data, 75000); // 5 msec at 15MHz save_to_file(data, 75000); delay_ms(5 * 60 * 1000); // 5 minutes }
But there are all sorts of details, like how to name the files you're saving and stuff like that.
how do I make it go at 15MHz though @granite spear , apart from that I get it
in fact, what even dictates how fast it is
I'm not sure how the logic-analyzer code selects the sampling frequency. I presume it has some sort of loop structure which determines how fast the PIO code is executed.
I dont see that
This might be the part that does it:sm_config_set_clkdiv(&c, div);It's setting some sort of a divider factor versus the Pico's system clock.
hmm
how do you do that code formatting
Single backticks give you inline code like this while triple backticks give you a code blocklike this
printf("Starting PWM example\n");
// PWM example: -----------------------------------------------------------
gpio_set_function(CAPTURE_PIN_BASE, GPIO_FUNC_PWM);
gpio_set_function(CAPTURE_PIN_BASE + 1, GPIO_FUNC_PWM);
// Topmost value of 3: count from 0 to 3 and then wrap, so period is 4 cycles
pwm_hw->slice[0].top = 3;
// Divide frequency by two to slow things down a little
pwm_hw->slice[0].div = 4 << PWM_CH0_DIV_INT_LSB;
// Set channel A to be high for 1 cycle each period (duty cycle 1/4) and
// channel B for 3 cycles (duty cycle 3/4)
@granite spear this looks like something to do with it
I dont know why the logic analyzer has PWN
PW
PWM
It might be doing that as test output to have a signal to capture?
right
so should I include that
// Grant high bus priority to the DMA, so it can shove the processors out
// of the way. This should only be needed if you are pushing things up to
// >16bits/clk here, i.e. if you need to saturate the bus completely.
16 bits per clock
thats fast
You could maybe use it to test your code in the same way, saving samples from that signal instead of from the ADC, before you hook up the real chip.
mmm, but how does that make the pins high or lwo
low
I'm not sure of the details, but basically you write a 0 to make the pin go low, or a 1 to make it go high.
mmm thats weird
this is pretty complex code
idk what the PWM does
I sort of understand the rest
Pulse width modulation just means you’re changing the duty cycle on a digital pin’s output
Usually variably to do a variety of things like move servos, play tones on buzzers, etc.
what is it used here for and do I need it
In this context? It’s likely just telling the peripheral that the signal will be either PWM or PWM like.
oh ok
I’m not sure why the logic analyzer would have this, it’s possible they are generating a PWM signal as an example to be processed by the logic pins you setup for reading
I think so
Do I need the example
this code is so complex
I’d venture to say you don’t need it
hmmm alrighty
My teammate wants to write his own logic analyzer as he thinks this is far too complex and unnecessary, although it is likely his wont work so I am working on my own(this one) in the meantime.
He knows more C than me though
I dont really know what else I need to do to this logic analyzer
I modified it
it seems fine
@half plover if you dont mind having a look, I would be greatful
and @granite spear too if you dont mind. Thanks a lot.
The point isn’t to make a logic analyzer though so making their own isn’t going to solve the issue. What he’s going to find is that regardless of what he thinks, it’s the same process to read 8 inputs of a signal bus for logic analyzing as it is reading 8 inputs from a parallel bus for loading into a file for signal processing.
The key here is simultaneous acquisition
Does the code above do that?
You only get that with PIO and FPGA in terms of signal processing
I don’t know, I am working my day job (still 3 in the afternoon for me)
Not an issue, I can respond in between compiling code
When replicating Ben Eater's Arduino-based sort-of "bus analyzer" for breadboarding a CPU, I took the simple approach of using an 8-bit-wide port for basically simultaneous acquisition.
At slow enough speeds many microcontroller can do it. For instance you can do logic analyzers for I2C on a simple microcontroller
But 15MHz for 8 data lines simultaneously is going to be very hairy
That’s why PIO is great because it’s independent from the cpu and has instant access to pin states.
we will probably run it at 10MHz
mm yeah
Try and have a look at my code when you have time, I understand if its tough though. Can't believe you are working while helping me. Thanks a lot
👍🏻
A lot of us are multitasking
yeah, I struggle with that myself
Btw madbodger there is very knowledgeable as well, very creative solutions
Yh I've seen
A lot of corner case things you wouldn’t think of.
Well then, would you mind having a look at my code and suggesting anything
Alas, I'm not up to it at the moment, I'm brain fried
oop
that is unfortunate
I'll repost it if you change your mind.
so one be able to build a duga style radar in their backyard with electronic scale power ? Or is it completely outside the realm of electronics ?
I always though that radio was a sensitivity thing not necessarily limited by power
It's also limited by the FCC/other government agency. Since a radar would be constantly transmitting (I think so), it might anger them. But it would be epic if you could pull it off.
yeah but I was thinking like with the evolution of technology you'd need much less power to detect a 1950 fighter aircraft with electronics ?
So you'd actually need less power and with more sensitivity for the same size due to the technology you'd still detect your own radar pings ?
I don't know RF. I'm trying to design a thing that harvests RF energy from FM radio broadcast signals and I have no clue how to design a matching network for the rectenna.
Can anyone help with the above question about designing an impedance matching network for a rectenna and energy harvester?
So it’s best to start with a 50ohm antenna. But there are calculators if you want to use smaller traces
You probably want a pi network
Pick a band like.. 88.3MHz
(8.83x10^7)Hz, a 16 mil micro strip trace on 1oz copper will have a source impedance of like 124ohm, plug into a network calculator like this from UC San Diego and pick probably a high pass low pass or pi network? https://home.sandiego.edu/~ekim/e194rfs01/jwmatcher/matcher2.html
University of Alberta has a nice paper too http://www.ece.ualberta.ca/~kambiz/papers/J22.pdf
Uhhhhh, what is source impedance?
I just now understand impedance
Sorry I meant load impedance since the matching network will be on the load side of the circuit
Source impedance is the impedance of the antenna
How do I integrate an antenna for FM broadcast bands onto a PCB? A dipole would need a lot of space. I'm not sure how to calculate the source impedance of that either
Usually a BNC or SMA connector
Or coax is common
That could work, but putting the antenna on the PCB would be even cooler
Yeah, I’m not confident they make chip FM antenna
lol
I didn't think so either
But there must be some way it is done. Old phones would use the headphone lines as FM antennas
Although a rubber duck isn't that bulky
Yeah, FM quarter wave is too long
There’s some portable radio antenna with SMA connectors so you can have an SMA board connector
I'm doing this for the Hackaday low power competition (goal is maybe an FM-powered clock) and just to see how low power I can get something.
I'm probably using this IC
I'm guessing that if the antenna source impedance is 50 ohms, the matching network converts that to a source impedance of something else, which should be the same as the rectifier impedance + the harvester IC impedance
Shame that you have a total power limit
because in the 1940s they used a passive FM radio to listen in on US ambassadors
The harvester IC has "ZMPPT". I guess that means it can adjust its own impedance so the power delivered is at a maximum
with a theramin-like device and it sent out AM signals when it was iluminated by FM signals
it was called "the thing" in a wood seal of the soviet union
Or should the matching network source impedance + the rectifier impedance equal the IC impedance?
the article says being illuminated by radio waves in the FM range powered it
might be worth looking into but I suspect it's the advanced engineering of the cavity/membrane in it that made it possible not the quality of the radio components in it...
That's cool that it was a completely passive modulator using no components like individual inductors or capacitors. Instead the components were the device.
@primal warren @granite spear does the ADE-1 RF Mixer that we are using need a power supply, as it doesn't have a VCC or Vin pin
is it a pssive component
passive*
also i built the circuit
Yes, it's a passive component. It doesn't need a power supply.
oh alright
What are R3 and R4 for? It looks like they would just waste power.
add 2.5V to every voltage
so I don't get negative voltages
That won't work.
it was suggested by @half plover
You'd need a coupling capacitor to block the mixer from grounding out the signal.
he suggested this
picture
That will only work with a floating signal in. That mixer does not provide a floating signal.
mm I see, how do I fix that
Insert a capacitor between the mixer and the resistors.
between the mixer and the voltage divider?
Right
The capacitance, along with the load impedance, determines the cutoff frequency
right, so depending on the output frequency of the RF mixer, that determines the capacitance
is there any way to calculate the capacitance required then?
High pass filter calculator
no, but for the capacitor in between
im not adding a band pas filter
Generally, a higher capacitance will mean more ac at lower frequencies gets through
Yes, for the dc blocking cap
What is this for anyways?
But why are you trying to read RF directly? I think it would be too fast, but maybe you could catch some of the signal. That is a parallel ADC, so maybe it's fast enough.
it is 15MSPS
its fast enough i think
1/2πRC
That gives you at most 7.5 MHz maximum
yes due to nyquist
But a good rule of thumb is to divide by 5
it is reading 0-3MHz
So 3MHz
oh right yes
Nope, it's 1k, since they're effectively in parallel
but its 3 separate 2k resistors isnt it?
2 separate 2k resistors
Hmm, nominal values of Vrb and Vrt are 0.36V and 1.56V, so 2.5V isn't the right center value anyway.
Also you'll need an RF amplifier.
yes they are
oh thats a very god point
I will recalculate
so I need to hit in between 0.36 and 1.56
so all voltages need to be between 0.36 and 1.56 I guess
You left F out of your equation. The cutoff frequency (F) is 1/2πRC
No, you left F out of the equation again
F = 2 mega
That's way too low, maybe use 6 megahertz
but out of the mixer it will be coming from 0-2MHz
LO is 27MHz
we are broadcasting 25.2 --> 28.8MHz
so the IF will maximum be 1.8MHz
2MHz to be safe
And the cutoff frequency is the point where the response is 3dB down. You don't want to throw away that 3dB, so use a cutoff frequency comfortably higher than the signal you want.
ok so 5MHz
OK
Definitely
yes massively
LC filter is basically a voltage divider, but with a cap instead of a resistor. Since the capacitor's impedance decreases as frequency rises...
What is your cutoff? And high pass or low pass filter?
well 5MHz cutoff I guess
I just did the calculations @primal warren
I need a resistor of 3M3 and a capacitor of 1F to give me a cutoff of 5.2MHz
so what do I change in the circuit
Do I put in a 1F capacitor and what values do I change R3 and R4 to
You can't easily get 1F cap
We have 1 Farad capacitors
Maybe LC filter
wait does it have to be electrolytic?
1F is a supercapacitor, and those usually have high esr. Might also have high parasitic inductance
Meaning not good for high frequency
Maybe LC filter would work
Too much resistor means that you might get a lot of noise I think
Lc filter
It is
But it doesn't really provide the voltage bias
You could maybe add an op amp
That's probably a good idea since RF is very low level
@grizzled vapor the aim is just to add 2.5V to every voltage coming out of the mixer
IF amp ICs exist
I dont understand why we have to filter things
It's because you inadvertently add a filter when doing the voltage bias
You could reference mixer/RF ground to a virtual ground at 2.5v?
Just a resistor divider
Or use lmc7660 negative voltage supply
hmm that seems interesting
this
Another option is to use a transformer
not an option for us
One that's good for HF
I like this idea of grounding the mixer at 2.5
does that just automatically add 2.5 to every voltage @grizzled vapor
Also make sure your LO shares the 2.5v virtual ground
Maybe? Probably?
brilliant
I need 5MHz not 1 hertz
But yes virtual ground seems like a good idea
@primal warren will this work, save me
But since it is a high pass filter that passes all freqs higher than x hertz
In this case 1Hz
you mean low pass?
Use two resistor divider
ok
And since they are effectively in parallel
so capacitor --> 2 resistor divider
You just use R value of half of single resistance
can you draw me a diagram please, I'm not fully understanding
Use Google
I created virtual ground for mixer and oscillator
@grizzled vapor so what do I need to connect the IF pin to?
for the mixer?
yes but I need to add 2.5V to all of the voltages outputting from it, or does the virtual ground already do that
I adjusted the circuit to meet the requirements that you suggested @primal warren @grizzled vapor
You did your math wrong, that's not even close
The capacitor goes to the junction of the two resistors (that's your signal input)
The power-supply portion of the circuit looks weird too. You don't want to use a voltage divider to create 3.3V like that, since the voltage will sag as the chip draws any significant power. You need a voltage regulator for that, or possibly you can tap off the 3.3V from the Pico. Also the capacitors are hooked up wrong, I think since, you've got both power and ground shorted together on one side of them, and the VDD connection to the chip isolated on the other side.
You need to correct some of the capacitors and power supply thins as edkeyes said. There are some shorts and reversed capacitors
you mean in the middle of the potential divider
mm ok, well the ADC requires a 'clean, quiet' source of +3V
Usually a LDO
this circuit seems like whenever I want to add one component, I end up having to add another 10
but ADC needs 3, unless 3.3 is fine
3.3V is pretty standard
What you're trying to build is a fairly advanced project, and I'm guessing you're going to need several more components at a minimum
what other components will be required?
You'll need an RF amplifier, and probably some impedance matching networks
That diagram looks good, but it doesn't match the way you have the capacitors arranged in your circuit, in terms of power and ground connections on each side of them.
we have an RF amplifier(MAV11)
I didn't see that on your board, just an "antenna in", so I didn't know if that went straight to an antenna.
oh right
yes
I've done that separately
doesn't it, the pins go to the bottom capacitor with a ground in the middle and the power supply connection to the positive side of the electrolytic capacitor?
oh right
mmm so to the middle then?
so this then
ok
It looks like you're trying to power the ADC with a voltage divider instead of a regulator: that isn't likely to work
yes that was the plan
ok so should I get the pico to power the ADC?
Double-check which side of the capacitors the VDD to the chip should be connected to. In your circuit, it's all by itself, whereas in the other diagram, it's also connected to the power input, with ground only on the opposite side.
Welcome to hardware design for dummies.
(And no I’m not calling you a dummy)
oh but I am a dummy
Possibly, depending on the voltage/current it needs. And the way it's drawn, your power supply is short-circuited anyway
how so?
You have the + (left) side of the left hand capacitor group connected to both power and ground.
that is a brilliant point
@granite spear @primal warren RF circuit version 165
I unshorted it
and I added the capacitor to the middle
and the voltage divider adds the middle of the nominal values, it adds 0.96V now which is in the middle of 1.56 and 0.36V
@half plover please have a look at it as well.
Maybe consider something like this for the digital and analog power supplies for your ADC
I haven't connected it to ground on my circuit diagram
The voltage divider should ideally also have resistors of equal values
No, the voltage divider is designed to center the input in the range the ADC accepts
yes, Vout in it is 0.96 which is the sensor
sensor's center
If the range of the ADC is 0-VCC, center would be half VCC
but the nominal values of the ADC are 0.36V and 1.56V
I don’t think that’s right.
Plus the divider should be pulled up to VCC of the ADC, not 5V
why is that?
then it would 'add' 1.5V to every voltage
Because you’re changing the reference
The divider being between VCC and gnd ensures there will be no negative values
Didn't madbodger say to use it to centre the voltage
yes exactly
They are. Capacitors are connected correctly, but AVDD and DVDD are connected to the other side of the caps.
are they?
yep
they are
thanks
Let me provide a reference to what I’m saying
The hardest to diagnose errors are always stupid mistakes
yep
Yes
ok but what is the VCC of the ADC
is it the pico?
Circuit diagram V1800 after fixing all short circuits, main thing now is what do I change those voltage divider resistors to.
The 3.3V pin on the Pico should be able to power the ADC, using its onboard regulator.
Yeah, there’s no need to tap the 5V rail either
yep ok
well the raspberry pi needs power
what about the circuit
I’m talking about the voltage divider
oh right
so I tap that to the Pi pico power supply to
Yeah
okie
is everything else alright?
Your voltage divider will change
yes
but what voltage needs to come out of the divider
so I just need 2 equal resistors
Right
Version 2500 with no errors I believe
@half plover @granite spear @primal warren give it the godly signal of approval
🥲
Heh heh. "Approval" is a strong word, but I don't see anything obviously wrong, at least. 👍
So now I 'just'(I hate this word now, I use it sarcastically) need to add impedance matching networks and add the antenna circuit with RF amplifiers
any suggestions of where to add these things
I'll have to defer to other folks about that, as I'm more of a digital guy rather than RF.
oh alright
Same, my knowledge stops there as well
But you’ll want to use something with a wide GPBW
GPBW?
I have 19 days left on the project now
Gain Product Bandwidth
testing, building PCB(yes we switched again), building transmitter(other teammates doing that, its going well) and then programming the pico and getting that to work
19 days for all of that ^
Definitely doable
Interesting
Rf is hard. It's described as black magic for a reason. A good place to find radio stuff might be some ham radio schematics. Like QRP labs' QDX
But what is the project?
You might want to use a pre-built IC or module that handles all the RF magic for you.
such as?
Create transmitter, bounce radio waves off the ionosphere to receive them on a gondola/balloon in the air. Collate/collect the data and save it to a file to be read at ground level. Then run fourier analysis on it using a program and find out the effect of the ionosphere on radio waves and see the received frequency.
idk if that exists
plus we're into it
Make sure it's all good with the fcc. If you have a ham license and you transmit your call sign (like as Morse code or data by turning the transmitter on and off), it should be good. But I can't be sure.
Yep, we have the go ahead
I'm in the uk
but its an international competition
it takes place in belgium @grizzled vapor so we have permission from them
Also, that's really complicated for a 19 day project. Really cool though. Hopefully, the transmitter can pump enough power into a directional antenna. Idk how to design an rf power amp. And recievers are hard too
well skerr thinks its doable
we have 19 days left
transmitter is almost functional
very close
we built a yagi antenna
and are amplifying voltages from a computer
into the yagi
You could use similar circuitry to a 20W QRP transmitter
we've got the transmitter
interesting
transmitter going well, Fourier analysis I built a pretty solid program if I do say so myself