#help-with-radio

1 messages · Page 2 of 1

untold needle
#

Also surely SciPy fftpack just does it for me @granite spear, or reduces the work significantly

granite spear
#

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.

untold needle
untold needle
#

Assembly language for what

granite spear
#

Yes, but I mean to get the RP2040 talking to the ADC. That's the advanced part.

untold needle
#

Doesn't seem impossible

#

Probably youtube tutorials for it

#

Or books

granite spear
#

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.

untold needle
#

As the ADC has to comply with the RP2040

granite spear
#

It's more like "your software has to MAKE the RP2040 comply with the ADC".

untold needle
#

I found tutorials and resources for 500kHz sampling

#

But I need 2MHz at least

untold needle
granite spear
#

Yeah, as you noted it's not fast enough for Nyquist.

untold needle
#

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

granite spear
#

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.

untold needle
#

Yes got it

untold needle
#

Why can't RP2040 just grab one number and add to file

#

So trivial right

half plover
granite spear
#

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.

half plover
untold needle
#

I don't think I fully understand the coding required at the moment

young cove
#

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.

granite spear
#

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.

wary arrow
#

Probably naive question: why do DSPs have general-purpose processors, when DDSs don’t?

young cove
#

@untold needle ^ up a few posts

half plover
young cove
#

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

young cove
# wary arrow Probably naive question: why do DSPs have general-purpose processors, when DDSs ...

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.

untold needle
untold needle
young cove
#

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

untold needle
#

too*

young cove
#

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

untold needle
#

200g

#

and current draw is 200mA

#

250mA maybe actually

young cove
#

yup, that is small, too small for something like an RPi zero

untold needle
#

plus I'm not afraid of working 5-6 hour days

#

and we have like 6 people

young cove
#

is the radio already built?

untold needle
#

only me and one other guy are particularly useful

young cove
#

the radio part

untold needle
young cove
#

is this a class project or a research project ... no, the receiver you outlined above, before the data acquisition

untold needle
#

Well we have build a yagi antenna and are connecting it to a function generator for the transmitter

untold needle
#

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

young cove
#

ok, so long term maintainability is not a requirement 🙂

untold needle
#

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

young cove
#

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

untold needle
half plover
short nimbus
#

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

primal warren
wary arrow
#

Is a raspberry pi a good thing to use to connect to / manage things like ADCs and DSPs?

primal warren
#

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).

untold needle
#

@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

untold needle
#

I think ill go with pyfftw

granite spear
untold needle
granite spear
#

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.

granite spear
untold needle
#

It requires more lines of code to get the data than to fft it

granite spear
#

Yep, that's what I'd expect. The FFT itself will just be a function call.

untold needle
#

Thank God there are modules for it

untold needle
#

Could just use matplotlib?

granite spear
#

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.

untold needle
#

I have github copilot too

#

👍

#

And chat gpt as backhup

#

The Holy trinity of programming

#

Chat gpt isn't that good to be fair

granite spear
#

Heh heh, that matches well with Larry Wall's quote that the three cardinal virtues of a programmer are laziness, impatience, and hubris. 😁

untold needle
short nimbus
# untold needle Chat gpt isn't that good to be fair

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 🤦

restive fjord
short nimbus
#

Noah would be confused because of oreilly books today

#

"Do I also have to save 2 books of the same type from oreilly too?"

untold needle
#

@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.

untold needle
#

@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

untold needle
#

now added axis labels which I thought was a smart idea

granite spear
untold needle
granite spear
untold needle
untold needle
granite spear
untold needle
granite spear
untold needle
#

we will take 5-10ms of data one every 2-3 minutes

untold needle
#

@granite spear I've invited a few of my project team members here

#

such as @weak niche and @twilit drum

weak niche
#

Yo

tropic fractal
#

Hi

twilit drum
#

Hello

fast isle
#

cool stuff here

crystal citrus
#

Hello

