User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Mon Jul 21, 2014 5:30 pm

itsisme wrote:Hai Gordon,

So you mean rem out :
// pinMode(CS_MCP3208, OUTPUT);

Tried it but after running the Python code it reads 0 again (reload spi_bcm2708) and it worked again (However also value to low compared to the Python output)

Chrs
the Python code is driving the hardware directly - bit-banging. You will definitely need to re-load the SPI drivers after running the Python code.

-Gordon
--
Gordons projects: https://projects.drogon.net/

itsisme
Posts: 20
Joined: Sat Mar 09, 2013 2:16 am

Re: Fast ADC with MCP3208

Mon Jul 21, 2014 5:49 pm

Thanks but how to get that into my code as this is a bit out of my league...

I tried to set the code as you

Code: Select all

buff[1] = 0x0F & buff[1];
//  adcValue = ( buff[1] << 8) | buff[2];
  adcValue = (buff [0] & 0x03) << 10 | buff [1] << 2 | (buff [2] >> 6) & 0x03 ;
But that provides also readouts for the grounded pins now

MCP3208 channel output.

adc0 Value = 3091 Voltage = 2.437
adc1 Value = 3072 Voltage = 2.422
adc2 Value = 3072 Voltage = 2.422
adc3 Value = 3072 Voltage = 2.422
adc4 Value = 3079 Voltage = 2.428
adc5 Value = 3072 Voltage = 2.422
adc6 Value = 3072 Voltage = 2.422
adc7 Value = 1024 Voltage = 0.807

1 to 7 are connected to ground via 100K only at 0 I have 1.17volts (multimeter readout)

Maybe you have a clear example somewhere that should hold the correct values?

Chrs..

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Mon Jul 21, 2014 5:52 pm

itsisme wrote:Thanks but how to get that into my code as this is a bit out of my league...

I tried to set the code as you

Code: Select all

buff[1] = 0x0F & buff[1];
//  adcValue = ( buff[1] << 8) | buff[2];
  adcValue = (buff [0] & 0x03) << 10 | buff [1] << 2 | (buff [2] >> 6) & 0x03 ;
But that provides also readouts for the grounded pins now

MCP3208 channel output.

adc0 Value = 3091 Voltage = 2.437
adc1 Value = 3072 Voltage = 2.422
adc2 Value = 3072 Voltage = 2.422
adc3 Value = 3072 Voltage = 2.422
adc4 Value = 3079 Voltage = 2.428
adc5 Value = 3072 Voltage = 2.422
adc6 Value = 3072 Voltage = 2.422
adc7 Value = 1024 Voltage = 0.807

1 to 7 are connected to ground via 100K only at 0 I have 1.17volts (multimeter readout)

Maybe you have a clear example somewhere that should hold the correct values?

Chrs..
I don't - else there would be a wiringPi driver for it. Let me re-read the data sheet again to make sure. I'm not convinced you're setting the channel register correctly...

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Mon Jul 21, 2014 6:02 pm

Give this a go:

Code: Select all

int read_mcp3208_adc (int adcChannel)
{
  unsigned char buff [3] ;

  int adcValue ;

  buf [0] = 0x80 |              // Start bit
            (chan & 7) << 4 |   // Channel
            0x08                // Padding
  
  buff [1] = buf [2] = 0 ;
  
  wiringPiSPIDataRW (SPI_CHANNEL, buff, 3) ;
  
   adcValue = (buf [0] & 0x03) << 10 | buf [1] << 2 | (buf [2] >> 6) & 0x03 ;
  
  return adcValue ;
} 
If it works let me know and I'll include it in wiringPi

-Gordon
--
Gordons projects: https://projects.drogon.net/

itsisme
Posts: 20
Joined: Sat Mar 09, 2013 2:16 am

Re: Fast ADC with MCP3208

Mon Jul 21, 2014 6:11 pm

Had to make some alterations and it compiles well now but giving:

MCP3208 channel output.

adc0 Value = 0000 Voltage = 0.000
adc1 Value = 0000 Voltage = 0.000
adc2 Value = 0000 Voltage = 0.000
adc3 Value = 0000 Voltage = 0.000
adc4 Value = 0003 Voltage = 0.002
adc5 Value = 0002 Voltage = 0.002
adc6 Value = 0002 Voltage = 0.002
adc7 Value = 0002 Voltage = 0.002

Code: Select all

int read_mcp3208_adc (int adcChannel)
{

     unsigned char buff [3] ;

     int adcValue ;
     buff [0] = 0x80 |             // Start bit
         (adcChannel & 7) << 4 |   // Channel
         0x08;                     // Padding

       buff [1] = buff [2] = 0 ;

     wiringPiSPIDataRW (SPI_CHANNEL, buff, 3) ;

     adcValue = (buff [0] & 0x03) << 10 | buff [1] << 2 | (buff [2] >> 6) & 0x03 ;

     return adcValue ;
}

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Mon Jul 21, 2014 6:37 pm

Difficult to remote debug, but I've just noticed I'm a bit-out on the channel initalisation as I forgot the single/differential bit )-:

Try replacing the channel selector 3 lines with the following 2:

Code: Select all

  buf [0] = 0xC0 |              // Start bit + single, 0x80 for differential
            (chan & 7) << 3     // Channel
The way it was before, it would have been in differential mode.

-Gordon
--
Gordons projects: https://projects.drogon.net/

itsisme
Posts: 20
Joined: Sat Mar 09, 2013 2:16 am

Re: Fast ADC with MCP3208

Mon Jul 21, 2014 10:12 pm

It keeps giving me the wrong readout.
I guess theer must be another item not corresponding to the proper setting but I am lost in where to look.

With the new codeI now get:

adc0 Value = 1239 Voltage = 0.977
adc1 Value = 0006 Voltage = 0.005
adc2 Value = 0010 Voltage = 0.008
adc3 Value = 0007 Voltage = 0.006
adc4 Value = 0522 Voltage = 0.412
adc5 Value = 0005 Voltage = 0.004
adc6 Value = 0006 Voltage = 0.005
adc7 Value = 0004 Voltage = 0.003

Looks like at the start with the code... (pc Channel 4 is not grounded just to know..
Would be good to get a good driver for this. If you have any hints or tips I would greatly appriciate it..

If Python can do the job C should also be possible hi..

My python readout is still ok:
Digital: 1464 Voltage: 1.154 V

Chrs..

itsisme
Posts: 20
Joined: Sat Mar 09, 2013 2:16 am

Re: Fast ADC with MCP3208

Tue Jul 22, 2014 11:09 pm

Hi Gordon,

I found the issue it was related to the clock speed only... duh...

#define SPI_SPEED 100000
Used here : if(wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED) == -1)

I could safely go up to 750000 but 1000000 was to much and that influenced the readout a lot.
Maybe breadboard issue or bad chip (I have another one I need to try)

Thanks for al your help and thinking......

Chrs....

RetiredProgrammer
Posts: 14
Joined: Sat Jan 10, 2015 10:42 pm

Re: Fast ADC with MCP3208

Sat Jan 10, 2015 10:49 pm

I have been struggling with some similar problems with the MCP3208. I found in the data sheet for it that analog input should have no more than 1K resistance. More than that and the sample and hold capacitor has a hard time getting the full charge. It is worse at higher frequencies. I thing your problem may be relate to the 100K resistors in your original post.

randombrain
Posts: 5
Joined: Sun Aug 23, 2015 3:44 pm

Re: Fast ADC with MCP3208

Sun Aug 23, 2015 3:51 pm

Hello Gordon and Chris—would you be able to post the full working C++/WiringPi source code for the MCP3208? With all the revisions that went back and forth I'm not sure I'd be able to recreate it correctly.

Thanks!

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Sun Aug 23, 2015 5:52 pm

randombrain wrote:Hello Gordon and Chris—would you be able to post the full working C++/WiringPi source code for the MCP3208? With all the revisions that went back and forth I'm not sure I'd be able to recreate it correctly.

Thanks!
I've not written a driver for this (yet). I could guess one from the data sheet though. It looks very similar to the mcp3004/8 though - can't you use that as a base for your code?

-Gordon
--
Gordons projects: https://projects.drogon.net/

randombrain
Posts: 5
Joined: Sun Aug 23, 2015 3:44 pm

Re: Fast ADC with MCP3208

Sun Aug 23, 2015 6:17 pm

[email protected] wrote: I've not written a driver for this (yet). I could guess one from the data sheet though. It looks very similar to the mcp3004/8 though
I'm a bit confused. I thought all the above discussion between you and itisme was about the 3208?

I'm using the code he posted, and I tried to apply the patches you described in the order you described. This is the code I have now:

Code: Select all

/*
 * Save as spi-test.c
 * Compile with: gcc -o spi-test spi-test.c -lwiringPi
 *
 * If no value: 
 * rmmod spi_bcm2708
 * modprobe spi_bcm2708
 * 
 * http://www.icbanq.com/pbloger/board_View.aspx?number=269
 * http://www.raspberrypi.org/forums/viewtopic.php?f=93&t=78551 (baart)
 * http://www.mikroe.com/add-on-boards/measurement/adc-proto/ (boards)
 * 
 */ 

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

#include <wiringPi.h>
#include <wiringPiSPI.h>

#define CS_MCP3208  6        // BCM_GPIO 25

#define SPI_CHANNEL 0
#define SPI_SPEED   50000 	 // 50kHz
#define AREFV		332.2	 // analog ref value

const char *byte_to_binary(int x)
{
    static char b[9];
    b[0] = '\0';

    int z;
    for (z = 128; z > 0; z >>= 1)
    {
        strcat(b, ((x & z) == z) ? "1" : "0");
    }

    return b;
}

int read_mcp3208_adc (int adcChannel)
{

     unsigned char buff [3] ;

     int adcValue ;
     buff [0] = 0xC0 |             		// Start bit + single, 0x80 for differential
               (adcChannel & 7) << 3 ;  // Channel

     buff [1] = buff [2] = 0 ;

     wiringPiSPIDataRW (SPI_CHANNEL, buff, 3) ;
     
     printf("\nbuff[0]: %s\tbuff[1]: %s\tbuff[2]: %s\n",byte_to_binary(buff[0]),byte_to_binary(buff[1]),byte_to_binary(buff[2]));

     adcValue = (buff [0] & 0x03) << 10 | buff [1] << 2 | (buff [2] >> 6) & 0x03 ;

     return adcValue ;
}

int main (void)
{
  int adc1Channel = 0;
  int adc1Value   = 0;
  int adc2Channel = 1;
  int adc2Value   = 0;
  int adc3Channel = 2;
  int adc3Value   = 0;
  int adc4Channel = 3;
  int adc4Value   = 0;
  int adc5Channel = 4;
  int adc5Value   = 0;
  int adc6Channel = 5;
  int adc6Value   = 0;
  int adc7Channel = 6;
  int adc7Value   = 0;
  int adc8Channel = 7;
  int adc8Value   = 0;
   
  if(wiringPiSetup() == -1)
  {
    fprintf (stdout, "Unable to start wiringPi: %s\n", strerror(errno));
    return 1 ;
  }

  if(wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED) == -1)
  {
    fprintf (stdout, "wiringPiSPISetup Failed: %s\n", strerror(errno));
    return 1 ;
  }

//  pinMode(CS_MCP3208, OUTPUT);

  while(1)
  {
    system("clear");
    printf("\n\nMCP3208 channel output.\n\n");
    adc1Value = read_mcp3208_adc(adc1Channel);
    printf("adc0 Value = %04u", adc1Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc1Value));
    adc2Value = read_mcp3208_adc(adc2Channel);
    printf("adc1 Value = %04u", adc2Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc2Value));
    adc3Value = read_mcp3208_adc(adc3Channel);
    printf("adc2 Value = %04u", adc3Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc3Value));
    adc4Value = read_mcp3208_adc(adc4Channel);
    printf("adc3 Value = %04u", adc4Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc4Value));
    adc5Value = read_mcp3208_adc(adc5Channel);
    printf("adc4 Value = %04u", adc5Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc5Value));
    adc6Value = read_mcp3208_adc(adc6Channel);
    printf("adc5 Value = %04u", adc6Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc6Value));
    adc7Value = read_mcp3208_adc(adc7Channel);
    printf("adc6 Value = %04u", adc7Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc7Value));
    adc8Value = read_mcp3208_adc(adc8Channel);
    printf("adc7 Value = %04u", adc8Value);
    printf("\tVoltage = %.3f\n", ((AREFV/4096) * adc8Value));
    usleep(1000000);
  }
  return 0;
}
The problem I'm hitting right now is that the values appear to be halved: with chan0 connected directly to the AREF pin (~330mV), I get a value of 2047 instead of the expected 4095. When I connect to a ~70mV voltage it reports as ~40mV.

(The byte_to_binary thing is an attempt to debug this problem, but it doesn't seem to be working quite right. All three bytes are always the same value. Don't know if it's a problem with my code or the device.)

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Sun Aug 23, 2015 6:43 pm

randombrain wrote:
[email protected] wrote: I've not written a driver for this (yet). I could guess one from the data sheet though. It looks very similar to the mcp3004/8 though
I'm a bit confused. I thought all the above discussion between you and itisme was about the 3208?
I'm confused too - I never looked at the history above.
A quick observation of your code ... you're extracting bits from all 3 bytes - it's only as 12-bit device, you only ought to be extracting bits from buf[1] and buf[2] and it's a straightforward pull: value = (buf[1] << 8) | buf[2]. See page 16 of the data sheet.

And it looks like my existing mcp3004 driver would be simple to alter to read this chip, then it fits nicely into the wiringPi analogRead() system.

Send me one and I'll put it into wiringPi.

-Gordon
--
Gordons projects: https://projects.drogon.net/

randombrain
Posts: 5
Joined: Sun Aug 23, 2015 3:44 pm

Re: Fast ADC with MCP3208

Sun Aug 23, 2015 7:07 pm

Okay, that makes sense. I guess I might have been able to figure that out eventually. It's only a four-bit left shift though, not eight.

Problem is when I do that connecting to AREF gives a solid 4095 and connecting to GND (usually) gives 0—but connecting to a different value returns a voltage that's a little more than double what it should be. I suppose that isn't a code problem at that point, though.

Thanks for the help!

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Sun Aug 23, 2015 7:43 pm

randombrain wrote:Okay, that makes sense. I guess I might have been able to figure that out eventually. It's only a four-bit left shift though, not eight.

Problem is when I do that connecting to AREF gives a solid 4095 and connecting to GND (usually) gives 0—but connecting to a different value returns a voltage that's a little more than double what it should be. I suppose that isn't a code problem at that point, though.

Thanks for the help!
It really is an 8-bit shift. The bits you want are in the bottom 4 bits of the byte. Shifting them up by 4 will then crash them into the top 4 bits of the bottom byte.

What I have in mcp3004.c:

Code: Select all

  return ((spiData [1] << 8) | spiData [2]) & 0x3FF ;
All you need to do is copy the mcp3004.[ch] files and change the channel encoding bits in myAnalogRead() and off you go...

(and alter the Makefile and your code)

-Gordon
--
Gordons projects: https://projects.drogon.net/

randombrain
Posts: 5
Joined: Sun Aug 23, 2015 3:44 pm

Re: Fast ADC with MCP3208

Sun Aug 23, 2015 9:41 pm

Okay, I've figured it out... mostly.

I reread the data sheet, especially the timing diagram, and figured out this system:

Code: Select all

CLK: 000 001 002 003 004 005 006 007 | 008 009 010 011 012 013 014 015 | 016 017 018 019 020 021 022 023
MOSI:  X   1   1 chn sel bit   X   X |   X   X   X   X   X   X   X   X |   X   X   X   X   X   X   X   X
MISO:  X   X   X   X   X   X   X  \0 | B11 B10 B09 B08 B07 B06 B05 B04 | B03 B02 B01 B00   X   X   X   X
So now my function looks like this:

Code: Select all

int read_mcp3208_adc (int adcChannel)
{
  unsigned char buff [3] ;

  int adcValue ;

  buff [0] = (0x18 | adcChannel) << 2 ; // 0b00011000 is start bit + single mode select
                                        // then bitwise-or with channel (0-7), then ltshft
  buff [1] = buff [2] = 0 ;             // need to send two more bytes to receive two more

  wiringPiSPIDataRW (SPI_CHANNEL, buff, 3) ;
     
  printf("b1: 0x%x\tb2: 0x%x\n", buff[1], buff[2]) ;    // debug / confirm bitwise ops

  adcValue = (buff [1] << 4) | (buff [2] >> 4) ;        // B11 is 3rd clk after chan sel

  return adcValue ;
}
Now my results are finally in the correct order of magnitude, even for non-extreme values. But the values are consistently 10-15mV too high! Do you have any thoughts on this?
I'll look into modifying your MCP3004.c shortly. Thanks for all the help!

EDIT: Using AREF = Vdd = 3V3 eliminates the error. It also greatly reduces the resolution, but I guess not quite to the point where it's useless... hm. I guess it's definitely a chip/circuit problem at that point.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Mon Aug 24, 2015 10:35 am

randombrain wrote:Okay, I've figured it out... mostly.

I reread the data sheet, especially the timing diagram, and figured out this system:

Code: Select all

CLK: 000 001 002 003 004 005 006 007 | 008 009 010 011 012 013 014 015 | 016 017 018 019 020 021 022 023
MOSI:  X   1   1 chn sel bit   X   X |   X   X   X   X   X   X   X   X |   X   X   X   X   X   X   X   X
MISO:  X   X   X   X   X   X   X  \0 | B11 B10 B09 B08 B07 B06 B05 B04 | B03 B02 B01 B00   X   X   X   X
So now my function looks like this:

Code: Select all

int read_mcp3208_adc (int adcChannel)
{
  unsigned char buff [3] ;

  int adcValue ;

  buff [0] = (0x18 | adcChannel) << 2 ; // 0b00011000 is start bit + single mode select
                                        // then bitwise-or with channel (0-7), then ltshft
  buff [1] = buff [2] = 0 ;             // need to send two more bytes to receive two more

  wiringPiSPIDataRW (SPI_CHANNEL, buff, 3) ;
     
  printf("b1: 0x%x\tb2: 0x%x\n", buff[1], buff[2]) ;    // debug / confirm bitwise ops

  adcValue = (buff [1] << 4) | (buff [2] >> 4) ;        // B11 is 3rd clk after chan sel

  return adcValue ;
}
Now my results are finally in the correct order of magnitude, even for non-extreme values. But the values are consistently 10-15mV too high! Do you have any thoughts on this?
I'll look into modifying your MCP3004.c shortly. Thanks for all the help!

EDIT: Using AREF = Vdd = 3V3 eliminates the error. It also greatly reduces the resolution, but I guess not quite to the point where it's useless... hm. I guess it's definitely a chip/circuit problem at that point.
OK. I'm more awake now and realise the following:
The 3208 is more different to the 3008 that I realised (read the fine manual in more detail!)
You're a bit out.

It also appears that you can delay the start bit to make the output easier to parse.

So if you create buf [0] = 0b0000 0 1 S <d2>
and buf [1] = 0b<d1> <d0> 00 0000

where S is the single/diff bit, and d2..d0 are the channel select bits...

...then do the transfer, you'll end up with:

adcVal = ((buf[2] & 0b00001111) << 4) | buf [3] ;

probably.
-Gordon
--
Gordons projects: https://projects.drogon.net/

randombrain
Posts: 5
Joined: Sun Aug 23, 2015 3:44 pm

Re: Fast ADC with MCP3208

Mon Aug 24, 2015 8:28 pm

[email protected] wrote: You're a bit out.
Where do you think that is?
With the new timing sequence, I have:

Code: Select all

CLK:  000 001 002 003 004 005 006 007 | 008 009 010 011 012 013 014 015 | 016 017 018 019 020 021 022 023
MOSI:   0   0   0   0   0   1   1 chn | sel bit   X   X   X   X   X   X |   X   X   X   X   X   X   X   X
MISO:   X   X   X   X   X   X   X   X |   X   X   X  \0 B11 B10 B09 B08 | B07 B06 B05 B04 B03 B02 B01 B00
And consequently the code is now:

Code: Select all

  spiData [0] = 0x06 | (chan >> 2);     // 0b0000011X is start bit + single-mode select
                                        // then bitor with MSB of ADC channel (0-4 or 0-7)
  spiData [1] = chan << 6;              // two MSB of second byte are last two bits of chn
  spiData [2] = 0;                      // send third byte
  
  wiringPiSPIDataRW (node->fd, spiData, 3);
  
  return ( (spiData [1] & 0x0f) << 8) | spiData [2];// 4 LSB of 2nd byte are 4 MSB of data
                                                    // 3rd byte is 8 LSB of data
But this is essentially the same as last time, and doesn't solve the problem—with AREF = 3v3, the values are correct, within the resolution. With AREF = 0v33, the values are 10-20 mV too high.
As an aside, I seem to be discovering the same thing itisme did: This chip does NOT like high clock speeds. Need to play around with it some more to narrow things down.

EDIT: A re-Read of The Friendly Manual revealed that nonlinearity increases dramatically with lower VREFs, especially at lower Vdd. This guy over at the Arduino forums says he solved the nonlinearity (at least for VREF = Vdd = 5V) with a unity gain amp—something I'll learn about this year in my EE classes, perhaps? I'll look into it. In particular, the last graph he posted seems like it would explain my current problem quite neatly.
I haven't done much more with the clock speed experimentation, but from what I have done it appears that it doesn't like speeds much above 400kHz. This is based solely on the output when a channel is connected directly to VREF, which at high speeds is likely to be 4090 or 4080 or even 4030 instead of the expected 4095.

ProfSparkles
Posts: 5
Joined: Mon Sep 29, 2014 7:36 pm

Re: Fast ADC with MCP3208

Sun Aug 28, 2016 9:45 pm

@Gordon
Did you ever got around to implement the MCP3208 into WirinigPi?
Looked into the git but couldn't find anything.
A big +1 for a proper WiringPi implementation. Would have no problem to send you a few for testing.

yannoo
Posts: 10
Joined: Sun Aug 07, 2016 1:07 am

Re: Fast ADC with MCP3208

Sun Jan 22, 2017 6:20 pm

Hi,

I have begin to work with a MCP 3208 with WirePi.

I have only used this component in 3.3V because I plane to use it on a PiZero on a "low" energy project.

I dream that this can handle the mixing of two stereo inputs in a differential manner (cf. 2x2x2 wires ) or 8 mono inputs in a absolute manner (where all mono inputs have the same GND, so only one wire to handle for each input)

But it's perhaps only a dream because I don't know what is the maximum speed acquisition of the MCP 3208 with the handling of multiples tracks on // :(

Can the WirePi API handling the acquisition of the 8 inputs on the same call, for to greatly reduce the time needed for to handle the acquisition of each track one after the other ?
(cf. make only one call to the wiringPiSPIDataRW() function for to read **alls** tracks in only one step instead to use one call for each track, so 8 calls to wiringPiSPIDataRW() for to convert the 8 analogics inputs into 8 digitals values ...)

@+
Yannoo

yannoo
Posts: 10
Joined: Sun Aug 07, 2016 1:07 am

Re: Fast ADC with MCP3208

Sun Jan 22, 2017 6:52 pm

Hi,

The MCP 3208 can handle the sampling of more than only one track in only one SPI call ?

If yes, can WirePi handling the acquisition of the 8 tracks in // for to greatly reduce the time need for to make the acquisition on the 8 different tracks that can handle the MCP 3208 ?

Cf. make only one call to the wiringPiSPIDataRW() function for to make the conversion of 8 tracks in // instead to make 8 sequentials calls to wiringPiSPIDataRW() for to sequentially handling the analogic -> digital conversion of each track one after the other

@+
Yannoo

fivdi
Posts: 208
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Fast ADC with MCP3208

Sun Jan 22, 2017 7:09 pm

The MCP 3208 can handle the sampling of more than only one track in only one SPI call ?
Yes, it can.
If yes, can WirePi handling the acquisition of the 8 tracks in // for to greatly reduce the time need for to make the acquisition on the 8 different tracks that can handle the MCP 3208 ?
WiringPi doesn't appear to have a function that can be used to perform multiple transfers with a single call.

yannoo
Posts: 10
Joined: Sun Aug 07, 2016 1:07 am

Re: Fast ADC with MCP3208

Sun Jan 22, 2017 7:30 pm

WiringPi doesn't appear to have a function that can be used to perform multiple transfers with a single call.
This can perhaps to be added :)

Theorically, this extension can have the power to divide by 8 the time spended by the Raspberry Pi on the total number of wiringPiSPIDataRW () calls for to handle the acquisition of 8 differents channels in // with the MCP 3208 ...

User avatar
DougieLawson
Posts: 35358
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Fast ADC with MCP3208

Sun Jan 22, 2017 7:34 pm

yannoo wrote:
WiringPi doesn't appear to have a function that can be used to perform multiple transfers with a single call.
This can perhaps to be added :)
Send an email to Gordon if you want him to consider that option.
http://wiringpi.com/contact/
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast ADC with MCP3208

Sun Jan 22, 2017 7:38 pm

yannoo wrote:Hi,

The MCP 3208 can handle the sampling of more than only one track in only one SPI call ?

If yes, can WirePi handling the acquisition of the 8 tracks in // for to greatly reduce the time need for to make the acquisition on the 8 different tracks that can handle the MCP 3208 ?

Cf. make only one call to the wiringPiSPIDataRW() function for to make the conversion of 8 tracks in // instead to make 8 sequentials calls to wiringPiSPIDataRW() for to sequentially handling the analogic -> digital conversion of each track one after the other

@+
Yannoo
the mcp3208 is a simple ADC device. It supports up to 8 channels, however there is only ONE ADC in the chip, so it can only sample one channel at a time. If you are after stereo audio sampling, then there will be a time difference between the channels. You need to sample each channel in-turn, I can not see a way to sample all channels in a single transaction. The transision of CS going low is what resets the internal state machine and starts the sampling.

However, there is a bigger problem - wiringPi uses the standard Linux SPI device driver and this has a relatively large latency between samples. to the extent that you can only get about 8-10K samples per second. you can bit-bang the SPI hardware or use alternative drivers such as pigpio to get higher rates.

I have an mcp3208 just not had the time or energy to write some code for it.

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “Automation, sensing and robotics”