NCV7240 Module

This module contains the Zerynth driver for the OnSemi NCV7240 automotive eight channel low-side/relay driver, that can be controlled with a standard SPI interface or parallel input pins.

Each output driver is protected for over load current and includes an output clamp for inductive loads. Open load or shorts to ground can be detected when the driver is in the off state.

class NCV7240

The NCV7240 class implements several methods to access the I/O expander over an SPI bus and easily control its features.

Each one of the 8 channels can be configured in one of 4 modes:

  • Standby (default) - the channel is disabled
  • On - the output driver is active (low), with over-load fault detection
  • Off - the output driver is inactive, with open-load fault detection
  • Input - the output driver on/off state is controlled by input pins (PWM capable)
Note:Faults are latched and must be cleared by switching the channel to Standby mode to attempt recovery.
Note:Off mode and open-load detection can be used as way to read channels as digital inputs.
__init__(spidrv, cs, clk=500000)

Creates an instance of NCV7240 class, using the specified SPI settings.

Parameters:
  • spidrv – the SPI driver to use (SPI0, ...)
  • cs – Chip select pin to access the NCV7240 chip
  • clk – Clock speed, default 500 kHz
Note:

SPI mode is fixed by the slave chip protocol (CPOL=0,CPHA=1)

setChannel(channel, mode)

Set one channel to the specified mode.

Parameters:
  • channel – Index of the channel (0-7)
  • mode – One of the four possible modes: CH_STANDBY, CH_ON, CH_OFF, CH_INPUT
setAllChannels(mode)

Set all channels to the specified mode.

Parameters:mode – One of the four possible modes: CH_STANDBY, CH_ON, CH_OFF, CH_INPUT
Note:If mode is a list or a tuple, each element specifies the corresponding channel mode
getChannel(channel)

Get the status of the specified channel.

Parameters:channel – Index of the channel (0-7)
Returns:One of the two possible states: CH_OPEN, CH_FAULT
Note:Put the channel in Standby mode to clear status.
getAllChannels()

Get the status of all channels.

Returns:A tuple where each element specifies the corresponding channel state: CH_OPEN or CH_FAULT
Note:Put the channel in Standby mode to clear status.
channelInputMode(channel)

Set the specified channel to input mode (output driver state is controlled directly by the corresponding input pin on the NCV7240 chip).

Parameters:channel – Index of the channel (0-7)
channelStandby(channel)

Set the specified channel to standby mode (output driver and fault detection are disabled, fault status cleared).

Parameters:channel – Index of the channel (0-7)
channelOn(channel)

Switch the specified channel output driver on (polarity active-low, over-load/over-temperature fault detection is active).

Parameters:channel – Index of the channel (0-7)
channelOff(channel)

Switch the specified channel output driver off (open-load fault detection current is active).

Parameters:channel – Index of the channel (0-7)
isChannelOpen(channel)

Returns whether the channel status indicates an open-load fault (only meaningful when the channel is off).

Parameters:channel – Index of the channel (0-7)
Note:Put the channel in Standby mode to clear fault status.
isChannelFault(channel)

Returns whether the channel status indicates an over-current/over-temperature fault (only meaningful when the channel is on).

Parameters:channel – Index of the channel (0-7)
Note:Put the channel in Standby mode to clear fault status.