My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

digipot_mcp4451.cpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "Configuration.h"
  2. #if ENABLED(DIGIPOT_I2C)
  3. #include "Stream.h"
  4. #include "utility/twi.h"
  5. #include "Wire.h"
  6. // Settings for the I2C based DIGIPOT (MCP4451) on Azteeg X3 Pro
  7. #if MB(5DPRINT)
  8. #define DIGIPOT_I2C_FACTOR 117.96
  9. #define DIGIPOT_I2C_MAX_CURRENT 1.736
  10. #else
  11. #define DIGIPOT_I2C_FACTOR 106.7
  12. #define DIGIPOT_I2C_MAX_CURRENT 2.5
  13. #endif
  14. static byte current_to_wiper(float current) {
  15. return byte(ceil(float((DIGIPOT_I2C_FACTOR*current))));
  16. }
  17. static void i2c_send(byte addr, byte a, byte b) {
  18. Wire.beginTransmission(addr);
  19. Wire.write(a);
  20. Wire.write(b);
  21. Wire.endTransmission();
  22. }
  23. // This is for the MCP4451 I2C based digipot
  24. void digipot_i2c_set_current(int channel, float current) {
  25. current = min( (float) max( current, 0.0f ), DIGIPOT_I2C_MAX_CURRENT);
  26. // these addresses are specific to Azteeg X3 Pro, can be set to others,
  27. // In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1
  28. byte addr = 0x2C; // channel 0-3
  29. if (channel >= 4) {
  30. addr = 0x2E; // channel 4-7
  31. channel -= 4;
  32. }
  33. // Initial setup
  34. i2c_send(addr, 0x40, 0xff);
  35. i2c_send(addr, 0xA0, 0xff);
  36. // Set actual wiper value
  37. byte addresses[4] = { 0x00, 0x10, 0x60, 0x70 };
  38. i2c_send(addr, addresses[channel], current_to_wiper(current));
  39. }
  40. void digipot_i2c_init() {
  41. const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS;
  42. Wire.begin();
  43. // setup initial currents as defined in Configuration_adv.h
  44. for(int i = 0; i < COUNT(digipot_motor_current); i++) {
  45. digipot_i2c_set_current(i, digipot_motor_current[i]);
  46. }
  47. }
  48. #endif //DIGIPOT_I2C