A version in C?
Jack3
Posts: 55
I need to read a square wave (from an RC receiver) and check for changes in state to 3 possible ranges and act accordingly.
Is there a function that does this already that I can include or modify for my needs that reads the pulse width? Simpliciy, this project is very simple.
I had asked this in a different way in the Propeller 1 threads,(http://forums.parallax.com/showthread.php/153533-Unsure-how-to-approach) but I am also looking for an answer in C, my education hasn't found the function yet.
Thanks
Is there a function that does this already that I can include or modify for my needs that reads the pulse width? Simpliciy, this project is very simple.
I had asked this in a different way in the Propeller 1 threads,(http://forums.parallax.com/showthread.php/153533-Unsure-how-to-approach) but I am also looking for an answer in C, my education hasn't found the function yet.
Thanks
Comments
The advantage, I suppose, is that the C version will a counter that is not busy doing something else. Still, I would hardly call this "simple" code....
libpropeller has a pulse width reader module in C++ if you're interested: https://github.com/libpropeller/libpropeller/tree/master/libpropeller/pulsewidthreader
I am assuming I have no idea what I am doing. So far, I got that just by adding a #include of the header file.....as below... Project Directory: C:/Users/Dad/Documents/SimpleIDE/LEDProj/LEDProj/
and it brings up the pulse_width_reader.h file with this first line highlighted.
This is using the Simple IDE to compile. Trying to back track from the compiler not being able to find the header file and was just putting in a line and doing a compile to look for the next error, got this far on the way back starting over from scratch.
Somehow I have a feeling I made no sense at all, so please ask for clarification.
I haven't heard of SRLM using libpropeller with SimpleIDE yet. I'd be happy to see it work, but I'm not sure if the combo is supported at this time - I haven't tested it. One thing is that libpropeller should be in a folder like Learn/Simple Libraries/libpropeller ... this is shown in GCC compiler properties tab.
Udate....Your help did get me past the error I was getting, now time to try it with some code.
Normally what I do is use a makefile, with the compile command set to:
In any case, the interesting bits are in the assembly driver. If this is purely a pedagogical exercise then you can browse that to see how the inputs are read.
@Jazzed
"Can libpropeller be used with SimpleIDE"? For objects that don't use an external .S file then yes. The easiest way is to just drop the .h files in the same folder as your source, and do the standard #include. You can also download the entire libpropeller folder to your computer and use the SimpleIDE "Add Include Path" to tell the compiler where to fulfill the #includes.
BTW, is there any plan to support .S files in SimpleIDE? I couldn't find anything on that except some old threads.
Also, I haven't forgotten about your request for a #include .cpp test. Just busy.
I read the S file, I know nothing about assembly, it was greek ...mostly ... to me
I find C so much easier to grasp than Spin. Why I have no idea it is much pickier, I think
There is a pulse reader in the "simpletools.h" header and library. Look for pulse_in() here.
There is no support for building with them at the moment that I know of, but it's not hard to add that sort of thing.
Actually if it's part of a pre-compiled library archive, it doesn't matter, because it's just another object to link. For example let's say you have a propeller library and header file ... library foo ....
Today, if you have a project where the main file has this ...
And the project, is called footest.side ....
As long as the Properties -> General -> Auto Include Simple Libraries box is checked, SimpleIDE will recursively look for a library called "libfoo" in Documents/SimpleIDE/Learn/Simple Libraries/*.
Once libfoo is found containing foo.h and cmm/libfoo.a, SimpleIDE will add everything needed to compile footest.c with the foo library assuming cmm mode. For lmm mode libfoo/lmm/libfoo.a should be found, etc....
There is no need to Add Include Path, etc... with Auto Include Simple Libraries checked.
Thanks.
I don't understand how to make the clock freq and mode work. I think I can work this out using waitpeq and waitpne if I can figure out clock stuff.
Could you give me some sample code to set the clock freq and mode with the propeller.h? This will need to be coded as the project is not going on a specific board, so generic profile and I don't know what clockspeed I would end up with.
@Jazzed....will look at pulse in too. Whichever is easier for me to grasp.
foovar = pulse_in(inputPin, mode);
Where mode is 0 for low sense, 1 for high sense mand foovar is pulsewidth. Beats the heck out of what it took in Spin. Wow. Piece of cake.
The Propeller.h file has a clkset instruction that simply writes the two registers that control that sort of thing. Like it says there you'll have to look in the manual: I've never tried using it.