ClearCore Library
List of all members | Public Types | Public Member Functions
ClearCore::DigitalInOutHBridge Class Reference

Detailed Description

ClearCore H-Bridge digital output connector class.

This manages a connector on the ClearCore board that supports H-Bridge digital output functionality, including sine tone generation. This connector can also be configured as a digital input or digital output.

The following connector instances support H-Bridge digital output functionality:

For more detailed information on the ClearCore Connector interface, check out the ClearCore Connector System informational page.

Note
If overloaded, these connectors will need to be reset using the StatusManager::HBridgeReset function. This applies when running in H-bridge mode or digital input/output modes.

ClearCore H-Bridge digital output connector class. More...

#include <DigitalInOutHBridge.h>

+ Inheritance diagram for ClearCore::DigitalInOutHBridge:
+ Collaboration diagram for ClearCore::DigitalInOutHBridge:

Public Types

enum  ToneState {
  TONE_OFF = 0, TONE_CONTINUOUS, TONE_TIMED, TONE_PERIODIC_ON,
  TONE_PERIODIC_OFF
}
 Possible states of the tone generator. More...
 
- Public Types inherited from ClearCore::DigitalIn
enum  FilterUnits { FILTER_UNIT_MS, FILTER_UNIT_SAMPLES }
 Units for the digital filter length. More...
 
- Public Types inherited from ClearCore::Connector
enum  ConnectorModes {
  INVALID_NONE, INPUT_ANALOG, INPUT_DIGITAL, OUTPUT_ANALOG,
  OUTPUT_DIGITAL, OUTPUT_H_BRIDGE, OUTPUT_PWM, OUTPUT_TONE,
  OUTPUT_WAVE, CPM_MODE_A_DIRECT_B_DIRECT, CPM_MODE_STEP_AND_DIR, CPM_MODE_A_DIRECT_B_PWM,
  CPM_MODE_A_PWM_B_PWM, TTL, RS232, SPI,
  CCIO, USB_CDC
}
 All possible operational modes for a connector. More...
 
enum  ConnectorTypes {
  DIGITAL_IN_TYPE, DIGITAL_IN_OUT_TYPE, SHIFT_REG_TYPE, ANALOG_IN_DIGITAL_IN_TYPE,
  ANALOG_OUT_DIGITAL_IN_OUT_TYPE, H_BRIDGE_TYPE, CPM_TYPE, SERIAL_TYPE,
  SERIAL_USB_TYPE, CCIO_DIGITAL_IN_OUT_TYPE
}
 The different types of ClearCore connectors. More...
 

Public Member Functions

virtual ConnectorModes Mode () override
 Get the connector's operational mode. More...
 
bool Mode (ConnectorModes newMode) override
 Set the connector's operational mode. More...
 
Connector::ConnectorTypes Type () override
 Get connector type. More...
 
void ToneAmplitude (int16_t amplitude)
 Set the amplitude of a PWM output for tone generation. More...
 
void ToneContinuous (uint16_t frequency)
 Output a continuous tone from the H-Bridge. More...
 
void ToneTimed (uint16_t frequency, uint32_t duration, bool blocking=false, bool forceDuration=false)
 Output a tone from the H-Bridge for the specified duration. More...
 
void TonePeriodic (uint16_t frequency, uint32_t timeOn, uint32_t timeOff)
 Output a periodic tone from the H-Bridge. More...
 
void ToneStop ()
 
volatile const ToneStateToneActiveState ()
 Accessor for the state of the tone currently active on the H-Bridge. More...
 
int16_t State () override
 Get connector's last sampled value. More...
 
bool State (int16_t newState) override
 Set the state of the Connector. More...
 
bool IsWritable () override
 Get R/W status of the connector. More...
 
- Public Member Functions inherited from ClearCore::DigitalInOut
bool IsInHwFault () override
 Get whether the connector is in a hardware fault state. More...
 
void OutputPulsesStart (uint32_t onTime, uint32_t offTime, uint16_t pulseCount=0, bool blockUntilDone=false)
 Start an output pulse. More...
 
