Hi,
The simplest way is probably LocalTimeMicroC, e.g.:
uint32_t time;
atomic{ //you don't want interrupts to mess up with the timing
call samplePin.makeOutput(); //make the pin an output
call samplePin.set(); //start ranging
call delay.wait (5); //for 5 micro seconds
call samplePin.clr(); //you probably need this as well
call samplePin.makeInput(); // make the pin an input
while ( !(call simplePin.get()) ) ; //wait for the sensor to pull the
data line high
time = call LocalTimeMicro.get();
while ( call simplePin.get() ) ; //wait for the sensor to pull the data
line low
time = call LocalTimeMicro.get() - time;
}
printf("%d\n", time);
I'm not a 100% sure that you need the pin.clr, but on avrs, set() and
makeInput() means turned on pull-up resistors. I don't know about telos,
but it's seems safer,
The code above might have some issues, I just typed in this mail, never
even compiled it.
And it has a couple us error, but that depends on the accuracy of
localtimemicro and the instruction timing of the mcu. It would be nicer
with input capture interrupts (which saves a timestamp when the inturrput
event occures), but I have no idea how they work on telosb.
best,
Andris
On Sat, Jan 24, 2015 at 1:54 PM, Bello Kontagora <[email protected]>
wrote:
> Hi everyone, please can anyone help me out? I want to get the duration of
> an echo pulse through gpio/input pin. I interfaced PING ultrasonic range
> finder with XM1000(TelosB) through GPIO pin. the sensor requires a pulse of
> 5micro seconds to trigger it, it then returns an echo whose duration I
> needed. below is my code section: thank you in advance.
>
> (PingingP.nc)
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *module PingingP @safe() { uses { interface Boot;
> interface Leds; interface HplMsp430GeneralIO as
> samplePin; interface BusyWait<TMicro, uint16_t> as delay;
> interface Timer<TMilli> as Timer; }} implementation {
> uint16_t Time; event void Boot.booted() { call
> Timer.startPeriodic(2000);} event void Timer.fired () { call
> Leds.led1Toggle(); call samplePin.makeOutput(); //make the pin an
> output call samplePin.set(); //start ranging call delay.wait
> (5); //for 5 micro seconds call samplePin.makeInput(); // make the
> pin an input Time = call samplePin.get(); //this is where am
> confused, how to get the duration of the echo pulse and print it?
> printf("Time is %d\n", Time); }}*
>
> (PingingC.nc)
> #include <Timer.h>
>
> configuration BuzzerC {
> }
> implementation {
> components MainC, BuzzerP as App, LedsC;
> MainC.Boot <- App;
> App.indication3 -> HplMsp430GeneralIOC.Port26; //pin4 of the 6
> pins expansion
> App.Leds -> LedsC;
> components HplMsp430GeneralIOC;
> components BusyWaitMicroC;
> App.delay -> BusyWaitMicroC;
> components SerialPrintfC;
>
> components new TimerMilliC() as Timer;
> App.Timer -> Timer;
>
> }
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help