Digital Pot


Closed Thread
Results 1 to 7 of 7

Thread: Digital Pot

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Here's the code I wrote to control 5 digital pots daisy chained together.

    Code:
    DEFINE  LOADER_USED 1   ' Bootloader is being used
    DEFINE  OSC 16          ' Set oscillator frequency, 4MHz (HS_PLL x4)
    DEFINE  HSER_BAUD 9600  ' Baud rate for serial output
    DEFINE  HSER_CLROERR 1  ' Automatically clear over-run errors
    DEFINE  HSER_RCSTA 90h	' Enable USART receive
    DEFINE  HSER_TXSTA 24h	' TXSTA=%00100100. TX enable, BRGH=1 for high-speed
    
    @ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H
    ' Oscillator Switch Disable
    ' Oscillator Type HS PLL    
     
    @ __CONFIG _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L
    ' Brown-Out Reset Enabled
    ' Power-Up Timer Enable
    ' Brown-Out Reset Voltage 4.5V
    
    @ __CONFIG _CONFIG2H, _WDT_ON_2H 
    ' Watch Dog Timer Enable
    
    @ __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
    ' Stack Over/Underflow Reset Enable
    ' Low Voltage ICSP Programming Disabled
    ' Background Debugger Disabled
    
        ADCON1 = %0111              ' Set porta to digital mode
    
        si      var     porte.2
        sclk    var     porte.1
        cs      var     porte.0
    
        pot_value_0 var     byte
        pot_value_1 var     byte
        pot_value_2 var     byte
        pot_value_3 var     byte
        pot_value_4 var     byte
        cmd         var     byte
        position    var     byte
    
        low     sclk    ' Set clock pin low
        high    cs      ' Set chip select low
    
        clear
        
    start:
        gosub pot_5
        gosub pot_4
        gosub pot_3
        gosub pot_2
        gosub pot_1
        goto start                      
    
    pot_5:
        low cs
        cmd = %00010001 : position = pot_value_4 : gosub shout
        cmd = 0 : position = 0 : gosub shout
        cmd = 0 : position = 0 : gosub shout
        high cs
        return
    
    pot_4:
        low cs
        cmd = %00010010 : position = pot_value_3 : gosub shout
        cmd = 0 : position = 0 : gosub shout
        high cs
        return
    
    pot_3:
        low cs
        cmd = %00010001 : position = pot_value_2 : gosub shout
        cmd = 0 : position = 0 : gosub shout
        high cs
        return
    
    pot_2:
        low cs
        cmd = %00010010 : position = pot_value_1 : gosub shout
        high cs
        return
    
    pot_1:
        low cs
        cmd = %00010001 : position = pot_value_0 : gosub shout
        high cs
        return
    
    shout:
        shiftout si,sclk,1,[cmd]
        shiftout si,sclk,1,[position]
        return
    Just set the pot_value_x to whatever you want between 0-255.

  2. #2
    Scott's Avatar
    Scott Guest


    Did you find this post helpful? Yes | No

    Default

    Wow!

    Thanks for the code I'll give it a try this week and let you know.

    Scott

  3. #3


    Did you find this post helpful? Yes | No

    Default

    If you need any help with them just give me a shout.

Similar Threads

  1. Digital Pot
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd January 2012, 08:54
  2. Controlling a MCP4162 Digital Pot
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th February 2011, 19:51
  3. Digital Pot Advice
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd October 2007, 21:38
  4. Replies: 4
    Last Post: - 24th January 2007, 23:20
  5. Serial control of a digital pot?
    By TonyA in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2006, 00:49

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts