Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
27-03-2014, 09:36 AM, (This post was last modified: 27-03-2014, 09:44 AM by moreno.)
#1
Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
Hi

Is very hard make prototype with SMD components 8<)))

My last library, available from IDE version 980, is the support for the great Microchip MCP342x ADC family.

I added library MCP342x.c and MCP342x.pdl32 for 32bit Pinguino boards.
I created even a sample program examples\04.Communication\MCP342x_I2C_ADC\MCP3422_2CH_18Bit_I2C_ADC.pde.


Bye Bye, Moreno


Attached Files Thumbnail(s)
   
Reply
27-03-2014, 10:26 AM,
#2
RE: Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
There are recent threads on TheBackShed about soldering these awkwardly small chips, e.g. http://www.thebackshed.com/forum/forum_p...=6410&PN=1

John
Reply
27-03-2014, 04:31 PM,
#3
RE: Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
Hi

The problem are the eyes and hands, I'm an old boy 8<)))

I moved the sample program in examples\04.Communication\i2c folder


Bye Bye, Moreno
Reply
27-03-2014, 06:07 PM,
#4
RE: Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
Hi, Moreno.

Olimex Proto Shield is convenient material to build SMT projects. Its SOIC and MSOP pins don't match SOT23 exactly, but 6 pins can be aligned to fit at SOIC pins well.

When many different ISR are used such as millis, CDC, serial and RTC together, occasionally the interrupt flag for I2C is cleared 'mysteriously' (by other ISR handler?) and any I2C function will hang at I2C_wait() waiting for the flag to be set.

It is a different issue from the I2C bus hang, but specific to Pinguino library. A work around is to add a loop counter to give up and return.

DJ


Attached Files Thumbnail(s)
   
Reply
27-03-2014, 07:07 PM,
#5
RE: Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
Hi

Mmmmm, I have see a similar problem during my tests.
Nothing work, all hang on I2C.start, even if the reset button was pushed or sending a new program do not solve the problem.
The only solution is to switch off the board.

This problem is appeared 2/3 times in these days.

Now the program is running from more than 24 hours with 2 I2C devices, 1 SPI device and CDC port and all run well.
We need investigate.

Bye Bye, Moreno
Reply
27-03-2014, 07:48 PM,
#6
RE: Support for MCP342x ADC with I2C interface
(27-03-2014, 07:07 PM)moreno Wrote: Mmmmm, I have see a similar problem during my tests.
Nothing work, all hang on I2C.start, even if the reset button was pushed or sending a new program do not solve the problem.
The only solution is to switch off the board.

This problem is appeared 2/3 times in these days.

There are 2 different issues to take care -- 'i2c bus hang' and 'i2c wait hang'.

The 'i2c bus hang' is common subject for different uP and platforms and you will find many references and suggested solutions (though not all of them work well).

The 'i2c wait hang' is hardly seen outside of Pinguino forum and so far nobody gave solution. Now I give a work around below.

Every I2C function calls I2C_wait() function to wait till the I2C bus is idle in i2c.c library.

Code:
while (IFS0bits.I2C1MIF == 0);    // wait until interrupt request has a occurred
IFS0bits.I2C1MIF = 0;        // clear flag

If the interrupt flag is set by i2c device, and cleared by another ISR handler (by mistake), the flag will not set and hang there forever. It happens quite often when many ISR handlers are running at the same time, especially mixing RTCC alarm and millis with CDC and serial. I haven't been able to find which ISR is causing this and hope someone will find it.

The work around is changing the above code as follow.

Code:
u16 i = 5000;
while (IFS0bits.I2C1MIF == 0 && i--) ;    // wait until interrupt request has a occurred
IFS0bits.I2C1MIF = 0;            // clear flag

Most of time the loop exits within 50 counts, but sometimes it times out. Now I2C will never hang. If timeout, then check the I2C result to decide what action to take.

The other problem of 'i2c bus hang' can happen when the PIC is reset during the I2C operation, or electric noise jump into the i2c bus causing i2c master and slave out of sync. The above hang problem followed by the watchdog reset will likely cause this problem.

This can lead to the critical situation if the unit is located in a remote area (jungle) and collecting the data and control devices over external I2C devices (Olimex MOD-IO). The PIC will keep reset by watchdog, but MOD-IO will never respond till both are power recycled.

Quite a few different ways are suggested to solve this problem, most of them are specific to I2C slave parts and not universal. The sure way to solve this way is to use a relay to cut off power to both PIC and external devices by PIC if i2c bus hang or watchdog reset is detected.

Without such drastic method, I had a good successful recovery by using the digital IO bit bang to simulate the I2C stop procedure.

DJ
Reply
27-03-2014, 08:48 PM,
#7
RE: Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
Hi

You are right, any potentially infinite loop must be avoided.

I doubled the I2C_wait function.
The standard one remain the default function, if defined I2CWAIT_WORKAROUND is used the version with timeout.


Code:
#ifndef I2CWAIT_WORKAROUND
void I2C_wait(u8 module)
{
    switch(module)
    {
        case I2C1:
            #if defined(__32MX220F032D__) || defined (__32MX220F032B__) || defined (__32MX250F128B__)
            while (IFS1bits.I2C1MIF == 0);    // wait until interrupt request has a occurred
            IFS1bits.I2C1MIF = 0;            // clear flag
            #else
            while (IFS0bits.I2C1MIF == 0);    // wait until interrupt request has a occurred
            IFS0bits.I2C1MIF = 0;            // clear flag
            #endif
            break;
#if !defined(UBW32_460) && !defined(UBW32_795) && !defined(PIC32_PINGUINO_T795)            
        case I2C2:
            // __32MX220F032D__ or not, it's the same for all processors
            while (IFS1bits.I2C2MIF == 0);
            IFS1bits.I2C2MIF = 0;
            break;
#endif
    }
}
#else
void I2C_wait(u8 module)
{
u16 i = 5000;

    switch(module)
    {
        case I2C1:
            #if defined(__32MX220F032D__) || defined (__32MX220F032B__) || defined (__32MX250F128B__)
            while (IFS1bits.I2C1MIF == 0 && i--);    // wait until interrupt request has a occurred
            IFS1bits.I2C1MIF = 0;            // clear flag
            #else
            while (IFS0bits.I2C1MIF == 0 && i--);    // wait until interrupt request has a occurred
            IFS0bits.I2C1MIF = 0;            // clear flag
            #endif
            break;
#if !defined(UBW32_460) && !defined(UBW32_795) && !defined(PIC32_PINGUINO_T795)            
        case I2C2:
            // __32MX220F032D__ or not, it's the same for all processors
            while (IFS1bits.I2C2MIF == 0 && i--);
            IFS1bits.I2C2MIF = 0;
            break;
#endif
    }
}
#endif


Bye Bye, Moreno
Reply
09-04-2014, 09:28 PM,
#8
RE: Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
Hi

The quality of my SMD work is improved, in the coming weeks will be ready printed circuit board.

With this board I will develop library for AD5627 2 channel 16 bit I2C DAC.

Bye Bye, Moreno


Attached Files Thumbnail(s)
   
Reply
09-04-2014, 10:32 PM,
#9
Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
Hi, Moreno.

Here is my tip for SOT23 soldering. Please check the picture.

1) SOT23 leg space is half of regular vero board. You can split the thread of vero board to solder each leg of SOT23. Then it can be plugged in to DIP socket.

2) You can use spider style of soldering to the board without using the DIP socket. The board in the picture is Li-Ion charger using TI chip.

My 2 cents.

DJ


Attached Files Thumbnail(s)
   
Reply
10-04-2014, 06:58 AM,
#10
RE: Support for MCP342x 1 to 4 channels 12 to 18bit differential ADC with I2C interface
hI

Wonderful


Bye Bye, Moreno
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)