StepperII
Dual Axis Stepper Controller

CMcp4242.h

00001 
00002 #pragma once
00003 
00004 //#include <avr/io.h>
00005 #include "CSpi.h"
00006 
00007 // This is the interface for the MCP4242 Microchip dual digital pot
00008 // 0 - 6.27K  127 - 56.19K
00009 // 1 - 6.66K  128 - 56.60K
00010 // 2 - 7.05K  129 - 56.60K
00011 
00012 // Forth Word(s)
00013 void readPot(void);             // pot# -- value
00014 void writePot(void);    // value pot# --
00015 
00016 class CMcp4242 : CSpi
00017 {
00018 private:
00019 protected:
00020         // Command Format: AAAA CC DDDDDDDDDD
00021         // Support constants
00022         static const int  addressShift = 12;
00023         static const int  commandShift = 10;
00024         static const int  dataMask     = 0x1FF;
00025 
00026         // Commands
00027         static const char writeCmd = 0;
00028         static const char readCmd  = 3;
00029 
00030         // Memory Map
00031         static const char wiper0   = 0; // RAM
00032         static const char wiper1   = 1; // RAM
00033 
00034         static const char wiper0nv = 2; // EEPROM
00035         static const char wiper1nv = 3; // EEPROM
00036 
00037         static const char tcon     = 4;
00038         static const char status   = 5;
00039         
00040         static const char EEWA     = 4; // Status bit
00041         
00042         // Addresses 6 - 15 are user data registers in EEPROM
00043         
00044 protected:
00045 public:
00046         static void init(void)
00047         {
00048                 CSpi::init();   // Call base class init()
00049         }
00050         // Command Format:
00051         // AAAA CC DDDDDDDDDD
00052         static void write(int address, int data)
00053         {
00054                 writeWord((address  << addressShift) |                  // Address
00055                                   (writeCmd << commandShift) |                  // Write command
00056                                   (data & dataMask));                                   // Data
00057         }
00058 
00059         static int  read(unsigned int address)
00060         {
00061                 return writeWord((address << addressShift) |    // Address
00062                                                  (readCmd << commandShift));    // Read command 
00063         }
00064 };
 All Classes Files Functions Variables Defines