Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help in using digital potentiometer with LM386

Status
Not open for further replies.

Rickooo

Member level 3
Joined
Aug 28, 2018
Messages
67
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
507
Hello,

I am newbie at CCS programming. I am designing speaker with digital potentiometer. The amplifier is LM386 and digital potentiometer is MCP4131 (100k). I am using PIC18F4520 microcontroller at 8Mhz frequency.

I have code for it and checked it in Proteus. In starting I get the result but later it's distroted. I am even not sure about connection and code.

Here is the link of my project:


Please guide me that where I am wrong and where I can improve and how.

Awaiting response.

Thanks
 

Many of us do not have Proteus, please post an image of the schematic and your source code.
Most likely the distortion is due to an electrical reason but without a schematic it isn't possible to investigate.

Brian.
 

Many of us do not have Proteus, please post an image of the schematic and your source code.
Most likely the distortion is due to an electrical reason but without a schematic it isn't possible to investigate.

Brian.
Helo.
here is the link for circuit

PICCC.png

Here is the code;
Code:
#define SSD1306_RST   PIN_D4
#include <18F4520.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP                       
#use delay(clock = 8MHz)
#use I2C(MASTER, I2C1, FAST = 400000, stream = SSD1306_STREAM)  // Initialize I2C

// Include SSD1306 OLED driver source code

#include <SSD1306OLED.c>

#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H) 
#define SPI_MODE_1  (SPI_L_TO_H) 
#define SPI_MODE_2  (SPI_H_TO_L) 
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)
#define CS_PIN PIN_B4  //Chip Select
#define CLK_PIN PIN_B5 //Serial Clock
#define DI_PIN PIN_B6  //Serial Data In
#define Up PIN_A0
#define Down PIN_A1
#define Select PIN_A2
// End specification for pins

void DigPot();
void initializeDigPot();


unsigned short t=0;
unsigned int16 Mask=0x7000|Mask;


void initializeDigPot(int InitialValue) 
//---------------------------------------------- 
{ 
   setup_spi(SPI_MASTER | SPI_MODE_3 | SPI_CLK_DIV_16 );
   output_high(CS_PIN); 
   
} 

void DigPot(int Mask) 
//---------------------------------------------- 
//used for MCP41xxx Microchip digital pot 
// 0x00 = wiper at PB0, 0xFF wiper at PA0 
{ 


   output_low(CS_PIN); 
   delay_us(1); 
   spi_write(Mask); 
   delay_us(1); 
  

   for (t=0; t<16; t++){
   delay_cycles(2);

   if((Mask&0x8000) == 0) output_low(DI_PIN);
   else output_high(DI_PIN);
   output_high(CLK_PIN);
   Delay_us(5);
   output_low(CLK_PIN);
   Mask = Mask << 1;
}
output_high(CS_PIN);
}

void main()
{
initializeDigPot();
while(1)
{
digpot(1024);
output_high(CS_PIN);
Delay_us(5);
}
return;
}
 

Hi,

EPOT_POA connection: There is a signal with arrow pointing upwards. Where does it go to?

Klaus
 

I believe Klaus has figured your problem. You are connecting the POA pin to some sort of voltage.

Speaking of supply voltages....Digipot's supplies are constrained to logic supplies. If you are operating the LM386 from 12 volts, to increase power output, you'll damage the digipot. But we can't know for sure.

But again, with an incomplete schematic, we can only make incomplete assumptions.
 

It is advisable to add a resistor from the LM386 input to ground.
Add a much bigger capacitor across it's supply pins. (~100uF).
Note that the MCP4131 is a linear device and not really suited to volume control applications and it cannot handle negative input voltages. It may be advisable to pre-bias the signal to it to around half VDD to remove the risk of the input voltage going below ground.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top