untold needle
primal warren
untold needle
untold needle
granite spear
#

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.

primal warren
#

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.

untold needle
#

though

primal warren
#

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.

granite spear
#

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.

untold needle
untold needle
#

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

primal warren
#

That's what I was thinking

granite spear
untold needle
#

right right

#

so the Pico will basically just control my whole circuit

untold needle
untold needle
granite spear
untold needle
#

oh

#

this is significantly easier than the other solutions

primal warren
#

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

granite spear
#

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.

untold needle
granite spear
untold needle
#

mmm, somehow this doesn't seem ridiculously difficult but still lots of scope for error

granite spear
untold needle
#

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

granite spear
untold needle
#

ah, so a bit trickier

granite spear
#

The order comes from the pin labels. The bits would go in order like D0, D1, D2, etc.

untold needle
#

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

granite spear
#

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.

worn bridge
untold needle
#

we did that in computing class ages ago

#

I know how binary works well

#

unsigned and signed integers

#

8-bit, 10-bit

untold needle
worn bridge
#

The outer shell is certainly python-able, but the PIO state machines are built in assembly-esque syntax.

untold needle
#

oh I see

worn bridge
#

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.

untold needle
#

not even approx

#

it will be 10MHz

untold needle
#

10MHz is quite fast

worn bridge
#

Yeah, sounds like a job for PIO or C.

untold needle
worn bridge
#

It’s pretty borderline. I would assume PIO would be the more reliable method here.

untold needle
untold needle
worn bridge
#

Breadboard is usually the way to go, if you’re not ready to solder wires yet.

granite spear
#

Yep. Your ADC might not be available in a breadboard-friendly package, though. The one you linked to above is surface-mount.

untold needle
#

not sure how to go about that

untold needle
#

there are quite a few adapters aren't there?

remote pond
untold needle
#

plus the pico we have is with headers already

remote pond
remote pond
#

at least it's not QFN or BGA

untold needle
#

compared to mixers and oscillators at least

half plover
untold needle
granite spear
untold needle
#

how have I missed that

#

whoops

untold needle
#

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???

untold needle
#

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

untold needle
#

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

half plover
untold needle
half plover
#

The corresponding value together makes up an 8 bit value that you then can easy convert into an integer.

untold needle
#

I need to figure out how to check if a pin is high or low using PIO

half plover
#

Yup, you use PIO to capture the state of each pin simultaneously

untold needle
#

😂

#

though it seems like something that I can google

half plover
#

Yup

untold needle
half plover
#

These are technically for writing it in C

#

If you’re using C, yes

untold needle
#

it will be going at something like 10-15MHz sampling

half plover
#

C is the fastest in the hardware world

untold needle
half plover
#

C++ is a higher abstraction of C, so no

untold needle
#

o

half plover
#

Hence the ++ bits

#

C++ takes care of many of the nuances that can be gotchas in C

untold needle
#

right

half plover
#

But those conveniences come at a cost

untold needle
#

#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");
    }
}

}

half plover
untold needle
#

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

half plover
#

It probably would, I’m not near my computer or a Pico to try at the moment

untold needle
#

I thought this was going to be more difficult

half plover
#

I will note that it’s generally a better practice to store the pin value in a local variable.

untold needle
#

To be fair, I am quite bad at C

untold needle
half plover
#

C/C++ is my day job and I’m not great at is

untold needle
#

I am terrible

#

chat gpt is probably better than me

half plover
#

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

untold needle
untold needle
#

to check 8 pins at the same time

half plover
untold needle
#

oh.

#

this seems useful

half plover
#

I’d work off something like this example

untold needle
half plover
#

Raspberry Pi invests a lot of money in making the SDK good by including examples so they’re great jumping off points.

untold needle
#

What does it do that my/chat gpt's code doesn't

half plover
#

Yeah, it probably will be.

untold needle
#

ouch

half plover
#

