X-Band Motion Detector (#32213)
pilot0315
Posts: 910
@Publison
Question for Publison have you seen this issue and do you have spin code that works.
Thanks Martin
@support
Does anyone have experience with this sensor. I am using the downloaded code for Spin on P1 on a wx board.
I have two of these modules. Both gives me what looks like the 3.9v indicating detected motion on my oscilloscope.
Code is intermittant it MAY start out saying detection then it sits dormant forever.
I have tried both boards. Also seeing a weird thing. The code prints out lines of "test good". This is not in the code.
Where does that come from? Themessage ends with Not detected.
Thank you in advance for the assist.
Martin
Comments
Hi Martin-
I'm saddened to report that it appears @Publison is no longer with us. He was seriously ill a couple years back, courageously fighting and steadfastly positive, but has not been seen since Jan 2023. I spent a lot of time scanning obits and local news, following up on all the connections I had, but to no avail; it's true we have no closure (no absolute certainty) on the matter, but it doesn't look like we'll meet again.
If your goal is to count positive edges during a specific window, this demo will show you how. The neat thing is that one counter module is setup as an oscillator and the other counter module us used to do the edge count -- no external hardware is required (though I did connect an LA to verify the output frequency)
This is what I get on PST
Since that motion detector just needs to be told when to output pulses, you can wrap that into a simple method (added to my demo). This is the same edge-reading code with an enable pin.
Finally...
That X-band object from Parallax is a mess and doesn't follow typical Propeller object rules.
I've written an X-Band motion detector object of it that is cleaner, easier to follow, works, and is written for the real world where CTRA might already be in use by an application. Note, the object sets the count pin to input mode, so if you want to do internal testing with the other counter, you must start the object first so that you can setup the other counter in NCO mode outputting to the desired pin. I tested this on a FLiP module using P26 as the test Enable pin so I could see its activity on the FLiP LED
I finally got the new ObEx to let me upload the correct code. You can find it here:
-- https://obex.parallax.com/obex/x-band-motion-detector-2/
-- last updated 5:45pm PDT, 17 JUL 2024
@VonSzarvas
I wish to thank you for the sad news. I as well, even though I did not know him or interact with him, hope that there was a positive outcome. Closure is important for all involved. I retired from the medical field several years ago and changed careeres. Navy Corpsman attached to the USMC as well as a nurse for many years. It is a sad business and I have seen way too much of that. Pain runs deep and affects me. So I understand. I can feel the respect that you have for @Publison.
I hope that others feel the same.
Martin
@JonnyMac
I have not worked with counters on the p1 in years. Cobwebs. Do you have a complete object that can jump start?
There is no generic object for the counter module (that I'm aware of) because it has so many modes (see table 2.7 in the P1 manual). The PEK book does a pretty good job of describing how the counters work with experiments.
Looking through my own objects I seem to use NCO mode the most; how it gets used is application-dependent. For example, I use it to generate servo pulses (form of PWM), standard PWM for DC motor control, and modulated output for transmitting IR signals. I work for a laser tag company and we used modulated IR packets. I have used DUTY mode in an audio project, POS- and NEG DETECT for pulse measurement, and even LOGIC ALWAYS as a free-running timer. In my DMX RX object I uses both counters in the cog in different modes: one is in NEG DETECT mode to measure the Break pulse, the other is in free-run mode to detect loss of signal.
It will take a bit of time, but I suggest you read the sections in the manual and the PEK on counters, and then look through the attached objects to see how I've put them into practice.
pilot0315,
The Propeller Education Kit (PEK) has a whole chapter on Counters.
https://www.parallax.com/package/propeller-education-kit-fundamentals-text-and-code/
https://www.parallax.com/package/an001-propeller-p8x32a-counters/
https://www.parallax.com/package/propeller-manual/
@JonnyMac
I ran into this:
https://www.parallax.com/download/propeller-1-documentation/
Had not seen this list before.
Reading this attached An001-p8x32ACounters... Document.
Studying it now. Appears to be what I have always wanted which is some documentation with indepth explanations and examples to play with so as to augment the learning process.
I will be tearing down your code and adding comments so as to see if I am understanding it. Will send it to you for further comment and tips. Simple tips please in Dummy language.
Thank you.
I am building a robot for an example as I am going to be a summer robot camp counseler at the local city college next summer. Unfortunately they will be using the Arduino but since it is in C++ for the Arduino I can port my brain over relatively easily. I have been away from the coding for over three years as major live changes occured. I now live in Northern Arizona having moved from Los Angeles. I am also looking for documents like in the list that I found for the P2. Does that exist?
I will get back to you soon, with questions. And how in the hell does one tell flexprop whether it is a P1 or P2?
As to your coment about NCO mode I am presently using the counter doc and my scope with a servo and writing a bunch of notes. Basically trying to rewrite the doc as I understand it.
Good catch on that old doc -- Parallax Semiconductor went away a long time ago so I forgot all about that stuff.
I write code the way I write code. Please do not repost modifications of my code with your style of commenting without removing my name or any reference to me. I don't want confusion over a [perceived] change in my style, nor credit for what you do. I am not of the opinion that programs are training documents -- that's what technical documents are for. You may see things differently. Great. Make your version available as there may be a market for that style.
Creating your own versions of my (and other) objects will go a long way in your understanding. In some cases I find using a logic analyzer a little easier, but having anything to record what's happening with pins useful.
The only time I open FlexProp is when I'm going to do a training session for Parallax and I want to ensure my code will work for those running Macs.
I just updated to the latest FlexProp and got my demo program working. Go into the Commands menu, select Configure Commands, and then select P1 Bytecode defaults. The program didn't work when compiled to assembly, but did when run as bytecodes (as in Propeller Tool) -- you may want to experiment (probably a timing thing).
Note: When using FlexProp you can comment out the call to wait_for_terminal(). If you don't you'll have to press Enter when you see the Entering terminal mode message.
@JonnyMac
Question.
Would you please explain the following in a simple way. I am not sure what is going on.
ctrb:=(%00100 << 26) | freq_pin
frqb := (%8000_0000 / ((clkfreq >> 1) / 10_000))
I understand that hte 00100 tels the counter what to do. In your code you shift left 26 places. On page 4 of the AN001 document it is shifted left 23. is that because the code on page 4 of the AN DOC has %00100_000 instead of %00100? Am I reading this correctly?
The freqb I understand is the clock cycle but can you give me an easy explanation of why there are say cycles of 1,2,3 and the pin values on apin are alternationg 1,0,1,0.
Thanks
Yes, you're correct. This is a style thing that the demo code in that document uses -- probably to be very explicit that the PLLDIV bits (25..23) are cleared.
The frqx register holds the value that gets added to phsx on every clock cycle. In NCO mode, bit 31 of phsx is output to the pin. If your frqx register was $8000_0000 then you would toggle the output pin every other cycle. $8000_0000 is 2^16. If phsx is $8000_0000 (output high) and you add $8000_0000 to it, you get $1_0000_0000 but with the registers being 32 bits, it gets truncated to $0000_0000 (output low).
Think of it this way: The bigger the value of frqx, the faster bit 31 of phsx will change -- which gives you a higher output frequency. Because of signed nature of Spin, $8000_0000 is the highest value you can add to phsx, above or below that will reduce the frequency.
The reason I use (clkfreq >> 1) in my setup is that $8000_0000 is 2^32 >> 1.
@JonnyMac
Since I am a novice again at this can I just use the values without the shifting?
If so could you give me a simple example with a more simple style. This is so I can get used to using the counter values an then get fancy later.
Thanks
Well, sure, if you want to make messy code -- I am against that. Since the mode occupies bits 30..26, you would have to do this without shifting.
It is criminal to subject others to this style. It can be improved a bit, but it's still atrocious and would not be used by professional coders.
So there it is, all spelled out, until an errant edit removes one of the zeroes and now your code doesn't work and it's hard to figure out why. The << 26 makes perfect sense when looking at the field layouts.
In my opinion, THIS is the simplest style, which is why I use it.
Shifting is an important part of programming and is useful in so many situations. Find a way to get comfortable with shifting.
@JonnyMac
The example makes sense. Counting zeros is a pain but looking at both shows that the shift is the easiest.
Thanks for the example.
I will play with it. May have more questions.
Martin