hsk-libs-dev  270
High Speed Karlsruhe XC878 library collection
Macros | Typedefs | Functions
hsk_pwc.h File Reference

HSK Pulse Width Counter headers. More...

#include "../hsk_isr/hsk_isr.isr"
Include dependency graph for hsk_pwc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PWC_CC0   0
 Capture/Compare channel 0 on EXINT3. More...
 
#define PWC_CC1   1
 Capture/Compare channel 1 on EXINT4. More...
 
#define PWC_CC2   2
 Capture/Compare channel 2 on EXINT5. More...
 
#define PWC_CC3   3
 Capture/Compare channel 3 on EXINT6. More...
 
#define PWC_CC0_P30   0
 Capture/Compare channel 0 input port P3.0 configuration. More...
 
#define PWC_CC0_P40   1
 Capture/Compare channel 0 input port P4.0 configuration. More...
 
#define PWC_CC0_P55   2
 Capture/Compare channel 0 input port P5.5 configuration. More...
 
#define PWC_CC1_P32   3
 Capture/Compare channel 1 input port P3.2 configuration. More...
 
#define PWC_CC1_P41   4
 Capture/Compare channel 1 input port P4.1 configuration. More...
 
#define PWC_CC1_P56   5
 Capture/Compare channel 1 input port P5.6 configuration. More...
 
#define PWC_CC2_P33   6
 Capture/Compare channel 2 input port P3.3 configuration. More...
 
#define PWC_CC2_P44   7
 Capture/Compare channel 4 input port P4.4 configuration. More...
 
#define PWC_CC2_P52   8
 Capture/Compare channel 2 input port P5.2 configuration. More...
 
#define PWC_CC3_P34   9
 Capture/Compare channel 3 input port P3.4 configuration. More...
 
#define PWC_CC3_P45   10
 Capture/Compare channel 3 input port P4.5 configuration. More...
 
#define PWC_CC3_P57   11
 Capture/Compare channel 3 input port P5.7 configuration. More...
 
#define PWC_EDGE_FALLING   0
 Configuration selection to trigger pulse detection on falling edge. More...
 
#define PWC_EDGE_RISING   1
 Configuration selection to trigger pulse detection on rising edge. More...
 
#define PWC_EDGE_BOTH   2
 Configuration selection to trigger pulse detection on both edges. More...
 
#define PWC_MODE_EXT   1
 Available capture modes, capture on external interrupt. More...
 
#define PWC_MODE_SOFT   3
 Available capture modes, capture on sofware event. More...
 
#define PWC_UNIT_SUM_RAW   0
 Sum of buffered pulse widths in multiples of $ 1/48 * 10^{-6} s $. More...
 
#define PWC_UNIT_WIDTH_RAW   1
 Average of buffered pulse widths in multiples of $ 1/48 * 10^{-6} s $. More...
 
#define PWC_UNIT_WIDTH_NS   2
 Average of buffered pulse widths in multiples of $ 10^{-9} s $. More...
 
#define PWC_UNIT_WIDTH_US   3
 Average of buffered pulse widths in multiples of $ 10^{-6} s $. More...
 
#define PWC_UNIT_WIDTH_MS   4
 Average of buffered pulse widths in multiples of $ 10^{-3} s $. More...
 
#define PWC_UNIT_FREQ_S   5
 Average frequency of buffered pulses in multiples of $ 1/s $. More...
 
#define PWC_UNIT_FREQ_M   6
 Average frequency of buffered pulses in multiples of $ 1/m $. More...
 
#define PWC_UNIT_FREQ_H   7
 Average frequency of buffered pulses in multiples of $ 1/h $. More...
 
#define PWC_UNIT_DUTYH_RAW   8
 Latest high pulse in multiples of $ 1/48 * 10^{-6} s $. More...
 
#define PWC_UNIT_DUTYH_NS   9
 Latest high pulse in multiples of $ 1 * 10^{-9} s $. More...
 
#define PWC_UNIT_DUTYH_US   10
 Latest high pulse in multiples of $ 1 * 10^{-6} s $. More...
 
#define PWC_UNIT_DUTYH_MS   11
 Latest high pulse in multiples of $ 1 * 10^{-3} s $. More...
 
#define PWC_UNIT_DUTYL_RAW   12
 Latest low pulse in multiples of $ 1/48 * 10^{-6} s $. More...
 
#define PWC_UNIT_DUTYL_NS   13
 Latest low pulse in multiples of $ 1 * 10^{-9} s $. More...
 
#define PWC_UNIT_DUTYL_US   14
 Latest low pulse in multiples of $ 1 * 10^{-6} s $. More...
 
