I have 2 mcp3208 adc’s. on a custom bd. The 1st (ch0 - ch7) is selected by Pin 10, the second by pin 9.
(ch8- 15).
When i change to the second adc I subtract 8 from the channel (0-15). I also change the select pin
AH_MCP320x ADC_SPI() and disble the select pin from the other ADC.
I get valid data out but…
When I run the code attached the printout values repeat 0 and 8 1 and 9 all the way up to 7 and 15.
Appreciate a look .
Thanks
/ DATAOUT 11 //MOSI
// DATAIN 12 //MISO
// SPICLOCK 13 //Clock
#include "AH_MCP320x.h"
#include <SPI.h>
// tests ch 0 to 15 of the Robtrol clone
//outputs on pin 2 tx
int ADCValue = 0;
AH_MCP320x ADC_SPI(10); //Declaration required
void setup()
{
Serial.begin(9600);
}
void loop(){
Serial.println (" adc lib test");
for(int i=0;i<17;i++){
int val = ADCread(i);
Serial.print ("ch");
Serial.print("\t");
Serial.print (i);
Serial.print("\t");
Serial.print ("value");
Serial.print("\t");
Serial.println (val,HEX);
}
}
int ADCread(int channel){
int ADCValue = 0;
if (channel < 8 )
{
bitSet(PORTB,1); //DELESECT
AH_MCP320x ADC_SPI(10); //select adco
}
else
{
bitSet(PORTB,2); //DELESECT
AH_MCP320x ADC_SPI(9); //select adc1
channel-= 8;
}
ADCValue = ADC_SPI.readCH(channel); //read analog value from IC (SPI mode)
return ADCValue;
}