jdesbonnet / RCWL-0516

Information about RCWL-0516 microwave proximity switch module (ICStation.com SKU 10630)
717 stars 102 forks source link

Ditch the IC, use just analog circuitry connected to uC ? #37

Open Harvie opened 4 years ago

Harvie commented 4 years ago

I am designing my own board with microcontroller (either ESP32 or ATmega), i would like to include the doppler sensor design directly to that board. I am bit tight on space and i was thinking that maybe i can just use the RF part of this circuit and replace RCWL 9196 block with my own circuitry to detect the output frequency shift myself. Effectively i want to cut the RCWL-0516 part in half and throw the IC half away.

I guess we can detect the baseband (downconverted doppler shift signal) using ADC of microcontroller. Maybe with little help of LM358 opamp or something... Another good thing about this might be that we would be able to fine tune signal processing in firmware in order to achieve desired sensitivity and range, without modifying analog circuitry, timing capacitors, etc...

Any ideas how to do this? Unfortunately i don't have scope at hand :/

Harvie commented 4 years ago

I've recorded signal on pins 12 and 16 using arduino nano ADC (single ended, 5V reference, samplerate less than 20 Hz). Please note that these are RCWL-9196 OUTPUT pins. Signal on input pins was too weak to be captured by single ended ADC without amplification.

The signal goes through two on chip opamps of RCWL-9196, pin 16 is output of first opamp, pin 12 is output of second one (=more amplified and filtered). There is also some kind of tuned RC network in feedback path of both of these opamps (see schematic for reference), which means there is not only amplification, but probably also some filtering going on.

I think it might be possible to replace RCWL-9196 IC with dual opamp IC like eg. LM358, given that we use the same feedback filter circuitry. Output of second stage can then be easily processed by microcontroller.

Another possibility might be use microcontroller with differential ADC (these often include gain settings). Filtering then might be possible in software. Maybe simple EWMA based bandpass filter to remove DC offset and high frequency noise will be enough?

image

image

I was standing 1 to 2m away from sensor. First rectangle is me raising my hand to scratch my head. Second rectangle is me jumping around and waving my hands for a while.

Harvie commented 4 years ago

OK, so we've managed to design the radar to custom microcontroller PCB while replacing RCWL-9196 IC by commonly available opamp. I will post more details later...

chaotix- commented 4 years ago

That is very interesting. Did you get it to work? Do you have more information on this?

Harvie commented 4 years ago

Yes. It is working including feeding the analogue signal to ADC. But i am just very busy. Hopefully i will manage to make Kicad design and upload it, but i have no idea about ETA. Also we based this on slightly different design, which has only simple ground plane without funny shapes on the back side of the board, which probably simplifies the manufacture...

chaotix- commented 4 years ago

Please do, when you finde the time and post a short note in this issue. Thanks a lot.

paddyrg commented 4 years ago

I'd also love to see your results, it could be quite handy for me in the next couple of months!

gauravduggal commented 3 years ago

Hi all, Please checkout my work here https://github.com/mimeakadug/Doppler_Radar_RCWL-0516. I have sampled the baseband signal using an arduino and processed the signal to generate a Fourier plot while the radar is looking at a ceiling fan. The Ceiling fan induces multiple Doppler velocities as seen the photos below Target - Ceiling Fan Time and Frequency Domain Edit: The radar parameters are calculated by the code and printed:


Sampling frequency of ADC: 1563.5 Sampleing time of ADC: 0.0006395906619763352 Wavelength: 0.09674298613350532 m Hamming window used Sampling duration: 2.619763351455069 Doppler frequency resolution: 0.3817138671875 Hz Doppler velocity resolution: 0.018464069680143504 m/s max detectable velocity: 37.79595063525375 m/s


thanks GD

gauravduggal commented 3 years ago

STFT_psd_td_fan -Added STFT algorithm for spectrogram display. Getting more meaningful results. -Power spectral density i.s plotted too. Time domain signal converted to volts (V)

