Site icon Ercan Koçlar

MCP4561 Digital Resistor Library – MikroC

My work - My Articles -My Experiences

MCP4561-Kapak

This post is also available in: Türkçe (Turkish)



MCP4561 Digital Resistor -POT

 

MCP4561 Memory Map

Address Function Memory Type
00h Volatile Wiper 0 RAM
01h Not used in this model
02h Non Volatile Wiper 0 EEPROM
03h Not used in this model.
04h Volatile TCON Register RAM
05h Status Register RAM
06h EEPROM Cell EEPROM
07h EEPROM Cell EEPROM
08h EEPROM Cell EEPROM
09h EEPROM Cell EEPROM
0Ah EEPROM Cell EEPROM
0Bh EEPROM Cell EEPROM
0Ch EEPROM Cell EEPROM
0Dh EEPROM Cell EEPROM
0Eh EEPROM Cell EEPROM
0Fh EEPROM Cell EEPROM

 

MCP4561 Control Areas

 

Status Register

Status Register – Memory Address 05h
1 1 1 1 read-0 read-x read-x
Reserved Area EEWA WL0 WP
7.bit 6.bit 5.bit 4.bit 3.bit 2.bit 1.bit 0.bit

 

TCON – Terminal Control Register

TCON – Terminal Control Register – Memory Address 04h
r/w-1 r/w-1 r/w-1 r/w-1 r/w-1
GCEN R0HW R0A R0W R0B
8.bit 7.bit 6.bit 5.bit 4.bit 3.bit 2.bit 1.bit 0.bit

 

MCP4561 Operation Protocols

 

MCP4561 Address System

MCP4561 Address Diagram

 

MCP4561 Genral Command Transmission System

General Commands
7 bit Command Function
100000D Writes data to the wiper area – Volatile Memory Expanded Command
110000D Writes data to the TCON area – Volatile Memory Expanded Command
1000010 Increases the Wiper Value General Command
1000100 Decreases the Wiper Value General Command

 

General Command System

MCP4561 General Command Diagram

 

Expanded General Command System

MCP4561 Expanded Genel Command Diagram

 

MCP4561 Operation Commands

Operation Commands
Command (binary) Function
00 Data Write
01 Wiper Increase
10 Wiper Decrease
11 Read Data

 

MCP4561 Data Write Operation

MCP4561 Data Write Diagram

 

MCP4561 Data Read Process

MCP4561 Data Read Diagram

 

MCP4561 Wiper Increase Process

MCP4561 Wiper Increase Diagram

 

MCP4561 Wiper Decrease Operation

MCP4561 Wiper Decrease Diagram

 

MCP4561 Pin Functions

MCP4561 Pins

 

Pin Name Function
1 A0 I2C Address Pin
2 SCL I2C Clock Pin
3 SDA I2C Data Pin
4 Vss GND
5 P0A Adjustable resistor 1st Pin
6 P0W Adjustable resistor wiper pin- WIPER
7 P0B Adjustable resistor 2nd Pin
8 Vdd Power +1,8V / +5V

 

MCP4561 Digital Trimpot Circuit

MCP4561 Circuit Diagram

MCP4561 Circuit Diagram

 

Necessary Materials

  1. MCP4561
  2. 100nf capacitor
  3. 20 k resistor – 2 units
  4. DIP adapter for test circuits

 

Circuit Construction

MCP4561 Circuit Layout
MCP4561 Circuit Layout 2
DIP Adapter

 

MCP4561 MikroC Library

Functions

General Command Functions

 

MCP4561_GENEL_KOMUTLAR Function

Function: unsigned char MCP4561_GENEL_KOMUTLAR(unsigned char KOMUT)

Purpose: Executes general commands. It performs wiper increment and decrement operations on MCP4561 devices on the I2C bus.

Parameters :

How to Use :

MCP4561_GENEL_KOMUTLAR(WIPER_ARTTIR);

Feedback :

 

MCP4561_GENISLETILMIS_GENEL_KOMUTLAR Function

Function : unsigned char MCP4561_GENISLETILMIS_GENEL_KOMUTLAR(unsigned char KOMUT,unsigned char VERI)

Purpose: Executes general commands. It is used to write to the TCON area and the volatile wiper value of MCP4561 devices on the I2C bus.

Parameters :

How to Use :

MCP4561_GENISLETILMIS_GENEL_KOMUTLAR(TCON_REGISTER_DEGERI,0b11001100)

Feedback :

 

Operation Functions

 

MCP4561_VERI_OKUMA Function

Function : unsigned int MCP4561_VERI_OKUMA(unsigned char MCP4561_ADRESI,unsigned char RAM_ADRESI)

Purpose: Reads data from the specified memory area.

Parameters :

How to Use :

MCP4561_VERI_OKUMA(0,5);

Feedback :

 

MCP4561_DIRENC_DEGERI_OKU Function

Function : unsigned int MCP4561_DIRENC_DEGERI_OKU(unsigned char MCP4561_ADRESI,unsigned char RAM_ADRESI)

Purpose: Directly reads the resistance value from the specified wiper points.

Parameters :