Sets up a PIO program, configures all pin states, adds the PIO program to the pio peripheral, manages the state machine.

untold needle
#

this one looks so hard

half plover
#

PIO takes a lot to get going properly

untold needle
half plover
#

That’s what makes it fast 😉

untold needle
#

oh no

#

I don't even understand it

#

gulp

half plover
#

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

untold needle
half plover
#

Nah

untold needle
#

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

half plover
#

There’s not really a question limit

#

Doing new things can be hard, but that’s what makes them worth doing.

untold needle
#

I need to understand this PIO code

half plover
#

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

untold needle
#

hopefully EdKeyes pops along

half plover
#

And reference that read the docs page too

untold needle
half plover
#

You might get some practice writing PIO programs using circuitpython as well

untold needle
#

I love python

#

I wish it was faster

untold needle
untold needle
half plover
#

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.

untold needle
#

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.

half plover
#

It’s fun, but I wouldn’t rely on it to be your source of truth when writing this.

untold needle
#

chat gpt seems reliable though

#

for this at least

#

it gives good suggestions

west perch
#

Or THINKS it gives good suggestions

untold needle
#

while its code might be wrong

half plover
#

Eh, I would still lean far more heavily on resources like stack exchange or documentation for your code.

untold needle
#

the suggestions seem decent-ish

west perch
#

It doesn’t actually know anything — just a lot of clever guessing

untold needle
half plover
#

In my experience, ChatGPT is not a tool a programmer should use for their work.

west perch
untold needle
#

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

west perch
#

I agree with skerr, better to check previous human work

untold needle
#

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

worn bridge
#

Storage, too.

untold needle
#

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

worn bridge
#

Looks like CAPTURE_PIN_COUNT will adjust the number of pins to sample

untold needle
#

capture_pin_base to 0

worn bridge
#

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

untold needle
untold needle
young cove
#

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.

untold needle
young cove
#

if it would at least do attribution, you could go to the original sources. The Bing Chat thing recently demonstrated does do attribution.

untold needle
west perch
#

It’s more a toy right now

half plover
west perch
#

I poke it now and then

untold needle
#

same

untold needle
west perch
#

Probably more fun to play against a monkey…

untold needle
untold needle
#

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

half plover
#

Raise your reference voltage

untold needle
half plover
#

Is this the RP2040 ADC?

#

Or that TSSOP one

untold needle
half plover
#

Okay

untold needle
#

I am connecting that to the RP2040 through PIO

#

but I need to avoid negative voltages below -0.3V or preferably anything below 0V

untold needle
half plover
#

You can pass your ADC input through a voltage divider

untold needle
half plover
#

Okay, let me explain through an image

untold needle
#

ok

half plover
#

What this does is raises the “0V” to half VCC

untold needle
#

this just splits VCC in half yes

#

I know how voltage dividers work from my electronics classes

half plover
#

👍🏻

untold needle
#

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?

half plover
#

In a way yes

untold needle
#

this basically just shifts the graph upwards, which is perfect

half plover
#

Yup

untold needle
#

so this is like

#

y = sin(x) + 2

half plover
#

If you’re power conscious, consider larger resistors

untold needle
#

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

half plover
#

Yeah, makes sense

untold needle
#

V = IR

#

voltage is constant

#

Oh

#

increasing resistance decreases current

#

I see.

half plover
#

Right

untold needle
#

I = V/R

untold needle
#

silly me

half plover
#

You could probably use 2x 1k resistors for a nice small milliamp power draw

#

2.5mA

#

12.5mW

untold needle
#

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

half plover
#

I’ve used it on some optical ADC projects that saw voltage swing wildly

untold needle
#

wow

#

its actually beautiful

#

just put it through a voltage divider and move the sine wave upwards on a graph

half plover
#

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

untold needle
#

though I'm sure he has some 1% ones too

#

idk if he has 0.5 and 0.1%, he probably does but idk

half plover
#

Use the best you can get, just make sure they’re identical in value and tolerance