#define PWC_UNIT_DUTYL_MS   15
 Latest low pulse in multiples of $ 1 * 10^{-3} s $. More...
 

Typedefs

typedef ubyte hsk_pwc_channel
 Typedef for PWC channel IDs. More...
 
typedef ubyte hsk_pwc_port
 Typedef for PWC input port. More...
 

Functions

void hsk_pwc_init (ulong window)
 This function initializes the T2CCU Capture/Compare Unit for capture mode. More...
 
void hsk_pwc_channel_open (const hsk_pwc_channel channel, ubyte averageOver)
 Configures a PWC channel without an input port. More...
 
void hsk_pwc_port_open (const hsk_pwc_port port, ubyte averageOver)
 Opens an input port and the connected channel. More...
 
void hsk_pwc_channel_close (const hsk_pwc_channel channel)
 Close a PWC channel. More...
 
void hsk_pwc_channel_edgeMode (const hsk_pwc_channel channel, const ubyte edgeMode)
 Select the edge that is used to detect a pulse. More...
 
void hsk_pwc_channel_captureMode (const hsk_pwc_channel channel, const ubyte captureMode)
 Allows switching between external and soft trigger. More...
 
void hsk_pwc_channel_trigger (const hsk_pwc_channel channel)
 Triggers a channel in soft trigger mode. More...
 
void hsk_pwc_enable (void)
 Enables T2CCU module if disabled. More...
 
void hsk_pwc_disable (void)
 Turns off the T2CCU clock to preserve power. More...
 
ulong hsk_pwc_channel_getValue (const hsk_pwc_channel channel, const ubyte unit)
 Returns a measure of the values in a channel buffer. More...
 

Detailed Description

HSK Pulse Width Counter headers.

This library uses the T2CCU to measure pulse width on the external interrupt pins.

Every caputre channel blocks an external interrupt. Opening a channel will block this interrupt and change its configuration.

Pulse with measurement has a window time that is configured with hsk_pwc_init() and defines the time frame within which pulses can be detected.

If no pulse occurs during the window, the channel buffer is invalidated and the hsk_pwc_channel_getValue() function will returns invalid (0) until the buffer is repopulated with valid measurements.

In order to guarantee the detection of invalid channels, the hsk_pwc_channel_getValue() function has to be called at least once every 256 window times.

Author
kami

Macro Definition Documentation

§ PWC_CC0

#define PWC_CC0   0

Capture/Compare channel 0 on EXINT3.

§ PWC_CC0_P30

#define PWC_CC0_P30   0

Capture/Compare channel 0 input port P3.0 configuration.

§ PWC_CC0_P40

#define PWC_CC0_P40   1

Capture/Compare channel 0 input port P4.0 configuration.

§ PWC_CC0_P55

#define PWC_CC0_P55   2

Capture/Compare channel 0 input port P5.5 configuration.

§ PWC_CC1

#define PWC_CC1   1

Capture/Compare channel 1 on EXINT4.

§ PWC_CC1_P32

#define PWC_CC1_P32   3

Capture/Compare channel 1 input port P3.2 configuration.

§ PWC_CC1_P41

#define PWC_CC1_P41   4

Capture/Compare channel 1 input port P4.1 configuration.

§ PWC_CC1_P56

#define PWC_CC1_P56   5

Capture/Compare channel 1 input port P5.6 configuration.

§ PWC_CC2

#define PWC_CC2   2

Capture/Compare channel 2 on EXINT5.

§ PWC_CC2_P33

#define PWC_CC2_P33   6

Capture/Compare channel 2 input port P3.3 configuration.

§ PWC_CC2_P44

#define PWC_CC2_P44   7

Capture/Compare channel 4 input port P4.4 configuration.

§ PWC_CC2_P52

#define PWC_CC2_P52   8

Capture/Compare channel 2 input port P5.2 configuration.

§ PWC_CC3

#define PWC_CC3   3

Capture/Compare channel 3 on EXINT6.

§ PWC_CC3_P34

#define PWC_CC3_P34   9

Capture/Compare channel 3 input port P3.4 configuration.

§ PWC_CC3_P45

#define PWC_CC3_P45   10

Capture/Compare channel 3 input port P4.5 configuration.

§ PWC_CC3_P57

#define PWC_CC3_P57   11

Capture/Compare channel 3 input port P5.7 configuration.

§ PWC_EDGE_BOTH

#define PWC_EDGE_BOTH   2

Configuration selection to trigger pulse detection on both edges.

§ PWC_EDGE_FALLING

