Pulse Width Measurement in C

8 years 2 months ago #29530012 by beerbot
Having set an input to pulse mode (with the PC Utility or ^PMOD ?), I want to
then read the pulse width in my C program. RioReadPulseAnaInputs() is a "short."
How do I use that short as a pulse width measurement? Is it simply the width in microseconds?


Given that there is a millisecond or two delay in updating a pin's value, will the
pulse value be the width of the last pulse before the update, the average since the last update, or ...?

Please Log in or Create an account to join the conversation.

8 years 2 months ago #29530013 by TechSupport
What exactly is this "short" it is reading? Is it a 0uS reading or something else I am not aware of?

To read back the pulse input, you can send a query of ?pi.

?pi 1 should query back the Pulse input 1 value.

Please Log in or Create an account to join the conversation.

8 years 2 months ago #29530016 by beerbot
"short" is the C language data type that you define in the Datasheet C Library Functions for this read.

That is, you define the function RioReadPulseAnaInput() as a data type "short" (page 14, first function).

Since you don't use the modifier "unsigned," this means that the value returned by that function is a signed integer, likely 16 bits in size.

The question is, when the pin is set to "Pulse Input Mode" (^PMOD), what does the returned value represent?

For example, it could be the pulse width in microseconds or in Hz. Your "Power Stage Electrical Specifications" on page 9 of the Datasheet shows both duration and frequency values for pulse parameters.


I assume that when the pin is set to analog input mode the value represents the voltage in millivolts?

I want to use the C Library, not the console/basic commands, but the same question applies for ?pi 1. That is, what data is returned?

Please Log in or Create an account to join the conversation.

8 years 2 months ago - 8 years 2 months ago #29530017 by TechSupport
Thanks for clarifying. I don't have any knowledge of the C language programming.

^pmod means that you are changing the pulse mode parameter for an input. If you are broadcasting to all inputs on the pulse, then 0 is used.

To change a pulse/analog input 1 from analog raw to pulse raw, then it can be done via a serial command which is ^pmod 1 2.

If you were to query the actual state of pmod 1, you would send ~pmod 1.

I've attached a screenshot using Robonav.

I queries the pmod to see what the states were.

Then I changed input 1 to become pulse raw.

Then I queried again to see that the change took effect, where position 1 went from 0 to a 2.
Attachments:

Please Log in or Create an account to join the conversation.

Time to create page: 0.066 seconds