untold needle
#

wait can't I just use

#

Vout = Vin*R2/R1+R2

#

product over sum

half plover
#

If they’re symmetrical you know center is 1/2 VCC

untold needle
#

its still minute though

#

so it shouldn't make the biggest different

#

difference

half plover
#

Right

untold needle
#

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

half plover
#

Lots of projects, experimentation, working for a Visible Light Communications startup

untold needle
#

this project is probably my biggest yet

half plover
#

Also I have an undergrad degree in computer engineering

untold needle
#

also why is the word 'd a m n' censored

half plover
#

It’s generally not consider child friendly as we have younger makers on this discord

untold needle
untold needle
half plover
#

Hardly lol, I use python as often as I can

untold needle
#

I mean C is pretty useful

#

its fast

#

thats basically its main positive

#

I only know python

half plover
#

It is, but I usually don’t need it for my projects. I use it at work mostly (C/C++)

untold needle
#

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

half plover
#

It’s all useful, love it or hate it, it’s good to know.

untold needle
#

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

half plover
untold needle
#

what is your feeling though?

half plover
#

Hard to say at this moment, I don’t see anything glaringly obvious.

untold needle
#

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

untold needle
#

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

granite spear
#

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.

untold needle
untold needle
#

@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

granite spear
#

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.

untold needle
granite spear
#

I thought you were using C above?

untold needle
#

because speed is required

#

Oh right, is there no way to do both?

granite spear
#

Not easily, yeah. Your application would typically either be all Micropython or all C.

untold needle
#

that's going to be hard

#

what do I have to adjust in that PIO code

granite spear
#

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.

untold needle
#

also, what is this business of the 'falling edge' of the clock input

granite spear
#

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.

untold needle
granite spear
#

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".

untold needle
#

ok

granite spear
#

I assume the logic analyzer code has a way to specify that.

untold needle
#

yes it does

untold needle
#

it does

#

at the beginning

#

but then how to make it turn of for 5ms

#

as it doesnt know that

#

either

granite spear
#

That would be part of your higher level application loop... record for 5 ms, save all the data, sleep for 5 minutes, repeat.

untold needle
#

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

granite spear
#

Yep, the same sort of loop structures and delay calls are available in C too.

untold needle
#

like this

granite spear
#

You could, but I suspect that would just needlessly complicate your code.

untold needle
#

and how else would I do it

granite spear
#

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.

untold needle
#

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

granite spear
#

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.

granite spear
#

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.

untold needle
granite spear
#

Single backticks give you inline code like this while triple backticks give you a code blocklike this

untold needle
#
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

granite spear
#

It might be doing that as test output to have a signal to capture?

untold needle
#

right

untold needle
#

// 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

granite spear
#

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.

untold needle
#

low

granite spear
#

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.

untold needle
#

this is pretty complex code

#

idk what the PWM does

#

I sort of understand the rest

half plover
#

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.

untold needle
half plover
#

In this context? It’s likely just telling the peripheral that the signal will be either PWM or PWM like.

untold needle
#

oh ok

half plover
#

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

untold needle
#

Do I need the example

#

this code is so complex

half plover
#

I’d venture to say you don’t need it

untold needle
untold needle
#

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.

half plover
#

The key here is simultaneous acquisition

untold needle
half plover
#

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)

untold needle
#

Wow sorry to bother you

#

forgot not everyone lives in the UK

#

🥲

half plover
#

Not an issue, I can respond in between compiling code

primal warren
#

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.

untold needle
#

I dont follo

#

follow

half plover
#

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

untold needle
#

extremely hairy

#

I mean it has to be anywhere above 10MHz basically

half plover
#

That’s why PIO is great because it’s independent from the cpu and has instant access to pin states.

untold needle
#

we will probably run it at 10MHz

untold needle
#

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

half plover
#

👍🏻

primal warren
#

A lot of us are multitasking

untold needle
half plover
#

Btw madbodger there is very knowledgeable as well, very creative solutions

half plover
#

A lot of corner case things you wouldn’t think of.

untold needle
primal warren
#

Alas, I'm not up to it at the moment, I'm brain fried

untold needle
#

that is unfortunate

#

I'll repost it if you change your mind.

short nimbus
#

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

grizzled vapor
#

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.

short nimbus
#

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 ?

grizzled vapor
#

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?

half plover
#

You probably want a pi network

#

Pick a band like.. 88.3MHz

grizzled vapor
#

I just now understand impedance

half plover
#

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

grizzled vapor
#

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

half plover
#

Or coax is common

grizzled vapor
#

That could work, but putting the antenna on the PCB would be even cooler

half plover
#

Yeah, I’m not confident they make chip FM antenna

grizzled vapor
#

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

half plover
#

Yeah, FM quarter wave is too long

#

There’s some portable radio antenna with SMA connectors so you can have an SMA board connector

grizzled vapor
#

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

short nimbus
#

Shame that you have a total power limit

#

because in the 1940s they used a passive FM radio to listen in on US ambassadors

grizzled vapor
#

The harvester IC has "ZMPPT". I guess that means it can adjust its own impedance so the power delivered is at a maximum

short nimbus
#

with a theramin-like device and it sent out AM signals when it was iluminated by FM signals

grizzled vapor
#

That's some pretty cool engineering

#

sounds like backscatter

short nimbus
#

it was called "the thing" in a wood seal of the soviet union

grizzled vapor
short nimbus
#

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...

grizzled vapor
untold needle
#

@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*

untold needle
#

also i built the circuit

primal warren
untold needle
#

oh alright

primal warren
#

What are R3 and R4 for? It looks like they would just waste power.

untold needle
#

so I don't get negative voltages

primal warren
#

That won't work.

untold needle
primal warren
#

You'd need a coupling capacitor to block the mixer from grounding out the signal.

untold needle
primal warren
#

That will only work with a floating signal in. That mixer does not provide a floating signal.

primal warren
#

Insert a capacitor between the mixer and the resistors.

untold needle
primal warren
#

Right

untold needle
#

0.1uF or 10uF or something

primal warren
#

The capacitance, along with the load impedance, determines the cutoff frequency

untold needle
#

is there any way to calculate the capacitance required then?

grizzled vapor
#

High pass filter calculator

untold needle
#

im not adding a band pas filter

grizzled vapor
#

Generally, a higher capacitance will mean more ac at lower frequencies gets through

grizzled vapor
untold needle
#

i guess ill add a 10uF

grizzled vapor
#

What is this for anyways?

untold needle
#

I need to add 2.5V to every voltage coming out of the RF mixer

grizzled vapor
#

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.

untold needle
#

its fast enough i think

primal warren
#

1/2πRC

grizzled vapor
#

That gives you at most 7.5 MHz maximum

untold needle
grizzled vapor
#

But a good rule of thumb is to divide by 5

untold needle
#

it is reading 0-3MHz

grizzled vapor
#

So 3MHz

untold needle
#

it is mixed down to 0-2/3MHz

untold needle
untold needle
#

4k

#

from the voltage divider

primal warren
#

Nope, it's 1k, since they're effectively in parallel

untold needle
primal warren
#

2 separate 2k resistors

untold needle
#

yes

#

2 i meant

#

mistype

#

therefore C = 4/1000pi

primal warren
#

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.

untold needle
#

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

primal warren
#

You left F out of your equation. The cutoff frequency (F) is 1/2πRC

untold needle
#

yes

#

C = 4*10^6/Pi * 10^3

#

= 4*10^3 / pi

primal warren
#

No, you left F out of the equation again

untold needle
#

F = 2 mega

primal warren
#

That's way too low, maybe use 6 megahertz

untold needle
#

LO is 27MHz

primal warren
#

You said 2-3 MHz

#

