Yes I did. See here although it was a bit of a bear to work with.
https://github.com/tom-biskupic/LabPSU/blob/master/Firmware/LabPSU/AD7705ADC.cpp
Code is a bit rough-and-ready and uses my own SPI code (long story).
I had a similar experience to you for a while and found I had damaged my device. Swapped in another one and it all worked.
In the immortal words of AvE, IT VURRRKS!. The two channels now work independently!
So this very clearly demonstrates that the
Adafruit kerrydwong/AD770X library does not work properly!
My clock crystal is 4.9152 Mhz, but using CLOCK_4_9152 doesn't work, so I have to use CLOCK_2 for some reason, any idea why?
Many thanks!
Here's the Arduino IDE compatible code that I used with your library:
/*
Parts of this code and the entirety of the SPI and AD7705ADC libraries have been taken from the repo of tom-biskupic
https://github.com/tom-biskupic/LabPSU
*/
#include <AD7705ADC.h>
const float RANGE_TO_5V = 0.00007629510948348210879682612344549;
const float RANGE_TO_5000mV = 0.07629510948348210879682612344549;
const int ADC_SS_PIN = 0;
const int ADC_DATA_READY_PIN = 4; // PORTD
AD7705ADC m_adc(ADC_SS_PIN, ADC_DATA_READY_PIN);
const AD7705ADC::Channel VOLTAGE_ADC_CHANNEL = AD7705ADC::CHANNEL_0;
const AD7705ADC::Channel CURRENT_ADC_CHANNEL = AD7705ADC::CHANNEL_1;
void initADC()
{
//
// We run the ADC in bipolar mode so we can get the full 0..5V range.
// The AIN- is tied to the reference so the input is a bipolar number
// relative to that.
//
// Because of the bipolar requirement we can't use gain.
// I am using a 2MHz crystal which means clockdiv is 1.
// An update rate of 50Hz or less is fine so filter select is 0
//
m_adc.reset();
m_adc.setClockRegister(AD7705ADC::CLOCK_2, 0);
m_adc.setSetupRegister(
VOLTAGE_ADC_CHANNEL, // Channel
AD7705ADC::AD7705ADC::MODE_NORMAL, // CAL mode
AD7705ADC::GAIN_1, // Gain = 1
AD7705ADC::UNIPOLAR, // Polarity
false, // Not buffered
false); // F Sync off
m_adc.reset();
m_adc.setSetupRegister(
CURRENT_ADC_CHANNEL, // Channel
AD7705ADC::AD7705ADC::MODE_NORMAL, // CAL mode
AD7705ADC::GAIN_1, // Gain = 1
AD7705ADC::UNIPOLAR, // Polarity
false, // Not buffered
false); // F Sync off
}
uint16_t readADC(const AD7705ADC::Channel channel)
{
m_adc.reset();
uint16_t value = m_adc.getValue(channel);
return value;
}
void setup()
{
Serial.begin(9600);
initADC();
}
void loop()
{
Serial.print(readADC(VOLTAGE_ADC_CHANNEL)*RANGE_TO_5000mV * 2,0);
Serial.print("mV :");
Serial.print(readADC(CURRENT_ADC_CHANNEL)*RANGE_TO_5000mV * 2,0);
Serial.println("mA");
delay(1000);
}