How to Use :

MCP4561_DIRENC_DEGERI_OKU(0,5);

Feedback :

 

MCP4561_STATUS_OKUMA Function

Function : unsigned char MCP4561_STATUS_OKUMA(unsigned char MCP4561_ADRESI)

Purpose: Reads the status register.

Parameters :

How to Use :

MCP4561_STATUS_OKUMA(0);

Feedback :

 

MCP4561_VERI_YAZMA Function

Function : unsigned char MCP4561_VERI_YAZMA(unsigned char MCP4561_ADRESI,unsigned char RAM_ADRESI,unsigned int VERI)

Purpose: Writes data to the selected memory address.

Parameters :

How to Use :

 MCP4561_VERI_YAZMA(0,5,125);

Feedback :

 

MCP4561_DIRENC_DEGERI_YAZ_GECICI Function

Function : void MCP4561_DIRENC_DEGERI_YAZ_GECICI(unsigned char MCP4561_ADRESI,unsigned int DIRENC_DEGERI_OHM)

Purpose: Writes the entered resistance value (in ohms) to the volatile resistor area.

Parameters :

How to Use :

unsigned char MCP4561_DIRENC_DEGERI_YAZ_GECICI(0,39);

Feedback: No feedback provided.

 

MCP4561_DIRENC_DEGERI_YAZ_KALICI Function

Function : void MCP4561_DIRENC_DEGERI_YAZ_KALICI(unsigned char MCP4561_ADRESI,unsigned int DIRENC_DEGERI_OHM)

Purpose: Writes the entered resistance value (in ohms) to the non-volatile resistor area.

Parameters :

How to Use :

unsigned char MCP4561_DIRENC_DEGERI_YAZ_KALICI(0,39);

Feedback: No feedback provided.

 

WIPER Functions

 

MCP4561_WIPER_BASLANGIC Function

Function : unsigned char MCP4561_WIPER_BASLANGIC(unsigned char MCP4561_ADRESI)

Purpose: This function is called first to perform the wiper adjustment.

Parameters :

How to Use :

MCP4561_WIPER_BASLANGIC(0);

Feedback :

 

MCP4561_WIPER_ARTTIRMA Function

Function : unsigned char MCP4561_WIPER_ARTTIRMA()

Purpose: Increases the wiper by one step.

Parameters: None

How to Use :

MCP4561_WIPER_ARTTIRMA();

Feedback :

 

MCP4561_WIPER_AZALTMA Function

Function : unsigned char MCP4561_WIPER_AZALTMA()

Purpose: Decreases the wiper by one step.

Parameters: None

How to Use :

MCP4561_WIPER_AZALTMA();

Feedback :

 

MCP4561_WIPER_SONLANDIR Function

Function : void MCP4561_WIPER_SONLANDIR()

Purpose: Terminates the wiper adjustment process.

Parameters: None

How to Use :

MCP4561_WIPER_SONLANDIR();

Feedback: No feedback provided.

 

Application of Functions

//I2C protokolü için pin ayarlamaları
 sbit I2C_SDA at RB6_bit;
 sbit I2C_SCL at RB7_bit;

 sbit I2C_SDA_VERI at LATB6_bit;//27.01.2019 güncellemesi ile eklendi

 sbit I2C_SDA_Direction at TRISB6_bit;
 sbit I2C_SCL_Direction at TRISB7_bit;
 
void  main()
{

    unsigned int deger=0;
    CMCON=7;

    MCP4561_DIRENC_DEGERI_YAZ_KALICI(0,5000);//5000 ohm yani 5k
    
    deger=MCP4561_DIRENC_DEGERI_OKU(0,2);
     
    MCP4561_DIRENC_DEGERI_YAZ_GECICI(0,deger);
    

}
The MCP4561 is set to 5k ohms.
//I2C protokolü için pin ayarlamaları
 sbit I2C_SDA at RB6_bit;
 sbit I2C_SCL at RB7_bit;

 sbit I2C_SDA_VERI at LATB6_bit;//27.01.2019 güncellemesi ile eklendi

 sbit I2C_SDA_Direction at TRISB6_bit;
 sbit I2C_SCL_Direction at TRISB7_bit;
 
void  main()
{

    unsigned int deger=0;
    CMCON=7;

    MCP4561_DIRENC_DEGERI_YAZ_KALICI(0,5000);
    
    deger=MCP4561_DIRENC_DEGERI_OKU(0,2);
     
    MCP4561_DIRENC_DEGERI_YAZ_GECICI(0,deger);
    
    
    MCP4561_WIPER_BASLANGIC(0);
    MCP4561_WIPER_ARTTIRMA();
    MCP4561_WIPER_ARTTIRMA();
    MCP4561_WIPER_SONLANDIR();
    
    
    deger=MCP4561_DIRENC_DEGERI_OKU(0,0);
    MCP4561_DIRENC_DEGERI_YAZ_KALICI(0,deger);
    

}
The MCP4561 wiper was increased by 2 steps.

The Operation Video


Result


Library Files

 


References


PIC

This post is also available in: Türkçe (Turkish)

Exit mobile version