LO doesn't matter

untold needle
#

we are broadcasting 25.2 --> 28.8MHz

#

so the IF will maximum be 1.8MHz

#

2MHz to be safe

primal warren
#

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.

untold needle
#

ok so 5MHz

primal warren
#

OK

untold needle
#

thats weird

#

I get a capacitance of 10^4/Pi

grizzled vapor
#

3db lower means 1/2 of input signal amplitude

#

For reference

untold needle
#

thats impossible

#

I cant get a 3kF capacitor

#

I have to increase R then

grizzled vapor
#

Definitely

untold needle
#

yes massively

grizzled vapor
#

LC filter is basically a voltage divider, but with a cap instead of a resistor. Since the capacitor's impedance decreases as frequency rises...

untold needle
#

ok so I need like a 3M ohm resistor

#

jesus

grizzled vapor
#

What is your cutoff? And high pass or low pass filter?

untold needle
#

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

grizzled vapor
#

You can't easily get 1F cap

untold needle
grizzled vapor
#

Maybe LC filter

untold needle
#

wait does it have to be electrolytic?

grizzled vapor
#

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

untold needle
#

yes, 1 farad is massive

#

ok we make the resistor higher

#

we spam resistor

grizzled vapor
#

Too much resistor means that you might get a lot of noise I think

untold needle
#

this is not good

#

We need a solution

grizzled vapor
#

Lc filter

untold needle
#

whats the difference

#

I dont even know if this is a filter

grizzled vapor
#

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

untold needle
#

@grizzled vapor the aim is just to add 2.5V to every voltage coming out of the mixer

grizzled vapor
#

IF amp ICs exist

untold needle
#

I dont understand why we have to filter things

grizzled vapor
#

It's because you inadvertently add a filter when doing the voltage bias

untold needle
#

oh right

#

whats the solution

grizzled vapor
#

You could reference mixer/RF ground to a virtual ground at 2.5v?

#

Just a resistor divider

#

Or use lmc7660 negative voltage supply

untold needle
#

hmm that seems interesting

grizzled vapor
#

Another option is to use a transformer

untold needle
#

not an option for us

grizzled vapor
#

One that's good for HF

untold needle
#

does that just automatically add 2.5 to every voltage @grizzled vapor

grizzled vapor
#

Also make sure your LO shares the 2.5v virtual ground

untold needle
#

brilliant

grizzled vapor
#

Although...

#

But virtual ground might be more stable

#

Or better in another way

untold needle
#

I need 5MHz not 1 hertz

#

But yes virtual ground seems like a good idea

#

@primal warren will this work, save me

grizzled vapor
#

But since it is a high pass filter that passes all freqs higher than x hertz

#

In this case 1Hz

untold needle
#

oh

#

but surely thats fine then

grizzled vapor
#

Maybe run a few simulations first or just experiment with your circuit

untold needle
#

oh right

#

so I only need one resistor

#

rather than a voltalge divider

grizzled vapor
#

Use two resistor divider

untold needle
#

ok

grizzled vapor
#

And since they are effectively in parallel

untold needle
#

so capacitor --> 2 resistor divider

grizzled vapor
#

You just use R value of half of single resistance

untold needle
#

can you draw me a diagram please, I'm not fully understanding

grizzled vapor
#

Use Google

untold needle
#

I created virtual ground for mixer and oscillator

#

@grizzled vapor so what do I need to connect the IF pin to?

grizzled vapor
#

That's output

#

Also maybe add cap to vgnd

untold needle
untold needle
#

I adjusted the circuit to meet the requirements that you suggested @primal warren @grizzled vapor

primal warren
primal warren
granite spear
#

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.

grizzled vapor
#

You need to correct some of the capacitors and power supply thins as edkeyes said. There are some shorts and reversed capacitors

untold needle
untold needle
half plover
#

Usually a LDO

untold needle
#

@granite spear im going off this for the capacitors

#

low dropout regulator?

half plover
#

Yup

#

But the Pico 3.3V DCDC should work just fine

untold needle
# half plover Yup

this circuit seems like whenever I want to add one component, I end up having to add another 10

untold needle
half plover
#

3.3V is pretty standard

primal warren
#

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

untold needle
primal warren
#

You'll need an RF amplifier, and probably some impedance matching networks

granite spear
untold needle
primal warren
#

I didn't see that on your board, just an "antenna in", so I didn't know if that went straight to an antenna.

untold needle
#

yes

#

I've done that separately

untold needle
untold needle
#

so this then

#

ok

primal warren
untold needle
#

ok so should I get the pico to power the ADC?

granite spear
worn bridge
primal warren
#

Possibly, depending on the voltage/current it needs. And the way it's drawn, your power supply is short-circuited anyway

primal warren
#

You have the + (left) side of the left hand capacitor group connected to both power and ground.

untold needle
#

@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.

primal warren
#

Maybe consider something like this for the digital and analog power supplies for your ADC

grizzled vapor
#

Why are AVDD and DVDD connected to ground?

#

They should be connected to VCC

untold needle
#

it isnt connected to ground?

#

is it

untold needle
grizzled vapor
#

The voltage divider should ideally also have resistors of equal values

primal warren
#

No, the voltage divider is designed to center the input in the range the ADC accepts

untold needle
#

sensor's center

half plover
#

If the range of the ADC is 0-VCC, center would be half VCC

untold needle
half plover
#

I don’t think that’s right.

#

Plus the divider should be pulled up to VCC of the ADC, not 5V

untold needle
#

then it would 'add' 1.5V to every voltage

half plover
#

Because you’re changing the reference

#

The divider being between VCC and gnd ensures there will be no negative values

untold needle
#

Didn't madbodger say to use it to centre the voltage

grizzled vapor
untold needle
#

yep

#

they are

#

thanks

half plover
#

Let me provide a reference to what I’m saying

grizzled vapor
#

The hardest to diagnose errors are always stupid mistakes

untold needle
#

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.

granite spear
#

The 3.3V pin on the Pico should be able to power the ADC, using its onboard regulator.

half plover
#

Yeah, there’s no need to tap the 5V rail either

untold needle
half plover
untold needle
#

so I tap that to the Pi pico power supply to

half plover
#

Yeah

untold needle
#

okie

untold needle
half plover
#

Your voltage divider will change

untold needle
#

but what voltage needs to come out of the divider

half plover
#

You will want it centered on the ADC supply since that’s its reference

#

So 1.65..V

untold needle
#

oh whoops

#

yes

#

3.3/2 not 3/2

#

yes

untold needle
half plover
#

Right

untold needle
#

Version 2500 with no errors I believe

#

@half plover @granite spear @primal warren give it the godly signal of approval

#

🥲

granite spear
#

Heh heh. "Approval" is a strong word, but I don't see anything obviously wrong, at least. 👍

untold needle
#

any suggestions of where to add these things

granite spear
#

I'll have to defer to other folks about that, as I'm more of a digital guy rather than RF.

half plover
#

Same, my knowledge stops there as well

#

But you’ll want to use something with a wide GPBW

untold needle
#

I have 19 days left on the project now

half plover
#

Gain Product Bandwidth

untold needle
#

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 ^

half plover
#

Definitely doable

untold needle
grizzled vapor
#

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.

untold needle
# grizzled vapor But what is the project?

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.

untold needle
#

plus we're into it

grizzled vapor
untold needle
#

I'm in the uk

#

but its an international competition

#

it takes place in belgium @grizzled vapor so we have permission from them

grizzled vapor
#

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

untold needle
#

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

grizzled vapor
#

You could use similar circuitry to a 20W QRP transmitter

untold needle
#

we've got the transmitter

untold needle
#

transmitter going well, Fourier analysis I built a pretty solid program if I do say so myself