+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Newbie level 3
    Points: 184, Level: 2

    Join Date
    Aug 2018
    Posts
    3
    Helped
    0 / 0
    Points
    184
    Level
    2

    Help in using digital potentiometer with LM386

    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

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 80,963, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,271
    Helped
    4433 / 4433
    Points
    80,963
    Level
    69

    Re: Help in using digital potentiometer with LM386

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  3. #3
    Newbie level 3
    Points: 184, Level: 2

    Join Date
    Aug 2018
    Posts
    3
    Helped
    0 / 0
    Points
    184
    Level
    2

    Re: Help in using digital potentiometer with LM386

    Quote Originally Posted by betwixt View Post
    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

    Click image for larger version. 

Name:	PICCC.png 
Views:	17 
Size:	125.6 KB 
ID:	154120

    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 
    
    #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;
    }



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 77,038, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,609
    Helped
    3557 / 3557
    Points
    77,038
    Level
    67

    Re: Help in using digital potentiometer with LM386

    Hi,

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

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  5. #5
    Advanced Member level 5
    Points: 14,794, Level: 29
    schmitt trigger's Avatar
    Join Date
    Apr 2013
    Posts
    2,460
    Helped
    796 / 796
    Points
    14,794
    Level
    29

    Re: Help in using digital potentiometer with LM386

    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.
    My batteries are recharged by "Helpful Post" ratings.
    If you feel that I've helped you, please indicate it as a Helpful Post



    •   AltAdvertisement

        
       

  6. #6
    Super Moderator
    Points: 80,963, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,271
    Helped
    4433 / 4433
    Points
    80,963
    Level
    69

    Re: Help in using digital potentiometer with LM386

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



--[[ ]]--