mcp4728: Update to better match printrbot revf requirements

Reported by @Grumps49.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-07-26 10:59:07 -04:00
parent 73709984b0
commit a878831d5e
3 changed files with 15 additions and 10 deletions

View File

@ -890,27 +890,28 @@
#i2c_mcu: mcu #i2c_mcu: mcu
# The name of the micro-controller that the MCP4451 chip is # The name of the micro-controller that the MCP4451 chip is
# connected to. The default is "mcu". # connected to. The default is "mcu".
#i2c_address: #i2c_address: 96
# The i2c address that the chip is using on the i2c bus. The default # The i2c address that the chip is using on the i2c bus. The default
# is zero. # is 96.
#channel_a: #channel_a:
#channel_b: #channel_b:
#channel_c: #channel_c:
#channel_d: #channel_d:
# The value to statically set the given MCP4728 channel to. This is # The value to statically set the given MCP4728 channel to. This is
# typically set to a number between 0.0 and 1.0 with 1.0 being the # typically set to a number between 0.0 and 1.0 with 1.0 being the
# highest voltage and 0.0 being the lowest voltage. However, the # highest voltage (2.048V) and 0.0 being the lowest voltage. However,
# range may be changed with the 'scale' parameter (see below). If a # the range may be changed with the 'scale' parameter (see
# channel is not specified then it is left unconfigured. # below). If a channel is not specified then it is left
# unconfigured.
#scale: #scale:
# This parameter can be used to alter how the 'channel_x' parameters # This parameter can be used to alter how the 'channel_x' parameters
# are interpreted. If provided, then the 'channel_x' parameters # are interpreted. If provided, then the 'channel_x' parameters
# should be between 0.0 and 'scale'. This may be useful when the # should be between 0.0 and 'scale'. This may be useful when the
# MCP4728 is used to set stepper voltage references. The 'scale' can # MCP4728 is used to set stepper voltage references. The 'scale' can
# be set to the equivalent stepper amperage if the MCP4728 were at # be set to the equivalent stepper amperage if the MCP4728 were at
# its highest voltage, and then the 'channel_x' parameters can be # its highest voltage (2.048V), and then the 'channel_x' parameters
# specified using the desired amperage value for the stepper. The # can be specified using the desired amperage value for the
# default is to not scale the 'channel_x' parameters. # stepper. The default is to not scale the 'channel_x' parameters.
# Statically configured MCP4018 digipot connected via two gpio "bit # Statically configured MCP4018 digipot connected via two gpio "bit

View File

@ -6,6 +6,10 @@ All dates in this document are approximate.
# Changes # Changes
20190726: The mcp4728 digital-to-analog code has changed. The default
i2c_address is now 0x60 and the voltage reference is now relative to
the mcp4728's internal 2.048 volt reference.
20190710: The z_hop option was removed from the [firmware_retract] 20190710: The z_hop option was removed from the [firmware_retract]
config section. The z_hop support was incomplete and could cause config section. The z_hop support was incomplete and could cause
incorrect behavior with several common slicers. incorrect behavior with several common slicers.

View File

@ -7,7 +7,7 @@ import bus
class mcp4728: class mcp4728:
def __init__(self, config): def __init__(self, config):
self.i2c = bus.MCU_I2C_from_config(config, default_addr=0) self.i2c = bus.MCU_I2C_from_config(config, default_addr=0x60)
scale = config.getfloat('scale', 1., above=0.) scale = config.getfloat('scale', 1., above=0.)
# Configure registers # Configure registers
for i, name in enumerate('abcd'): for i, name in enumerate('abcd'):
@ -17,7 +17,7 @@ class mcp4728:
self.set_dac(i, int(val * 4095. / scale + .5)) self.set_dac(i, int(val * 4095. / scale + .5))
def set_dac(self, dac, value): def set_dac(self, dac, value):
self.i2c.i2c_write([0x40 | (dac << 1), self.i2c.i2c_write([0x40 | (dac << 1),
(value >> 8) & 0x0f, value & 0xff]) ((value >> 8) & 0x0f) | 0x80, value & 0xff])
def load_config_prefix(config): def load_config_prefix(config):
return mcp4728(config) return mcp4728(config)