#define PWC_EDGE_FALLING   0

Configuration selection to trigger pulse detection on falling edge.

§ PWC_EDGE_RISING

#define PWC_EDGE_RISING   1

Configuration selection to trigger pulse detection on rising edge.

§ PWC_MODE_EXT

#define PWC_MODE_EXT   1

Available capture modes, capture on external interrupt.

§ PWC_MODE_SOFT

#define PWC_MODE_SOFT   3

Available capture modes, capture on sofware event.

Typedef Documentation

§ hsk_pwc_channel

typedef ubyte hsk_pwc_channel

Typedef for PWC channel IDs.

§ hsk_pwc_port

typedef ubyte hsk_pwc_port

Typedef for PWC input port.

Function Documentation

§ hsk_pwc_channel_captureMode()

void hsk_pwc_channel_captureMode ( const hsk_pwc_channel  channel,
const ubyte  captureMode 
)

Allows switching between external and soft trigger.

This does not reconfigure the input ports. Available modes are specified in the PWC_MODE_* defines. PWC_MODE_EXT is the default.

Parameters
channelThe channel to configure.
captureModeThe mode to set the channel to.

§ hsk_pwc_channel_close()

void hsk_pwc_channel_close ( const hsk_pwc_channel  channel)

Close a PWC channel.

Parameters
channelThe channel to close.

§ hsk_pwc_channel_edgeMode()

void hsk_pwc_channel_edgeMode ( const hsk_pwc_channel  channel,
const ubyte  edgeMode 
)

Select the edge that is used to detect a pulse.

Available edges are specified in the PWC_EDGE_* defines.

Parameters
channelThe channel to configure the edge for.
edgeModeThe selected edge detection mode.

§ hsk_pwc_channel_getValue()

ulong hsk_pwc_channel_getValue ( const hsk_pwc_channel  channel,
const ubyte  unit 
)

Returns a measure of the values in a channel buffer.

It also takes care of invalidating channels that haven't been captured for too long.

The value is returned in a requested unit, the units defined as PWC_UNIT_* are available.

Parameters
channelThe channel to return the buffer sum of
unit' The unit to return the channel value in
Return values
>0The channel value in the requested unit
0Invalid channel, measurement timed out

§ hsk_pwc_channel_open()

void hsk_pwc_channel_open ( const hsk_pwc_channel  channel,
ubyte  averageOver 
)

Configures a PWC channel without an input port.

The channel is set up for software triggering (PWC_MODE_SOFT), and triggering on both edges (PWC_EDGE_BOTH).

Parameters
channelThe PWC channel to open
averageOverThe number of pulse values to average over when returning a value or speed. The value must be between 1 and 8.

Set the PWC capture mode.

Set the interrupt triggering edge.

Here is the call graph for this function:

§ hsk_pwc_channel_trigger()

void hsk_pwc_channel_trigger ( const hsk_pwc_channel  channel)

Triggers a channel in soft trigger mode.

Parameters
channelThe channel to trigger.
Here is the call graph for this function:

§ hsk_pwc_disable()

void hsk_pwc_disable ( void  )

Turns off the T2CCU clock to preserve power.

§ hsk_pwc_enable()

void hsk_pwc_enable ( void  )

Enables T2CCU module if disabled.

§ hsk_pwc_init()

void hsk_pwc_init ( ulong  window)

This function initializes the T2CCU Capture/Compare Unit for capture mode.

The capturing is based on the CCT timer. Timer T2 is not used and thus can be useed without interference.

The window time is the time frame within which pulses should be detected. A smaller time frame results in higher precission, but detection of longer pulses will fail.

Window times vary between ~1ms ( $(2^{16} - 1) / (48 * 10^6)$) and ~5592ms ( $(2^{16} - 1) * 2^{12} / (48 * 10^6)$). The shortest window time delivers ~20ns and the longest time ~85µs precision.

The real window time is on a logarithmic scale (base 2), the init function will select the lowest scale that guarantees the required window time. I.e. the highest precision possible with the desired window time, which is at least $2^{15}$ for all windows below or equal 5592ms.

Parameters
windowThe time in ms to detect a pulse.
Here is the call graph for this function:

§ hsk_pwc_port_open()

void hsk_pwc_port_open ( const hsk_pwc_port  port,
ubyte  averageOver 
)

Opens an input port and the connected channel.

The available configurations are available from the PWC_CCn_* defines.

Parameters
portThe input port to open
averageOverThe number of pulse values to average over when returning a value or speed. The value must be between 1 and CHAN_BUF_SIZE
Here is the call graph for this function: