mirror of https://github.com/Desuuuu/klipper.git
mcp4728: Add initial support for the mcp4728 i2c dac chip
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0da064ccd9
commit
c2086796bf
|
@ -639,6 +639,36 @@
|
||||||
# to not scale the 'wiper_x' parameters.
|
# to not scale the 'wiper_x' parameters.
|
||||||
|
|
||||||
|
|
||||||
|
# Statically configured MCP4728 digital-to-analog converter connected
|
||||||
|
# via I2C bus (one may define any number of sections with an "mcp4728"
|
||||||
|
# prefix).
|
||||||
|
#[mcp4728 my_dac]
|
||||||
|
#i2c_mcu: mcu
|
||||||
|
# The name of the micro-controller that the MCP4451 chip is
|
||||||
|
# connected to. The default is "mcu".
|
||||||
|
#i2c_address:
|
||||||
|
# The i2c address that the chip is using on the i2c bus. The default
|
||||||
|
# is zero.
|
||||||
|
#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.
|
||||||
|
#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.
|
||||||
|
|
||||||
|
|
||||||
# Configure an SX1509 I2C to GPIO expander. Due to the delay incurred
|
# Configure an SX1509 I2C to GPIO expander. Due to the delay incurred
|
||||||
# by I2C communication you should NOT use SX1509 pins as stepper enable,
|
# by I2C communication you should NOT use SX1509 pins as stepper enable,
|
||||||
# step or dir pins or any other pin that requires fast bit-banging. They
|
# step or dir pins or any other pin that requires fast bit-banging. They
|
||||||
|
|
|
@ -74,3 +74,11 @@ max_velocity: 300
|
||||||
max_accel: 3000
|
max_accel: 3000
|
||||||
max_z_velocity: 5
|
max_z_velocity: 5
|
||||||
max_z_accel: 100
|
max_z_accel: 100
|
||||||
|
|
||||||
|
# Use the following on a Printrboard RevF to control stepper current.
|
||||||
|
#[mcp4728 stepper_current_dac]
|
||||||
|
#scale: 2.327
|
||||||
|
#channel_a: 1.3 # Extruder
|
||||||
|
#channel_b: 1.1 # stepper_z
|
||||||
|
#channel_c: 1.1 # stepper_y
|
||||||
|
#channel_d: 1.1 # stepper_x
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# MCP4728 dac code
|
||||||
|
#
|
||||||
|
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
||||||
|
#
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
import bus
|
||||||
|
|
||||||
|
class mcp4728:
|
||||||
|
def __init__(self, config):
|
||||||
|
self.i2c = bus.MCU_I2C_from_config(config, default_addr=0)
|
||||||
|
scale = config.getfloat('scale', 1., above=0.)
|
||||||
|
# Configure registers
|
||||||
|
for i, name in enumerate('abcd'):
|
||||||
|
val = config.getfloat('channel_%s' % (name,), None,
|
||||||
|
minval=0., maxval=scale)
|
||||||
|
if val is not None:
|
||||||
|
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])
|
||||||
|
|
||||||
|
def load_config_prefix(config):
|
||||||
|
return mcp4728(config)
|
Loading…
Reference in New Issue