PICAXE to MCP6S21/8 PGA

Parramatta

New Member
I'm trying to set up a cct to read in sensors to the adc's on a 40x. The sensors have really small outputs (Thermo coupler, battery temp etc.) so I'm trying to use a PGA. I'm using the MCP6S21/8 and they utilise a SPI. Has anyone had any experience with this type of set up? Any help would be greatly appreciated!!!
 

Eclectica

Member
Hi Parramatta,

Your approach looks like an elegant alternative method to using rail-rail instrumentation op-amps.:cool:

The MCP6S21 looks like a good choice with gain programmable from 1-32. In particular the MCP6S28 would give you 8 mux selectable inputs (via SPI) which you could read into one ADC port on the 40X. This would work out a lot cheapr (and simper - PCB wise) than using instrumentation op-amps [possibly slight loss of accuracy though?]. Also give you more effective analogue inputs.

Firstly let me say I haven't actually used one of these, but...

I believe that using the 40X you would use the dedicated spi pins, and then set up the SPI using hpisetup, followed by issuing the appropriate SPI commands using hspiout e.g. instruction register to set gain, and then channel. There is some sample SPI code - [you've probably already seen it] - on manual2 p68.

Then it would be a matter of reading the ADC pin on the 40X using the readadc10 command.

It goes without saying that careful PCB layout and cabling on the analogue inputs is important here in order to avoid extra errors in the readings.

Hopefully this has helped and good luck trying it out!

Michael
 

hippy

Ex-Staff (retired)
I've not used these but the SPI control looks to be fairly standard. I would suggest bread-boarding a test setup first just to make sure you can control the device. I'd start with bit-banged SPI, move up to using SPIOUT, then onto HSPIOUT.

That may seem like a lot of unnecessary work when you could simply use HSPIOUT to start with, but if you go that way and it doesn't work then you're left scratching your head wondering why and an oscilliscope / logic analyser is the only tool you'll have for debugging.

It's a bit like tight-rope walking - maybe you'll get lucky first time out, twenty feet up, no safety net, but it's usually best to practice standing on one leg first then move up to the next level. Once you have basic bit-banging working, any problems in moving to SPIOUT or to HSPIOUT are isolated to having not got the configuration right because you know what you are meant to be sending does work. If you start with SPIOUT/HSPIOUT and it doesn't work you don't know if you've got the configuration wrong, the data to send wrong, or both and you'll have a tough time debugging that and will probably resort to bit-banging anyway to take configuration issues out of the equation.

If you're familiar with SPI then you can choose to dive in at the deep end as you'll be more knowledgeable of what can go wrong.
 

MFB

Senior Member
No substitute for the real thing

The MCP6S21/8 is certainly a useful device for conditioning single-ended signals, but for differential signals (sensor bridge outputs etc) it is in no way a substitute for a dedicated instrumentation amplifier. If you have a short run between the sensor and the MCP6S21/8 then you might get away with using the approach outlined in Microchip application note AN251. Basically this uses two mux inputs for either side of the bridge but then combines them as a differential signal in the micro.

However, the main challenge when using low level differential output sensors is often rejecting common mode noise and drift whilst amplifying the required signal, and this is just the difficult task that the ‘instrumentation’ amplifier was designed for. They even come in programmable gain versions.
 

Parramatta

New Member
G'day again Guys,

I have the PGA's working but I'm having trouble controlling them with the SPI from the PICAXE. The manual does not give a clear indication of the pins being used for the 40X1. Any additional information would be greatly appreciated.
 

Parramatta

New Member
Thanks for that pete. I have got the PGA's working through bit banging with the spiout command. I can't seem to get it to work using the hspiout.
 

womai

Senior Member
I am using those amplifiers in my Picaxe based oscilloscope. Work fine. The hardware SPI pins were already taken (for I2C), so I do SPI with the software SPI functions of the Picaxe 28X1: SPI_CLK = Output 2, SPI_DATA = Output 3. The chip select is driven through an I/O expander, but you can hook that up to any I/O oir output pin - don't forget to pull it low to enable SPI communication, and pull it high after sending the data to latch in the data.

Here is the code to set channel and gain:

Code:
set_gain:

    b_pga_channel = b_param1
    b_pga_instruction = %01000000 ' set gain
    b_pga_data = b_param2

    gosub pga_command

return

pga_command:
    ' PGA channel has the channel number (1 or 2)
    ' PGA_data and PGA_instrunction hold data byte and isntruction byte to send

    ' enable PGA
    if b_pga_channel = 1 then
        writei2c IOEXP_PGA1_CSn,(0)
    else
        writei2c IOEXP_PGA2_CSn,(0)
    endif    

    spiout SPI_CLK, SPI_DATA, MSBFirst_L, (b_pga_instruction,b_pga_data)
    
    ' latch data into PGA, enable PGA
    if b_pga_channel = 1 then
        writei2c IOEXP_PGA1_CSn,(1)
    else
        writei2c IOEXP_PGA2_CSn,(1)
    endif    
    
return
Hope that helps

Wolfgang
 

Parramatta

New Member
Thanks for your help everybody. I think I'll stick with the spiout route. This seems to be working fine and suits my requirements.

Jesse
 
Top