Hypothesis -> 18 peaks in 1.2 seconds -> 15 peaks in 1 second -> 5 revolution per second (divide by 3 fan blades) -> 900 rpm which is approximately how fast a ceiling fan rotates at full speed.

Code: https://github.com/gduggal1729/Doppler_Radar_Signal_Processing

dbuezas commented 3 years ago

Would a higher time resolution be useful for you? There are ways to speed that up quite a lot (e.g. changing the ADC clock prescaler, ditching analogRead, acquiring and sending in batches, ...).

gauravduggal commented 3 years ago

@dbuezas A higher time resolution will mean I can detect higher Doppler velocity shifts. I can already detect up to 37 m/s with the RCWL-0516 which would be alright for most things.

I am planning to try this code with another Doppler radar which has a higher Carrier frequency hence would result in higher Doppler frequencies for the same velocity of the target so for that it would be helpful. I would appreciate any changes / suggestions you would want to make my code I see you are a much better coder than I am :)!

dbuezas commented 3 years ago

These are really interesting experiments you're doing. I'll gladly help if you need a couple of tricks to speed up readings. I recently spend some time doing exactly that in this project https://github.com/dbuezas/arduino-web-oscilloscope (not for standard arduino boards yet)

Harvie commented 3 years ago

I have some work in progress KiCAD design of USB-C ESP32 devkit with doppler radar daughterboard:

image

I've used bit different radar design, which does not need any shapes on the back side of PCB. Just ground plane. This is really great, because single sided boards are easier to make at home. (well actualy dual sided, but ground plane does not require alignment or any complex etched pattern on back). Also this makes it possible to use 4 layer board in scuh way that 2 layers are used for radar and two more layers are still left for microcontroller and other stuff. I've unfolded this to separate daughterboard, because it is expensive to do pick and place on both sides at the same time, but it can be cut and folded back on itself.

Unfortunately there are several issues (both technical and legal) i need to solve before i will be able to share the files.

chaotix- commented 3 years ago

Unfortunately there are several issues (both technical and legal) i need to solve before i will be able to share the files.

This sounds very promising. Please share when you have solved the problems. I'm still very much interested.

danilozte commented 2 years ago

Chaotix como vas con los diseños? ya solucionaste los problemas tecnicos de diseño?, quiero hacer mi propio diseño. Chaotix how are you doing with the designs? have you solved the technical design problems, I want to make my own design.

Harvie commented 2 years ago

There was not much progress since in terms of design. The legal problems are mostly solved. I think i will need to review the files to see if all chips are still available for PCBA, since global chip shortage messed us a bit. Then i will order the prototype batch to verify the design. Hopefully i will find some time to do this as i am still rather busy.

I know it's been long. But i had not abandoned the idea yet :-)

willtmakinen78 commented 2 years ago

Harvie, any updates in the last 4 months? Even if the design isn't fully validated I would love to see the KiCAD files and/or see a schematic, since I would like to do something very similar and your files could serve as a great starting point.

Harvie commented 2 years ago

Yes, sorry. i am busy. i will try to share the design today even when not fully routed and tested. however we had some success with it in the past (but on different board containing much more peripherals).

Harvie commented 2 years ago

Ok, here are the files:

REF-radar.tar.gz

Some notes:

Eg. Here you can see ratsnest indicating where exactly to place the R9 resistor for PCB assembly. all RF-critical components are tied like this. Layout of baseband (low frequency) amplifier circuit is not very critical, but try to keep traces reasonably short. image

willtmakinen78 commented 2 years ago

This is great, I'll have a look at it and let you know my thoughts and if I have any questions

willtmakinen78 commented 2 years ago

Harvie, I'm confused about the purpose of this IC in the schematic. None of the components attached to it appear in the PCB file. Additionally, what's the difference between the 3v3, Radar_3v3, and the VCC lines radar_ic_screenshot ?

Harvie commented 2 years ago

Harvie, I'm confused about the purpose of this IC in the schematic.

That is not IC. This is symbol which is associated with the radar RF footprint. Or you may call it "the pcb antenna". There is no actual component populated to this footprint. All components have separate footprint. This might look rather cryptic at the first sight (especially in the schematic), however it allows you to easily integrate this antenna footprint to your custom PCB without having to carefully craft the RF layout every time, which was my goal. Also it allows you to generate data for automatic assembly, because each component has it's own footprint overlayed on top of that antenna. i wouldn't able to figure better way of doing this so that design remains both easily reusable and fit for PCBA.

what's the difference between the 3v3, Radar_3v3, and the VCC lines

There is transistor which uses digital signal to switch 3V3 that goes to radar, so you can disable it using microcontroller when not needed. You can ditch the transistor circuit and let it powered on all the time. (eg. directly shorting 3v3 and radar_3v3). If you have complex design and you figure out, the radar is causing some RF interferrence or violates regulation, you can at least disable it by firmware upgrade, so that you can still use rest of the device safely, until you fix the hardware.

willtmakinen78 commented 2 years ago

That makes sense. Where in the PCB file is the BFR193 Q4? Only the Si2301CDS Q3 is present on the current layout.

Harvie commented 2 years ago

That makes sense. Where in the PCB file is the BFR193 Q4? Only the Si2301CDS Q3 is present on the current layout.

You are right. you wanted it quickly, so i haven't checked almost anything :-) The REF numbering do not match between schematic and pcb, you might want to fox that. But there are only two transistors. One optional which switches the whole thing on and of. Second is part of the RF design of radar. All of the parts which are only directly connected to the "antenna" symbol are placed on top of the RF footprint. Therefore the RF transistor is this one:

image

Harvie commented 2 years ago

Just pres this button in PCB

image

Then select "delete footprints without symbols" and "replace footprints with those specified in schematic"

it will probably sync

willtmakinen78 commented 2 years ago

Another question, what is the inductance of the microstrip inductor (squiggly trace), and the parameters of the rectangular antenna traces? Also, what frequency does it oscillate at?

Harvie commented 2 years ago

what is the inductance of the microstrip inductor (squiggly trace), and the parameters of the rectangular antenna traces?

TBH i don't know, it will vary on different boards due to thickness and material differences, etc... You should not use board which is too thick, i would stick with thinner ones if possible. I don't have equipment required to measure these, however you can find online calculators, put dimensions in and you will get some approximate calculation if that's important to you.

The design is based on some chinese module, but we've replaced baseband circuitry with opamp so we can process the output with ADC on ESP32. (original only had digital output which latched in active state for few seconds after each trigger). It should allow to detect magnitude of motion and therefore fine tune sensitivity in software, as long as you can do some basic signal processing, removing DC offset, calibrate threshold levels, maybe apply low pass filter, etc... This modification was proven to work with microcontroler (even on rather thick board), but not proven to comply with regulations.

Also, what frequency does it oscillate at?

I beleive it was little bit over 3GHz, but never really measured it, so take that with huge crystal of salt. Fortunately this circuit is not very sensitive to frequency variation. Like most of the cheap doppler radars, it uses same oscillator for TX and RX, so it can receive whatever frequency it transmits, so basicaly it subtracts the transmitted frequency from received signal and you are in turn left with just the difference between the two, which is rather low frequency which can be easily processed in the baseband amplifier and captured to uC using ADC. Exact RF frequency is not that critical (unless we speak about local regulations)

You might even try to use different PCB thickness to change the frequency until you get to some freely available part of specturm. Otherwise you might try to change dimensions of the RF traces a bit.

willtmakinen78 commented 2 years ago

Thanks. A final thing I was curious about was the choice in corner frequencies of the op amp bandpass filter - after simulation they seem to be around 100Hz and 100KHz. For person detection, a doppler shift of 1-100Hz would be more expected, as these frequencies correlate to movement speeds of 0.5m/s-10m/s. Obviously you gotworkable results from the current circuit, but I was wondering what your thought process was. Does the atennae and supporting circuitry shift the difference in frequency up in some way?

