Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple chips in series not working. #5

Open
jsmoconnor opened this issue Feb 23, 2023 · 21 comments
Open

Multiple chips in series not working. #5

jsmoconnor opened this issue Feb 23, 2023 · 21 comments

Comments

@jsmoconnor
Copy link

Hi. I have used the library successfully on one chip, but when I put 2 in series, they both output the same data.
I am using the supplied example programs.

Any thoughts? Thanks
James

@peterpolidoro
Copy link
Member

It has been a couple of years since I messed with this library, I cannot remember if I ever actually tested putting several in series.

So you set the chip_count parameter to 2 in the call to setup? Does it have the appropriate response when you call getChipCount and getChannelCount? Then you called setAnalogValue with the channel and value?

@jsmoconnor
Copy link
Author

Thankyou for your reply. I have tested the getChipCount and the getChannelCount, they are worrking correctly.
I am ending up with the last 4 values sent to the DACs across both chips. I have tested the chips individually and they worrk fine.
any more thoughts greatly appreciated.

@peterpolidoro
Copy link
Member

Can you please post your code so I can take a look to see if I can figure it out? Thanks.

@jsmoconnor
Copy link
Author

`#include <AD57X4R.h>
#include <Streaming.h>

const size_t CHIP_SELECT_PIN = 10;
const size_t LOAD_DAC_PIN = 3;
const size_t CLEAR_PIN = 4;
const long BAUD = 115200;
const long ANALOG_CHANNEL = 0;

const int LOOP_DELAY = 500;
const size_t ANALOG_VALUE_INC = 10;

AD57X4R dac = AD57X4R(CHIP_SELECT_PIN);
long analog_value = 0;

void setup()
{
// PC communications
Serial.begin(BAUD);
// Initialize DAC
dac.setLoadDacPin(LOAD_DAC_PIN);
dac.setClearPin(CLEAR_PIN);
dac.setup(AD57X4R::AD5724R,2); // this is where you set the type/resolution of the DAC chip
dac.setOutputRange(0,AD57X4R::UNIPOLAR_10V);
dac.setOutputRange(1,AD57X4R::UNIPOLAR_10V);
dac.setOutputRange(2,AD57X4R::UNIPOLAR_10V);
dac.setOutputRange(3,AD57X4R::UNIPOLAR_10V);
dac.setOutputRange(4,AD57X4R::UNIPOLAR_10V);
dac.setOutputRange(5,AD57X4R::UNIPOLAR_10V);
dac.setOutputRange(6,AD57X4R::UNIPOLAR_10V);
dac.setOutputRange(7,AD57X4R::UNIPOLAR_10V);

uint8_t Result = dac.getChipCount();
uint8_t Result1 = dac.getChannelCount();
Serial << "Chip Count: " << Result << ", Channel Count: " << Result1 << endl;
}

void loop()
{

dac.beginSimultaneousUpdate();
dac.setVoltage(0,1);
dac.setVoltage(1,2);
dac.setVoltage(2,3);
dac.setVoltage(3,4);
dac.setVoltage(4,5);
dac.setVoltage(5,6);
dac.setVoltage(6,7);
dac.setVoltage(7,8);
dac.simultaneousUpdate();

delay(LOOP_DELAY);

dac.beginSimultaneousUpdate();
dac.setVoltage(0,0);
dac.setVoltage(1,0);
dac.setVoltage(2,0);
dac.setVoltage(3,0);
dac.setVoltage(4,0);
dac.setVoltage(5,0);
dac.setVoltage(6,0);
dac.setVoltage(7,0);
dac.simultaneousUpdate();
delay(LOOP_DELAY);
}

Thanks James

@peterpolidoro
Copy link
Member

Ah yes, I remember now. I did not finish implementing the multi-chip code since I did not have a hardware setup to test it with.

I could take a shot at fixing the code, but I do not have a way to test it at the moment. If I start an experimental branch in this repository, would you be able to download the repository and test code in that branch with your hardware setup?

@jsmoconnor
Copy link
Author

Hi Peter
Yes I would be happy to test the new code.
My set up is 2 DAC's.

Thanks
James

@peterpolidoro
Copy link
Member

Ok I created a new branch named multichip and added an example named MultiChip. I have not yet fixed the library. You might want to verify that this example shows the same flawed output that you saw in your code, then I will work on the fix.

@jsmoconnor
Copy link
Author

Hi Peter
I have tested the MultiChip example.
Outputs are
DAC 1
Out 1 = 4V
Out 2 = 5V
Out 3 = 6V
Out 4 = 7V
DAC 2 : SDIN taken from DAC 1 SDOUT
Out 1 = 4V
Out 2 = 5V
Out 3 = 6V
Out 4 = 3V

I have noticed before that Out 4 of DAC 2 is not what you would expect.
I have swapped the DACs around and the same thing occurs.

thanks
James

@peterpolidoro
Copy link
Member

Ok I made some initial code changes. It compiles, but it may or may not work properly. Give it a try when you have a chance and see what happens. Thanks!

@jsmoconnor
Copy link
Author

Hi Peter
I installed the new library.
Outputs are
DAC 1
Out 1 = 4V
Out 2 = 5V
Out 3 = 6V
Out 4 = 7V
DAC 2 : SDIN taken from DAC 1 SDOUT
Out 1 = 4V
Out 2 = 5V
Out 3 = 6V
Out 4 = 7V

As an aside, is there an easy way to run 2 libraries ? Currently I'm just replacing the .cpp and .h files in the AD57X4R library..
Thanks
James

@peterpolidoro
Copy link
Member

Thanks. I will look over my code to see if I can find where I made mistakes.

Just to double-check, you are using code in the multistep branch correct?

What do you mean by run two libraries? You can clone the git repository directly into your Arduino library directory and then just switch back and forth between branches. You probably have to restart the IDE after switching to another branch.

I also use symbolic links to change libraries within that directory, but I do not know if your operating system supports that.

@jsmoconnor
Copy link
Author

Hi Peter.
I think my test's this morning where invalid.
I have reinstalled your new library and am running the multichip example.
I now have no outputs from any of the DAC channels.
Checking with a scope I have Clock and Data signals.

Thanks
James

@peterpolidoro
Copy link
Member

I found at least one bug in my code and I think I fixed it. Can you please update your repository and try it again using the MultiChip.ino example in the multichip branch? Thanks!

@jsmoconnor
Copy link
Author

jsmoconnor commented Mar 6, 2023 via email

@peterpolidoro
Copy link
Member

Oh no, I hope your ankle gets better. No worries about a delay, I will pick it up and keep working on it whenever you have a chance to test it out.

@jsmoconnor
Copy link
Author

Hi Peter

Finally got back on to this.
There is a problem when trying to compile the code.
Please see reported error below.

I tried the suggested alternative that still gave a different compilation error.

I have tested the DAC's by using a simple direct SPI program. The hardware is working fine.

Thanks
James

c:\Users\jsmoc\Documents\Arduino\libraries\AD57X4R\src\AD57X4R.cpp: In member function 'void AD57X4R::writeMosiDatagramToChip(int, AD57X4R::Datagram)':
c:\Users\jsmoc\Documents\Arduino\libraries\AD57X4R\src\AD57X4R.cpp:504:7: error: 'datagram_array' was not declared in this scope
datagram_array[chip_n] = mosi_datagram;
^~~~~~~~~~~~~~
c:\Users\jsmoc\Documents\Arduino\libraries\AD57X4R\src\AD57X4R.cpp:504:7: note: suggested alternative: 'mosi_datagram_array'
datagram_array[chip_n] = mosi_datagram;
^~~~~~~~~~~~~~
mosi_datagram_array

@peterpolidoro
Copy link
Member

Ok fixed, you can try it again.

@peterpolidoro
Copy link
Member

I went ahead and merged the changes into the main branch. Please let me know if you are still having problems. Thanks!

@jsmoconnor
Copy link
Author

jsmoconnor commented Feb 11, 2024 via email

@peterpolidoro peterpolidoro reopened this Mar 8, 2024
@peterpolidoro
Copy link
Member

I am going to need to rig up some hardware so I can debug the code. If you can look at the signals with an oscilloscope and give me some ideas about what might be going wrong then I might be able to fix it, but it is hard for me to know what is happening without being able to test it myself.

@peterpolidoro
Copy link
Member

Another person found some bugs in my code. I still have not been able to test them on real hardware, but if you ever have a chance, please test it again and see if it works now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants