Shop OBEX P1 Docs P2 Docs Learn Events
Pulsin Command — Parallax Forums

Pulsin Command

ArchiverArchiver Posts: 46,084
edited 2000-05-26 00:43 in General Discussion
Following is a sample from my code using the Pulsin command:
(Code Starts Here)
.
.
.

p1 var byte
p2 var byte
.
.
.
tempcheck:
pulsin 5,1,p1
pulsin 5,0,p2
tz1 = 455 - ((720*p1)/p2)
pause 1500
.
.
.

Here is my problem. I am measuring the a pulse comming from a TMP04
Temp. Sensor When I read the High portion (BINARY one(1)) pulse and
the Low Portion (BIN zero(0)) pulse, P1 and P2 always read ZERO (0)
when i display on my LCD or using the debug command.

The lenth of the pulse's at roome temp are as follows
p1 => 18.2ms
p2 => 15.7ms

Can the stamp not read this small of a number or am I doing somthing
wrong?

THanks in advance.

Tobin Moore.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-05-25 19:54
    Tobin,

    Try making yours variables words instead of bytes.

    I don't believe you can represent milliseconds
    with just 8-bit variables.

    Also I would watch for how my math was done to
    avoid a division by zero problem.

    Hope this helps,
    Bob

    At 06:32 PM 5/25/00 -0000, you wrote:
    >Following is a sample from my code using the Pulsin command:
    >(Code Starts Here)
    >.
    >.
    >.
    >
    >p1 var byte
    >p2 var byte
    >.
    >.
    >.
    >tempcheck:
    > pulsin 5,1,p1
    > pulsin 5,0,p2
    > tz1 = 455 - ((720*p1)/p2)
    > pause 1500
    >.
    >.
    >.
    >
    >Here is my problem. I am measuring the a pulse comming from a TMP04
    >Temp. Sensor When I read the High portion (BINARY one(1)) pulse and
    >the Low Portion (BIN zero(0)) pulse, P1 and P2 always read ZERO (0)
    >when i display on my LCD or using the debug command.
    >
    >The lenth of the pulse's at roome temp are as follows
    >p1 => 18.2ms
    >p2 => 15.7ms
    >
    >Can the stamp not read this small of a number or am I doing somthing
    >wrong?
    >
    >THanks in advance.
    >
    >Tobin Moore.
    >
    >
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-25 20:05
    Tobin:

    The Pulsin command measures time in 2 microsec intervals. This results in a
    byte var only good to 510 microsecs: beyond that you get overflow with the
    lower 8 bits being 0. Use var word, and you should be good to 0.131 secs.

    Good luck,
    Ray McArthur

    Original Message
    From: <ttm@g...>
    To: <basicstamps@egroups.com>
    Sent: Thursday, May 25, 2000 2:32 PM
    Subject: [noparse][[/noparse]basicstamps] Pulsin Command


    > Following is a sample from my code using the Pulsin command:
    > (Code Starts Here)
    > .
    > .
    > .
    >
    > p1 var byte
    > p2 var byte
    > .
    > .
    > .
    > tempcheck:
    > pulsin 5,1,p1
    > pulsin 5,0,p2
    > tz1 = 455 - ((720*p1)/p2)
    > pause 1500
    > .
    > .
    > .
    >
    > Here is my problem. I am measuring the a pulse comming from a TMP04
    > Temp. Sensor When I read the High portion (BINARY one(1)) pulse and
    > the Low Portion (BIN zero(0)) pulse, P1 and P2 always read ZERO (0)
    > when i display on my LCD or using the debug command.
    >
    > The lenth of the pulse's at roome temp are as follows
    > p1 => 18.2ms
    > p2 => 15.7ms
    >
    > Can the stamp not read this small of a number or am I doing somthing
    > wrong?
    >
    > THanks in advance.
    >
    > Tobin Moore.
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-26 00:43
    Hi Tobin,

    Yes, as Ray & Bob suggested, redefine p1 and p2 as word variables. But I
    think there is some other problem. Is the sensor hooked up to P5 (physical
    pin 10 on the module?) The BS2 pulsin command returns a value of zero when
    it does not detect a pulse within 65535*2 microseconds (=0.131070 seconds).
    The expected values of 18.2 and 15.7 milliseconds are well within that
    limit. That is why I wonder if it is really hooked to the pin. I surmise
    that the pulses are verified by looking at an oscilloscope? Also, are you
    sure your LCD code is okay?

    Once you do have the pulses, the math is bad. Yes, it is straight out of
    the TMP04 data sheet, however, integer math on the Stamp requires that you
    keep in mind the limit of 16 bits on word variables. An 18.2 millisecond
    pulse gives a count value of p1=9100. When the program calculates 720*9100
    will erroneously come up with 63936, which is the mod 2^16 remainder of the
    right answer of 6552000. Divide that by p2, and you see strange results.
    (Though that does not explain the zero results you are getting.) Post
    another message if you need some help on the integer math.

    regards,
    -- Tracy Allen
    Electronically Monitored Ecosystems
    http://www.emesystems.com



    >p1 var byte
    >p2 var byte
    >tempcheck:
    > pulsin 5,1,p1
    > pulsin 5,0,p2
    > tz1 = 455 - ((720*p1)/p2)
    > pause 1500
    >.
    >Here is my problem. I am measuring the a pulse comming from a TMP04
    >Temp. Sensor When I read the High portion (BINARY one(1)) pulse and
    >the Low Portion (BIN zero(0)) pulse, P1 and P2 always read ZERO (0)
    >when i display on my LCD or using the debug command.
    >The lenth of the pulse's at roome temp are as follows
    >p1 => 18.2ms
    >p2 => 15.7ms
    >Can the stamp not read this small of a number or am I doing somthing
    >wrong?
    >THanks in advance.
    >Tobin Moore.
Sign In or Register to comment.