Harvie commented 2 years ago

what your thought process was

it was quite some time, but i beleive the original circuit used some application specific IC, which also had integrated amplifier along with other things, so we just took that circuit and replaced "weird" chinese IC with more common LM358 standalone opamp so we only get the unprocessed baseband signal.

after simulation they seem to be around 100Hz and 100KHz.

interresting. what are you using for the simulation? never tried simulating anything RF.

For person detection, a doppler shift of 1-100Hz would be more expected, as these frequencies correlate to movement speeds of 0.5m/s-10m/s.

Great. This is exactly the reason why i shared the design. So smart people like you can figure out new ways to improve it :-) Should be simple as replacing some RC filters right? You can order several PCBs for cheap and try populating different baseband filter setups and let us know what works best for you. Just note that between 1 and 100Hz that you propose lays huge ammount of noise caused by 50/60Hz mains and these devices are often mounted directly to light fixtures, lightbulbs, etc... Might that be an issue?

Does the atennae and supporting circuitry shift the difference in frequency up in some way?

I have no way to measure this

willtmakinen78 commented 2 years ago

I just used LTspice for simuation, here's a screenshot of the bode plot, starting from th initial low pass filter consisting of R26, R27, R30, and C24-C27 to the output of the 2nd stage of the amplifier.

image

Defintely some room for playing around here - I was going to do exactly what you suggested and get a few boards made up with different gains and corner frequencies and see which ones work best, as well as using a scope to see what the doppler shits being produced by the antenna actually looks like. This should also let me see what sort of mains interference occurs as well.

willtmakinen78 commented 2 years ago

The design is based on some chinese module,

Any chance you know which module?

Harvie commented 2 years ago

Any chance you know which module?

We've been working on this with several people. I had this idea to add analog output to chinese module and i was helping with the design, remotely instructing other coworkers how to do it, while i was on vacation, and specificaly told them to use RCWL-0516 (because i've previously managed to modify the module for this purpose), but for some reason they've used some different design i've never saw before. But i liked the fact it is single sided (only groundplane on the backside, unlike the weird circles that RCWL-0516 has on backside), so i was happy with this and didn't cared to enquire for more information. I can't really find what module was originaly used exactly, because it's few years ago. I can't even find photos of similar module online.

willtmakinen78 commented 2 years ago

No problem, I'd agree that the additional simplcity is a big plus. I'll get an antenna fabbed up using your kicad design (after converting it to altium, my preferred pcb design software) and see how things go.

Harvie commented 1 year ago

Radar using ESP32 wifi peripheral https://www.youtube.com/watch?v=tFxKUzEDSdw

paddyrg commented 1 year ago

Radar using ESP32 wifi peripheral https://www.youtube.com/watch?v=tFxKUzEDSdw

Interesting! I looked at the link Espressif suggested https://www.espressif.com/en/company/newsroom/news in the comments for any news...nothing in the past year seems to mention esp-wifi-csi sadly, so we are still waiting :,-(

Cowh3adDK commented 1 year ago

image Hi after looking at this thread, and wanting to incorporate a "hidden" presence detector in a lightswitch i am working on, i started to try and reverse engineer the amplification part, and i am not having much success, my oscilloscope, can easily catch the voltage differences on the RCWL module itself, but when i try and build my own op-amp circuit nothing works, tried both the one provided by harvie, and 1 a little simpler. now im trying one based on the values of components from the RCWL schematic and saw that 2nd stage op-amp does not have a positive input, is what i have put in my image okay to use?

casesolved-co-uk commented 9 months ago

It looks to me like the components in the blue box are actually meant to be connected to the - input of the 2nd op-amp, and the + input is supposed to be to GND.

See inverting band pass filter circuit here: https://www.electronics-tutorials.ws/filter/filter_7.html

The blue box components bias the input voltage (by charging the capacitor) to keep it within the voltage range of the op-amp. The AC coupled signal doesn't have a DC bias otherwise.