void OutputPulsesStop (bool stopImmediately=true)
 Stop an output pulse. More...
 
volatile const bool & OutputPulsesActive ()
 Check the output pulse state. More...
 
bool PwmDuty (uint8_t newDuty)
 Set the PWM duty on the I/O pin. More...
 
- Public Member Functions inherited from ClearCore::DigitalIn
void FilterLength (uint16_t length, FilterUnits units=FILTER_UNIT_SAMPLES)
 Set the connector's digital transition filter length. The default digital filter length for digital input connectors is 3 samples. More...
 
uint16_t FilterLength ()
 Get the connector's digital filter length in samples. The default is 3 samples. More...
 
bool InputRisen ()
 Clear on read accessor for this connector's rising input state. More...
 
bool InputFallen ()
 Clear on read accessor for this connector's falling input state. More...
 
bool InterruptHandlerSet (voidFuncPtr callback=nullptr, InputManager::InterruptTrigger trigger=InputManager::InterruptTrigger::RISING, bool enable=true)
 Register the interrupt service routine to be triggered when the given input state condition is met on this connector. More...
 
void InterruptEnable (bool enable)
 Enable or disable the interrupt on this connector. More...
 
- Public Member Functions inherited from ClearCore::Connector
void Reinitialize ()
 Reinitialize this connector to the power-up state. More...
 
int32_t ConnectorIndex ()
 Accessor for the bit index of this connector in the input register. More...
 
uint32_t InputRegMask ()
 Get a bit mask representing this connector. More...
 

Member Enumeration Documentation

Possible states of the tone generator.

Note
IO-4 and IO-5 each have their own tone generators, and are the only connectors capable of tone generation on the ClearCore.
Enumerator
TONE_OFF 

No tone is currently active.

TONE_CONTINUOUS 

A tone is playing indefinitely.

TONE_TIMED 

A tone is playing that will end after a specified duration.

TONE_PERIODIC_ON 

A periodic tone is playing and the tone is currently sounding (in the "on" phase of the tone output cycle).

TONE_PERIODIC_OFF 

A periodic tone is playing and the tone is currently silent (in the "off" phase of the tone output cycle).

Member Function Documentation

bool ClearCore::DigitalInOutHBridge::IsWritable ( )
overridevirtual

Get R/W status of the connector.

// IO-4 is in an output mode
}
Returns
True if in OUTPUT_DIGITAL, OUTPUT_PWM, OUTPUT_H_BRIDGE, OUTPUT_TONE, or OUTPUT_WAVE mode, false otherwise.

Reimplemented from ClearCore::DigitalInOut.

virtual ConnectorModes ClearCore::DigitalInOutHBridge::Mode ( )
inlineoverridevirtual

Get the connector's operational mode.

// IO-4 is currently a PWM output.
}
Returns
The connector's current operational mode.

Reimplemented from ClearCore::DigitalInOut.

Examples:
AnalogIOExamples/ReadAnalogInput/ReadAnalogInput.cpp, DigitalIOExamples/WriteDigitalOutput/WriteDigitalOutput.cpp, and SerialCommExamples/ClearCoreCommandProtocol/ClearCoreCommandProtocol.cpp.
bool ClearCore::DigitalInOutHBridge::Mode ( ConnectorModes  newMode)
overridevirtual

Set the connector's operational mode.

// Configure IO-4 for tone output
Parameters
[in]newModeThe new mode to be set. The valid modes for this connector type are:
Returns
Returns false if the mode is invalid or setup fails.
Note
If connector is in fault, attempts to set the mode will return false, but the mode that was commanded will be applied once the connector is no longer in a fault mode. Useful for getting out of a bad mode.

Reimplemented from ClearCore::DigitalInOut.

int16_t ClearCore::DigitalInOutHBridge::State ( )
overridevirtual

Get connector's last sampled value.

// In this example, IO-4 has been configured for digital input
// IO-4's input is currently high
}
// In this example, IO-4 has been configured for PWM output
if (ConnectorIO4.State() < UINT8_MAX / 4) {
// IO-4 is outputting PWM at a duty cycle less than 25%
}
// In this example, IO-4 has been configured for H-Bridge output
if (ConnectorIO4.State() < INT16_MIN / 2) {
// IO-4 is outputting differential PWM in the negative direction
// at a duty cycle greater than 50% (between -50% and -100%)
}
Returns
The latest sample

Reimplemented from ClearCore::DigitalInOut.

Examples:
AnalogIOExamples/ReadAnalogInput/ReadAnalogInput.cpp, and DigitalIOExamples/WriteDigitalOutput/WriteDigitalOutput.cpp.
bool ClearCore::DigitalInOutHBridge::State ( int16_t  newState)
overridevirtual

Set the state of the Connector.

// Assert IO-5's digital output
}
// Set IO-5's digital PWM output to 50% duty
// Valid range is 0 to UINT8_MAX
ConnectorIO5.State(UINT8_MAX / 2);
}
// Set IO-5's H-Bridge output to -25% duty
// Valid range is -INT16_MAX to INT16_MAX
ConnectorIO5.State(-INT16_MAX / 4);
}
Parameters
[in]newStateNew state to set for the connector.
Returns
success.

Reimplemented from ClearCore::DigitalInOut.

volatile const ToneState& ClearCore::DigitalInOutHBridge::ToneActiveState ( )
inline

Accessor for the state of the tone currently active on the H-Bridge.

// An endless tone is currently playing on IO-5
}
Returns
The type of tone currently playing
void ClearCore::DigitalInOutHBridge::ToneAmplitude ( int16_t  amplitude)

Set the amplitude of a PWM output for tone generation.

// Set IO-4's amplitude to 1/10 of the max
ConnectorIO4.ToneAmplitude(INT16_MAX / 10);
Parameters
[in]amplitudeThe amplitude of the tone (0 to INT16_MAX)
void ClearCore::DigitalInOutHBridge::ToneContinuous ( uint16_t  frequency)

Output a continuous tone from the H-Bridge.

// Start a continuous 100Hz tone on IO-4
Parameters
[in]frequencyThe frequency of the tone (Hz)
void ClearCore::DigitalInOutHBridge::TonePeriodic ( uint16_t  frequency,
uint32_t  timeOn,
uint32_t  timeOff 
)

Output a periodic tone from the H-Bridge.

// Start a 50Hz, 150ms on/25ms off tone on IO-4 that continues until
// stopped by a call to ToneStop().
ConnectorIO4.ToneTimed(50, 150, 25);
Parameters
[in]frequencyThe frequency of the tone (Hz)
[in]timeOnPeriodic on time (ms)
[in]timeOffPeriodic off time (ms)
void ClearCore::DigitalInOutHBridge::ToneStop ( )

Stop the tone output.

// Stop a tone playing on IO-4
void ClearCore::DigitalInOutHBridge::ToneTimed ( uint16_t  frequency,
uint32_t  duration,
bool  blocking = false,
bool  forceDuration = false 
)

Output a tone from the H-Bridge for the specified duration.

// Start a 50Hz, 500ms tone on IO-4 that does not block further code
// execution
Parameters
[in]frequencyThe frequency of the tone (Hz)
[in]durationHow long to play the tone (ms). Specifying a duration of 0 will result in a continuous tone (equivalent to calling ToneContinuous(uint16_t frequency) with the supplied frequency).
[in]blocking(optional) Sets whether the function will block all other operations until the tone has finished playing. Default: false.
[in]forceDuration(optional) If true, the tone will be made to sound for the full duration specified, regardless of any subsequent tone function calls made before the duration has elapsed. Default: false.
Note
Duration is only accurate to the SysTickRate.
The blocking and forceDuration parameters do not apply when duration = 0.
Connector::ConnectorTypes ClearCore::DigitalInOutHBridge::Type ( )
inlineoverridevirtual

Get connector type.

if (ConnectorAlias.Type() == Connector::H_BRIDGE_TYPE) {
// This generic connector variable is a DigitalInOutHBridge
// connector
}
Returns
The type of the current connector.

Reimplemented from ClearCore::DigitalInOut.


The documentation for this class was generated from the following file: