Serial Wombat
a general-purpose digital interface device for hobbyists, engineers and students

 


Home
Overview
Protocol
Documentation
Channel Modes
Direct Control
Controlled Pin
Raw A/D
A/D Averaging
A/D 1st Order Filtering
Matrix Keypad
Servo Control
Analog Direct
Analog Follow
Rotary Encoder
Debouncing
Counter
Hysteresis
Morse Code
Pulse
Unipolar Stepper
LCD Driver 1
LCD Driver 2
HW Pulse Meas.
2D Lookup
SPI Master
HD44780 Generic
Remote Control
DataLogger
Min-Max
Public Data
Timed IO
Getting Started
Connectivity
Pin Mode SDK Beta
Sample Projects
Downloads
Contact Us
Purchase
Forum

Did you know...

 

Serial Wombat Hardware Transition Measurement Channel Mode

A few pins on the Serial Wombat have special hardware assisted features capable of measuring the timing between high to low and low to high transitions. These pins can accurately count and time transitions occuring as often as every 15 microseconds, and as infrequently as every two seconds. This channel mode was designed with two primary goals in mind: allowing the measurement of periodic events such as a position sensor on a rotating wheel or shaft, and allowing the measurement of standard R/C Servo pulse inputs from a receiver or other source.

This channel mode is different from most other Serial Wombat channel modes in that it only works on a few specific pins: 16, 17, 33, 34, and 35. These pins have special hardware which allows interrupts to occur upon a pin state transition. When this happens, the Wombat will stop what it's doing, capture a new timestamp corresponding to the time of the transition, increment a counter for that pin, and return to its prior work. This allows the Wombat firmware to be sufficently responsive to inputs while still maintaining the round-robin style pin scheduling used by the Serial Wombat executive.

When the host enables the Hardware Transition Measurement Channel Mode for one of the eligible pins, a high priority interrupt is enabled inside the Wombat for that pin. Any time this input pin changes state, a small amount of interrupt code will be executed at a higher priority than other tasks in the system.

This presents a potential problem for the system. If pin transitions occur faster than the Wombat's CPU core can process the interrupt code, then the Wombat will spend 100% of its time trying to record these transitions. This results in a situation where the rest of the Wombat firmware, including the Serial Port receive software which could otherwise be used to turn off this mode is starved. In order to avoid this situation, the system design should not allow pin transitions on pins using Hardware Transition Measurement to occur more often than every 15 microseconds. This applies to the summation of all pins which are enabled in this mode. This is to say that if all 5 eligible pins are enabled, on average, only one pin should transition every 15 microseconds.

Future versions of the Serial Wombat will include a user-enabled watchdog function which will reset the Wombat if the communications code is not serviced within some period of time (likely 1 to 2 seconds). This will disable all channel modes and allow the host to regain control in the event of a starvation event.

Even if these conditions are met, it is possible that under some circumstances transition interrupts may consume enough of the Wombat's CPU time to cause other tasks to run slowly. It is recommended that a throughput analysis be performed under realistic usage conditions to determine if the Wombat has sufficient CPU power to perform all desired tasks. Documentation on how to use the Wombat's internal CPU usage monitoring will be available in the future.

For each of the 5 pins the Wombat keeps transition timestamps of the two most recent high-to-low and low-to-high transitions. This allows the Wombat to provide period/frequency information, and durations for high and low sections of a wave form. This can be used to accurately measure the frequency and duty cycle of an incoming PWM signal. Each of these four times is stored as a 24-bit number. Each 'tick' of the time represents 1/16 of the clock used by the Serial Wombat. Therefore, the 32Mhz internal clock would yield a time of 500 nanoseconds. The absolute value of these timestamps has no meaning. However, by comparing timestamps of events which happen within 2 seconds of each other, relative timing can be determined.

Additonally, a counter is kept for each pin which counts the total number of transitions for that pin. This is a 16 bit value which will wrap around from 65535 to 0. This counter can be used by the host to determine if new timing data is available, and can be used to determine the average number of transitions over a period of time.

The Hardware Transition Measurement function can provide one of a number of different outputs as it's public data:

Output Value Meaning
Low Time 0 The elapsed time between the latest high-to-low and low-to-high transition pair. Units are 1 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. Because the internal oscillator can vary by up to 1%, this value is only accurate to within 1%. If this value is longer than 65535 units, then 65535 units will be the public data.
High Time 1 The elapsed time between the latest low-to-high and high-to-low transition pair. Units are 1 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. Because the internal oscillator can vary by up to 1%, this value is only accurate to within 1%. If this value is longer than 65535 units, then 65535 units will be the public data.
Low Period 2 The elapsed time between the last two high-to-low transitions. Units are 1 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. Because the internal oscillator can vary by up to 1%, this value is only accurate to within 1%. If this value is longer than 65535 units, then 65535 units will be the public data.
High Period 3 The elapsed time between the last two low-to-high transitions. Units are 1 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. Because the internal oscillator can vary by up to 1%, this value is only accurate to within 1%. If this value is longer than 65535 units, then 65535 units will be the public data.
Low Time / 256 4 Same as 0 above, but with units of 256 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. This allows lower resolution timing but longer pulse durations. Durations of more than 2 seconds may cause internal mathematics overflows resulting in undefined behavior.
High Time / 256 5 Same as 1 above, but with units of 256 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. This allows lower resolution timing but longer pulse durations. Durations of more than 2 seconds may cause internal mathematics overflows resulting in undefined behavior.
Low Period / 256 6 Same as 2 above, but with units of 256 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. This allows lower resolution timing but longer pulse durations. Durations of more than 2 seconds may cause internal mathematics overflows resulting in undefined behavior.
High Period / 256 7 Same as 3 above, but with units of 256 / 2,000,000ths of a second when the 32Mhz internal oscillator is used. This allows lower resolution timing but longer pulse durations. Durations of more than 2 seconds may cause internal mathematics overflows resulting in undefined behavior.
Duty Cycle 8 Provides a value between 0 and 65535 representing the duty cycle of the input waveform. This value is updated only when a new transition comes in. Therefore, this duty cycle will not accurately represent 0% or 100% duty cycles, since they do not cause transitions.

 

 

Message format:

The first message is used to enable interrupts so that the special hardware on the selected pin can begin measuring transitions. This message also configures which aspect of the transition measurements is presented to the rest of the system as public data.

Data Sent to the Wombat: 200 Pin # 24 Public Data Output 0x55 0x55 0x55 0x55
Meaning: Configure Pin First message Pin Number to be set to HW Pulse measurement. Must be 16, 17, 33, 34, or 35 Hardware Transition Measurement Mode See table above for values and meanings Unused. Unused. Unused. Unused.
This message is echoed back by the Wombat.

 

The second message is used to retreive transition data. It is possible that the user may wish to retreive more than one set of data for a set of captured transitions. For this reason, the host can choose to suspend additional captures after the message is returned to the host. This allows, for example, the host to request both high and low times for the same set of 4 transitions, allowing a calculation of duty cycle. This is not possible if additional transtions are captured between requests. If the host is only interested in one piece of data, such as pulse high-time, then additional captures can be left enabled so that additional data is captured after the message is returned.

Data Sent to the Wombat: 201 Pin # 24 Requested data Continous Capture 0x55 0x55 0x55
Meaning: Configure Pin Second message Pin Number to be set to HW Pulse measurement. Must be 16, 17, 33, 34, or 35 Hardware transition measurement mode What Time Data is to be returned to the host:

0:Low Time
1: High Time
2: High-to-low Transition period
3: Low-to-high transition period

0: Stop capturing new transitions

1: Continue capturing new transitions

Unused Unused Unused.
Data Returned from the Wombat: 201 Pin # 24 Time Value MSB Time Value Middle Byte Time Value LSB Count MSB Count LSB
Meaning: Same as send Same as send Same as send This 24-bit value represents the time requested by the host. Units are 1 / 2,000,000 of a second when using the internal 32Mhz oscillator. Accuracy is +/- 1% due to variation in internal oscillator frequency. This 16-bit value is a running count of the number of transitions detected. This value can roll over from 65535 to 0 without notice.

 

 

Example:

 

Configure channel 16 to capture the high time of pulses. Then issue a command asking for the high time to be returned to the host, without pausing captures. Response will be for a high pulse of 0.7624 seconds, pulse number 4217

SEND to Wombat:
 200 16 24 1 0x55 0x55 0x55 0x55 ; Set pin 16 to Hardware Pulse Management mode,
                           ; Report high time as public data (1)
SEND to Wombat:
 201 16 24 1 1 0x55 0x55 0x55             ; Get High Time from Pin 16, don't pause
RESPONSE from Wombat:
201 16 24 0x17 0x44 0x40 0x10 0x79    ;  High time = 0x174440 = 1524800 = 2000000 * .7624
                                      ;  Count = 0x1079 = 4217

 


 

Copyright Wombat Interface Products, 2005-2008. All Rights Reserved.