Any one made use of pulse_in?
NumPy
Posts: 27
I have searched the PI/ Propeller threads with no luck.
Im still trying to get my feet wet, so be kind.:-)
I am trying to measure the freq on a tsl235r, and
in my newbie dreams, I was hoping it would be as simple
as:
/** * This is the main Measure freq program file.
*/
#include <propeller.h>
#include "simpletools.h"
int main(void)
{
int myfreq;
int pin1;
pin1=input(1);
myfreq=pulse_in(1,1);
printf("Frequency = %d",myfreq);
return 0;
}
Im still trying to get my feet wet, so be kind.:-)
I am trying to measure the freq on a tsl235r, and
in my newbie dreams, I was hoping it would be as simple
as:
/** * This is the main Measure freq program file.
*/
#include <propeller.h>
#include "simpletools.h"
int main(void)
{
int myfreq;
int pin1;
pin1=input(1);
myfreq=pulse_in(1,1);
printf("Frequency = %d",myfreq);
return 0;
}
Comments
So calculating the freq would be more involved that yhus. But all I get in debug
Is Frequency=0
Any ideas?
Do you know that there is a changing signal on pin 1 ?
The parallax scope shows a definite change when light is applied and removed.
The scope says max 200kHz and the sensor says 200 - 300kHz,
but for what its worth, this is the only evidence I have:
Pic one is very low light, pic 2 is an led flashlight shined in to the
sensor 2 inches away.
If you move the flashlight away slowly, there is a gradual positive
movement.
I was expecting to see square waves with this.
however, in my debug on the serial port window all I get is "1960" from:
pulse_duration=pulse_in(1,1); print("Pulse Duration: \%d \n"),pulse_duration;
no matter what the light intensity is.
I feel like I may not be using "pulse_in" correctly.
I have verified that I am using pin 1 by driving an led from the same pin on a quickstart board
with different led test code, so I feel confident that my connection from signal to pin 1 is valid.
I am scoping this while driving it and have tried without scoping it as well.
For some reason if I remove the comments for x, pulse_duration and x always are the same, and the
1960 value doesn't even appear.
I have ran this code while changing the amount of light stimulating the sensor and get no change
in the debug value pulse_duration.
This seems to be the big issue in your code.
Below is a demo of pulse in and pulse out on the same pin.
It is your code with some modifications.
Comment out the cogstart/printf lines if you just want to measure a pulse.
You only need "simpletools.h" in this program.
light intensity changes. I have no brain power left after getting your code changes
and testing them. I have experimented with changing the pause time some, to
get it more real time responsive, it seems to want to stick around 20 or so and
with very little change zooms off into the thousands and back down.
I must eventually get these number to conform, to be ruley.
Not complaining, I just want to understand this much more than I do and you have
given me the ability to do this. I will update as I learn more.
I will labor over this first thing in the am.
Ultimately, I will be in a black box with an led backlight watching an lcd
screen go silver or black, so it has to be sensitive.
I feel like I'm in the same boat as trying to take raw xyz axis data and
turn it into something usable now.
Thank You! Thank You!