TM7705 / AD7705 getting both channels to work with Arduino - Page 1
Forum section: electronics / projects

author: ziplock9000
author_rank: Regular Contributor
timestamp: October 01, 2018, 05:15:43 pm
content: I followed the instructions on this page:https://www.instructables.com/id/Arduino-16-bit-500SPS-Dual-Channel-DAQ/Using KDW's revised library:http://www.kerrywong.com/2012/04/18/ad7705ad7706-library-revisited/When supplying a voltage to Channel 1 only. Channel 1 shows a wrong value intermittently, Channel 2 shows zeroWhen supplying a voltage to Channel 2 only. Channel 2 shows a meaningful value as does Channel 1!There only seems to be one library out there that has some issues, has anyone been able to get both channels working?I've checked SCK and it's at a solid 250KhzDRDY isn't connected to anything.. could that be an issue?

author: tombi
author_rank: Regular Contributor
timestamp: October 03, 2018, 04:03:13 am
content: 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.cppCode 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.

author: ziplock9000
author_rank: Regular Contributor
timestamp: October 03, 2018, 09:18:23 am
content: Thanks mate. I'll have a look at your library.

author: ziplock9000
author_rank: Regular Contributor
timestamp: October 03, 2018, 01:14:06 pm
content: Quote from: tombi on October 03, 2018, 04:03:13 amIn the immortal words of AvE, IT VURRRKS!. The two channels now work independently!So this very clearly demonstrates that theAdafruitkerrydwong/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:Code:/*Parts of this code and the entirety of the SPI and AD7705ADC libraries have been taken from the repo of tom-biskupichttps://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; // PORTDAD7705ADC 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, // ChannelAD7705ADC::AD7705ADC::MODE_NORMAL, //CAL modeAD7705ADC::GAIN_1,//Gain = 1AD7705ADC::UNIPOLAR,//Polarityfalse,//Not bufferedfalse);//F Sync offm_adc.reset();m_adc.setSetupRegister(CURRENT_ADC_CHANNEL, // ChannelAD7705ADC::AD7705ADC::MODE_NORMAL, //CAL modeAD7705ADC::GAIN_1,//Gain = 1AD7705ADC::UNIPOLAR, //Polarityfalse,//Not bufferedfalse);//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);}

author: tombi
author_rank: Regular Contributor
timestamp: October 03, 2018, 01:28:06 pm
content: Hmm - no not really.From looking at the datasheet it should be CLOCK_4_9152Might be a bug in my code but I can't see it right now.Glad it worked though! I also found the part pretty bloody slow although I didn't mess with the filters too much.Tom