From a878831d5ea8eb86a1bcd94a6a2da926a84d5b6a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 26 Jul 2019 10:59:07 -0400 Subject: [PATCH] mcp4728: Update to better match printrbot revf requirements Reported by @Grumps49. Signed-off-by: Kevin O'Connor --- config/example-extras.cfg | 17 +++++++++-------- docs/Config_Changes.md | 4 ++++ klippy/extras/mcp4728.py | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config/example-extras.cfg b/config/example-extras.cfg index 53321aef..f7deeb61 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -890,27 +890,28 @@ #i2c_mcu: mcu # The name of the micro-controller that the MCP4451 chip is # 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 -# is zero. +# is 96. #channel_a: #channel_b: #channel_c: #channel_d: # 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 -# highest voltage and 0.0 being the lowest voltage. However, the -# range may be changed with the 'scale' parameter (see below). If a -# channel is not specified then it is left unconfigured. +# highest voltage (2.048V) and 0.0 being the lowest voltage. However, +# the range may be changed with the 'scale' parameter (see +# below). If a channel is not specified then it is left +# unconfigured. #scale: # This parameter can be used to alter how 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 # MCP4728 is used to set stepper voltage references. The 'scale' can # be set to the equivalent stepper amperage if the MCP4728 were at -# its highest voltage, and then the 'channel_x' parameters can be -# specified using the desired amperage value for the stepper. The -# default is to not scale the 'channel_x' parameters. +# its highest voltage (2.048V), and then the 'channel_x' parameters +# can be specified using the desired amperage value for the +# stepper. The default is to not scale the 'channel_x' parameters. # Statically configured MCP4018 digipot connected via two gpio "bit diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index 3844b3b3..979b0967 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -6,6 +6,10 @@ All dates in this document are approximate. # 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] config section. The z_hop support was incomplete and could cause incorrect behavior with several common slicers. diff --git a/klippy/extras/mcp4728.py b/klippy/extras/mcp4728.py index 6f2eeb29..eb1c3904 100644 --- a/klippy/extras/mcp4728.py +++ b/klippy/extras/mcp4728.py @@ -7,7 +7,7 @@ import bus class mcp4728: 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.) # Configure registers for i, name in enumerate('abcd'): @@ -17,7 +17,7 @@ class mcp4728: self.set_dac(i, int(val * 4095. / scale + .5)) def set_dac(self, dac, value): self.i2c.i2c_write([0x40 | (dac << 1), - (value >> 8) & 0x0f, value & 0xff]) + ((value >> 8) & 0x0f) | 0x80, value & 0xff]) def load_config_prefix(config): return mcp4728(config)