StepperII
Dual Axis Stepper Controller

CCurrentLimit.h

00001 
00002 #pragma once
00003 
00004 //#include <avr/io.h>
00005 #include "CMcp4242.h"
00006 
00007 // Here are some design notes for the MCP4242 current limiting
00008 //  with the LMD18245 devices
00009 
00010 // LMD18245 3A, 55V DMOS Full-Bridge Motor Driver:
00011 // The LMD18245 device is rated for a maximum of 3 amps.
00012 // Current limiting is set by a resistance between CS_OUT and GND.
00013 // The resistance is made up of a 6.2K resistor in series with
00014 //  a 50K rheostat in the MCP4242 device.  There are two LMD18245's,
00015 //  and two current limiting reistor paths, so both rheostats must
00016 //  be updated at the same time.
00017 // Formula is 5V x 15/16 / (.00025 x R) = Amps
00018 //  or Amps = 18750 / R  where R = 6.2K + rheostat setting
00019 
00020 // MCP4242 Dual 50K 129-step Non-volatile Rheostat
00021 // Each step of the rheostat is 50K/128 = 390.625 + 70 = 460.625 ohms
00022 // Combined with the series 6.2K resistor yields total resistance of:
00023 // 0 - 6.27K  127 - 56.19K
00024 // 1 - 6.66K  128 - 56.60K
00025 // 2 - 7.05K  129 - 56.60K
00026 
00027 //  0   0   6.27K  2.99A      6  36  20.33K  0.92A
00028 //  1   6   8.61K  2.18A      7  42  22.68K  0.82A
00029 //  2  12  10.95K  1.70A      8  48  25.02K
00030 //  3  18  13.30K  1.41A      9  54  27.36K
00031 //  4  24  15.65K  1.20A     10  60  29.71K  0.63A
00032 //  5  30  17.99K  1.04A
00033 
00034 //  STEPS - Each step represents roughly 0.25A change
00035 //  0   0   3.00A       4   8  2.00A    8  32   1.00A
00036 //  1   2   2.66A   5  11  1.77A    9  48   0.75A
00037 //  2   3   2.51A   6  16  1.50A   10  80   0.50A
00038 //  3   5   2.28A   7  22  1.26A
00039 
00040 // Forth Word(s)
00041 void readCurrentLimit(void);    // -- setting or error (-1)
00042 void writeCurrentLimit(void);   // setting --
00043 
00044 const char settings[] = {80, 48, 32, 22, 16, 11, 8, 5, 3, 2, 0};  // Low to high current
00045 
00046 //---------------------------------------------------------------------------- //-------------------------------------------------------------------------
00049 class CCurrentLimit : CMcp4242
00050 {
00051 public:
00052         static void init(void)
00053         {
00054                 CMcp4242::init();       // Call base class init()
00055         }
00056 
00066         static int read(void)
00067         {
00068                 int wiperValue;
00069 
00070                 wiperValue = CMcp4242::read(wiper0nv);
00071                 for (unsigned int i = 0; i < sizeof(settings); i++)
00072                 {
00073                         if (wiperValue == settings[i])
00074                         {
00075                                 if (wiperValue != CMcp4242::read(wiper0))
00076                                         break;
00077                                 if (wiperValue != CMcp4242::read(wiper1))
00078                                         break;
00079                                 if (wiperValue != CMcp4242::read(wiper0nv))
00080                                         break;                  // Go to error condition
00081                                 if (wiperValue != CMcp4242::read(wiper1nv))
00082                                         break;                  // Go to error condition
00083                                 return i;                       // All 4 pot regs match
00084                         }
00085                 }
00086                 // Conversion didn't work or wipers don't match
00087                 return -1;                                      // Return error
00088         }
00089 
00098         static void write(int setting)
00099         {
00100                 // Check setting for invalid array index
00101                 if (setting < 0 || setting >= (int)sizeof(settings))
00102                         return;
00103                 if (read() == setting)          // Compare to current setting
00104                         return;                                 // Rheostats are alread set
00105 
00106                 CMcp4242::write(wiper0,   settings[setting]);
00107                 CMcp4242::write(wiper1,   settings[setting]);
00108                 CMcp4242::write(wiper0nv, settings[setting]);
00109                 // Wait for EEWA (EEPROM Write Active) to be inactive
00110                 while (CMcp4242::read(status) & _BV(EEWA));             
00111                 CMcp4242::write(wiper1nv, settings[setting]);
00112         }
00113 };
 All Classes Files Functions Variables Defines