MCP3422 Analog to Digital Converter


Today 22:23
Forum: The Lounge
Starter: Tim
Views: 0
Replies: 12
Today 22:21
Forum: The Lounge
Starter: John Drew
Views: 0
Replies: 2
Today 22:15
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 9
Today 22:04
Forum: GSM / SMS
Starter: david
Views: 0
Replies: 2
Today 15:12
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 0
Today 11:40
Forum: Proton 24
Starter: SCV
Views: 0
Replies: 10
Today 05:59
Forum: GPS
Starter: david
Views: 0
Replies: 0
Today 05:37
Forum: Test Postings
Starter: david
Views: 0
Replies: 0
Today 01:07
Forum: Proton Plus Compiler v3
Starter: geoff_c
Views: 0
Replies: 15
+ Reply to Thread
Results 1 to 4 of 4

Thread: MCP3422 Analog to Digital Converter79 days old

  1. #1
    Junior Member eds's Avatar
    Join Date
    Feb 2018
    Posts
    2
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    152.89 MB

    0 Not allowed!

    Default MCP3422 Analog to Digital Converter

    I am intending to use a MCP3422 Analog to digital Converter with a PIC18F2480. Can someone please help with Proton Basic setup and coding?
    Thanks

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    35
    Thumbs Up
    Received: 9
    Given: 0
    Total Downloaded
    144.28 MB

    0 Not allowed!

    Default Re: MCP3422 Analog to Digital Converter

    Eds, Here is a routine I use for the MCP3421 which is the same part but, with only a single channel.

    UNIT0 CON %11010000 'CONTROL AND ADDRESS OF MCP3421 A to D CONVERTER
    CONFIGBITS CON %10011100 'A/D CONFIGURATION REGISTER BITS (start conversion, continuous mode,18 bits, gain of x1)
    MSB VAR BIT
    HDATA3421 VAR LONG '32 bits



    '************************************************* ********************
    READMCP3421: 'READ MCP3421 A/D VOLTAGE (18 BIT) (SINGLE ENDED MODE)
    '************************************************* ********************
    I2CREAD SDA,SCK,UNIT0,[HDATA3421],NOACK 'READ CURRENT DATA
    I2CWRITE SDA,SCK,UNIT0,[CONFIGBITS] 'START ANOTHER CONVERSION
    HDATA3421 = (HDATA3421 >> 8) 'TURN RESULT INTO 18 BIT VARIABLE
    MSB = HDATA3421.17
    IF MSB = 1 THEN HDATA3421 = ABS(HDATA3421 | $FFFD0000)
    RETURN
    NOACK:
    HDATA3421 = 0
    RETURN

    Of course this is NOT Proton basic but PBP but you should get the drift. Bit's 5 and 6 of the configuration will select your channel on the MCP3422.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,060
    Thumbs Up
    Received: 330
    Given: 122
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default Re: MCP3422 Analog to Digital Converter

    Here's a program I've just written to interface with the MCP3422 ADC chip. I don't have a device, but I've tested it in Isis and it works. It's only written for, upto, 16-bit operation, but adding the 18-bit will be a simple task for you. Just use a Dword variable and read three bytes from the MC3422 chip. See its datasheet, Page 22. Everything is in the program to easily add 18-bit operation, but I ran out of time.

    Code:
    '
    ' A simple program to read from an MCP3422 ADC device
    ' Written by Les Johnson for the PRoton BASIC compiler
    '
        Device = 18F26K22
        Declare Xtal= 20
    '
    ' Setup the USART
    '    
        Declare Hserial_Baud= 9600                     ' Set the Baud for USART1
        Declare Hserout_PinPORTC.6                     ' Choose the pin for TX
    '
    ' Setup I2C
    '    
        Declare SDA_Pin= PORTC.4                       ' Choose the pin to use for the I2C SDA line
        Declare SCL_Pin= PORTC.3                       ' Choose the pin to use for the I2C SCL line
    '
    ' Create variables for the MCP3422 routine
    '    
        Dim MCP34_bChannel As Byte                      ' Holds the channel to read from
        Dim MCP34_bConfig As Byte                       ' Holds the Config for the MCP3422 chip
        Dim MCP34_wResult As Word                       ' Holds the result of the ADC reading
       
    $define cMCP34_SlaveAddress %11010000               ' The slave address of the MCP3422 chip
    '
    ' The values below need to be ORed together to make a Config register value
    '    
    ' Ready Bit
    ' This bit is the data ready flag. In read mode, this bit indicates if the output register has been updated with a latest conversion result.
    ' In One-Shot Conversion mode, writing this bit to "1" initiates a new conversion.
    '   Reading RDY bit with the read command:
    '       1 =  Output register has not been updated
    '       0 =  Output register has been updated with the latest conversion result
    '  Writing RDY bit with the write command:
    '       Continuous Conversion mode: No effect
    '       One-Shot Conversion mode:
    '           1 =  Initiate a new conversion
    '           0 =  No effect
    '
    $define cMCP34_Rdy %10000000            ' RDY: Ready Value to start a conversion
    $define cMCP34_RdyBit 7                 ' Ready bit to examine in the program
    
    ' C1-C0: Channel Selection Bits
    $define cMCP34_Ch_1 %00000000           ' Select Channel 1 (Default)
    $define cMCP34_Ch_2 %00100000           ' Select Channel 2
    $define cMCP34_Ch_3 %01000000           ' Select Channel 3 (MCP3424 only, treated as "00" by the MCP3422/MCP3423)
    $define cMCP34_Ch_4 %01100000           ' Select Channel 4 (MCP3424 only, treated as "01" by the MCP3422/MCP3423)
    
    ' O/C: Conversion Mode Bit
    $define cMCP34_Mode_Cont %00010000      ' Continuous Conversion Mode (Default). The device performs data conversions continuously
    $define cMCP34_Mode_One  %00000000      ' One-Shot Conversion Mode. The device performs a single conversion and enters a low power
                                            ' standby mode until it receives another write or read command
    ' S1-S0: Sample Rate Selection Bit
    $define cMCP34_Sample_12 %00000000      ' 240 SPS (12 bits) (Default)
    $define cMCP34_Sample_14 %00000100      ' 60 SPS (14 bits)
    $define cMCP34_Sample_16 %00001000      ' 15 SPS (16 bits)
    $define cMCP34_Sample_18 %00001100      ' 3.75 SPS (18 bits)
    
    ' G1-G0: PGA Gain Selection Bits
    $define cMCP34_Gain_1 %00000000         ' x1 (Default)
    $define cMCP34_Gain_2 %00000001         ' x2
    $define cMCP34_Gain_4 %00000010         ' x4
    $define cMCP34_Gain_8 %00000011         ' x8 
    '
    ' Some values for standard one-shot ADC configurations
    '   
    $define cConvert_Ch1_12  cMCP34_Rdy | cMCP34_Ch_1 | cMCP34_Mode_One | cMCP34_Sample_12 | cMCP34_Gain_1  ' Read channel 1 at a gain of 1 in 12-bit mode
    $define cConvert_Ch2_12  cMCP34_Rdy | cMCP34_Ch_2 | cMCP34_Mode_One | cMCP34_Sample_12 | cMCP34_Gain_1  ' Read channel 2 at a gain of 1 in 12-bit mode
    $define cConvert_Ch1_14  cMCP34_Rdy | cMCP34_Ch_1 | cMCP34_Mode_One | cMCP34_Sample_14 | cMCP34_Gain_1  ' Read channel 1 at a gain of 1 in 14-bit mode
    $define cConvert_Ch2_14  cMCP34_Rdy | cMCP34_Ch_2 | cMCP34_Mode_One | cMCP34_Sample_14 | cMCP34_Gain_1  ' Read channel 2 at a gain of 1 in 14-bit mode      
    $define cConvert_Ch1_16  cMCP34_Rdy | cMCP34_Ch_1 | cMCP34_Mode_One | cMCP34_Sample_16 | cMCP34_Gain_1  ' Read channel 1 at a gain of 1 in 16-bit mode
    $define cConvert_Ch2_16  cMCP34_Rdy | cMCP34_Ch_2 | cMCP34_Mode_One | cMCP34_Sample_16 | cMCP34_Gain_1  ' Read channel 2 at a gain of 1 in 16-bit mode
    
    '------------------------------------------------------------------------------
        GoTo Main  ' Jump to the main program loop
        
    '------------------------------------------------------------------------------
    ' Read the MCP3422 ADC chip
    ' Input     : pChannel holds the ADC channel to read
    ' Output    : MCP34_wResult holds the result of the ADC reading
    ' Notes     : To change the ADC resolution alter the MCP34_bConfig value
    '           : The routine will not work for 18-bit resolution
    '           : If it is required, use a Dword variable for the result
    '
    $define MCP3422_Read(pChannel) '
        MCP34_bChannel = pChannel  '
        _MCP3422_Read()
          
    Sub _MCP3422_Read()    
        If MCP34_bChannel = 1 Then                              ' Are we reading channel 1?
            MCP34_bConfig = cConvert_Ch1_16                     ' Yes. So setup for channel 1 at 16-bits
        Else                                                    ' Otherwise...
            MCP34_bConfig = cConvert_Ch2_16                     ' Setup for channel 2 at 16-bits
        EndIf
        BusOut cMCP34_SlaveAddress,[MCP34_bConfig]              ' Start a conversion
    '
    ' Wait for the conversion to be ready
    '    
        Do
            BusIn cMCP34_SlaveAddress, [MCP34_wResult.Byte1,_   ' Read the high byte of the ADC value
                                        MCP34_wResult.Byte0,_   ' Read the low byte of the ADC value
                                        MCP34_bConfig]          ' Read the Config byte
            If MCP34_bConfig.cMCP34_RdyBit = 0 Then Break       ' Exit the loop when the conversion is complete    
        Loop
    EndSub
    
    '------------------------------------------------------------------------------
    ' The main program loop starts here
    '
    Main:
        Do
            MCP3422_Read(1)                                 ' Read channel 1 from the MCP3422
            HRSOutLn "Channel 1 = ", SDec MCP34_wResult     ' Transmit the result to the serial terminal
            
            MCP3422_Read(2)                                 ' Read channel 2 from the MCP3422
            HRSOutLn "Channel 2 = ", SDec MCP34_wResult     ' Transmit the result to the serial terminal
            
            DelayMS 500                                     ' A delay so we can see things happening
        Loop                                                ' Do it forever
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Junior Member eds's Avatar
    Join Date
    Feb 2018
    Posts
    2
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    152.89 MB

    0 Not allowed!

    Default Re: MCP3422 Analog to Digital Converter

    Thanks Les, much appreciated :-)

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. ADC32RF45 industry's fastest 14-bit analog-to-digital converter (ADC)
    By normnet in forum New devices and techniques
    Replies: 0
    Last Post: 21st May 2016, 14:23
  2. Microchips new MCP48FXBXX Digital-to-Analog converter families
    By normnet in forum New devices and techniques
    Replies: 0
    Last Post: 24th February 2016, 20:15
  3. Replies: 0
    Last Post: 4th December 2015, 04:38
  4. 12 bit analog to digital converter
    By geoff_c in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 6th July 2012, 13:29
  5. Is switching analog to digital possible?
    By nuclear__ in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 11th November 2007, 20:17

Members who have read this thread : 43

Actions :  (Set Date)

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