Can someone fix this code? Controlling voltage of a Digital Potentiometer(AD8400) using LM317 voltage regulator through Arduino Uno (such that the current remains constant)
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vinayak
le 25 Août 2022
Déplacé(e) : Joel Van Sickel
le 28 Sep 2022
I'm working on a project where my setup should receive a steady Current(I). I'm using AD8400 Digital Potentiometer and LM317 voltage regulator connected to an Arduino Uno. This circuit is connected to my setup which is connected to a multimeter. The multimeter displays the voltage(V) and the Current(I) values, where the Current(I) fluctuates because of the built up resistance, so I was trying to write a code to control the voltage of the digital potentiometer(AD8400) such that the Current reading on the multimeter remains constant (say 4mA).
Here is a link to the datasheet for the device I am trying to use: https://www.analog.com/media/en/technical-documentation/data-sheets/AD8400_8402_8403.pdf
Here is a circuit diagram describing the circuit connections of LM317 voltage regulator:

In the circuit diagram the Potentiometer is represented by 'R'.
I wrote this code to control the voltage but there is some issue in it. And I couldn't figure out how to change the voltage such that the Current(I) remains constant.
clear all;
a=arduino('com3','Uno','Libraries','SPI');
d_pot = device(a, 'SPIChipSelectPin', 'D10','bitrate',1);
d=a,d_pot;
value=200;reverse=0;
for i=1:10
if value>=200
reverse=1;
end
if value<=200
reverse=0;
end
if reverse==0
value=value+1;
else
value=value-1;
end
writeRead(d,50,value);
pause(0.1)
end
Any input would be really appreciated. Thank you!
0 commentaires
Réponse acceptée
Walter Roberson
le 25 Août 2022
Déplacé(e) : Joel Van Sickel
le 28 Sep 2022
if value>=200
reverse=1;
end
if value<=200
reverse=0;
end
If value is exactly 200, then you set reverse to 1 and then you set it back to 0.
6 commentaires
Walter Roberson
le 27 Août 2022
Déplacé(e) : Joel Van Sickel
le 28 Sep 2022
The AD8400 appears to also be SPI, so programming it would appear to be much the same.
The manual at https://www.analog.com/media/en/technical-documentation/data-sheets/ad8400_8402_8403.pdf implies you might need to send a 10 bit data value -- though if you are using the single-output version then it looks to me as if the two high bits would always be 00
The device has a built-in resistance that is added to D/256 * resistance_span -- so if you wanted to control the resistance completely linearly you would need to subtract the constant resistance from the target resistance, and divide by the resistance span and multiply by 256 to get the value to send.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!