laoadam
Member level 2
Hi,
I am testing a MCP4261 by the code below, got the result measured by a multi-meter with different readings, why?
The pot0 output at: 0 - 2.24 loop;
The pot1 output at: 2.52 - 4.80 loop.
why?
Thanks for help.
adam
I am testing a MCP4261 by the code below, got the result measured by a multi-meter with different readings, why?
The pot0 output at: 0 - 2.24 loop;
The pot1 output at: 2.52 - 4.80 loop.
why?
Thanks for help.
adam
Code:
#include <SPI.h>
const byte csPin = 2; // MCP42100 chip select pin
const int maxPositions = 256; // wiper can move from 0 to 255 = 256 positions
const long rAB = 100000; // 100k pot resistance between terminals A and B
const byte rWiper = 125; // 125 ohms pot wiper resistance
const byte pot0 = 0x11; // pot0 addr
const byte pot1 = 0x12; // pot1 addr
const byte potBoth = 0x13; // pot0 and pot1 simultaneous addr
const byte pot0Shutdown = 0x21; // pot0 shutdown
const byte pot1Shutdown = 0x22; // pot1 shutdown
const byte potBothShutdown = 0x23; // pot0 and pot1 simultaneous shutdown
byte addressPot0 = 0b00010001; //PIN 9 // To define potentiometer use last two BITS 01= POT 0
byte addressPot1 = 0b00010010; //PIN 6 // To define potentiometer use last two BITS 10= POT 1
byte addressPot0and1 = 0b00010011; //To define potentiometer use last two BITS 10= POT 0 and 1
byte CS = 53; // MCP4261_1, Chip control goes to pin 10
byte SHDN = 49; //MCP4261_12, Chip SHUTDOWN - PIN 9
byte RS = 48; // MCP4261_11, Chip RESET - PIN 8
void setup()
{
pinMode (CS, OUTPUT); //CS - When High, sets chip to read the data.
pinMode (SHDN, OUTPUT); //CS - When High, sets chip to read the data.
pinMode (RS, OUTPUT); //CS - When High, sets chip to read the data.
digitalWrite(SHDN, HIGH); //Power ON (HIGH)
digitalWrite(RS, HIGH); //Power NO RESET (LOW)
SPI.begin();
}
void loop()
{
Test0_loop();
}
void Test0_loop()
{
PotHighAndLow_mt(addressPot0); //Change POT values on Pot0
PotHighAndLow_mt(addressPot1); //Change POT values on Pot1
PotHighAndLow_mt(addressPot0and1); //Change POT values on both
digitalPotWrite(245, addressPot1);
digitalWrite(SHDN, LOW); //Power OFF (LOW)
delay(5000); //delay for 5 seconds to test current consumption of potentiometer
digitalWrite(SHDN, HIGH); //Power ON (HIGH)
digitalPotWrite(245, addressPot1);
digitalWrite(RS, LOW); //Power NO RESET (LOW)
delay(100); //delay 100 mls
digitalWrite(RS, HIGH); //Power RESET (HIGH)
delay(10000); //delay 10 sec
}
void PotHighAndLow_mt(byte address)
{
/* We have limit from 130 - 255 just for LED test, but for other projects it can be 0-255 */
for (int i = 130; i <= 255; i++)
{
digitalPotWrite(i,address);
delay(50);
}
// delay(500);
for (int i = 255; i >= 130; i--)
{
digitalPotWrite(i,address);
delay(100);
}
}
int digitalPotWrite(byte value, byte address)
{
digitalWrite(CS, LOW); //Set Chip Active
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(CS, HIGH); //Set Chip Inactive
}