Pages: [1]   Go Down
Author Topic: Library for AD5321, problem  (Read 698 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just made library for AD5321 digital potentiometer

I am able to send commands and get potentiometer to change (A-W-B)
I am able to track and print that all commands are sent as required

I am not able to get the right response from reading command
it just not returning the values but just keep repeating the request

from who of you interested or have some background with this device
attached is the code with example problem

_write sent 33 1 2 get B0 0 9 // sending writ to EEROM address 3, value 102 geting last change potentiometer  command - OK
_write sent 93 0 0 get 33 1 2 // asking to read from EEROM addres 3, geting last command - OK
_write sent 0 0 0 get 93 0 0 // sending NOP but getting the last command and not EEROM value, should be 93 1 2 - ERROR

remarks: ignore file names AD5325, it was made for AD5321

attached files


* AD5235.pde (0.98 KB - downloaded 5 times.)
* AD5235.cpp (4.98 KB - downloaded 15 times.)
* AD5235.h (1.65 KB - downloaded 12 times.)

Global Moderator
Offline Offline
Shannon Member
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The cpp code can be made a bit more neat by using your own defined functions:

byte AD5235::restoreRdac(byte nDac, int value)
  enable(); <<<<<<<<<<<
  _write( RESTORE_EEMEM_TO_RDAC_COMMAND, nDac, 0);  <<< should the 0 be value?
  disable(); <<<<<<<<<<<

  return OK;

It is not clear in this function why it has the parameter value.

Normally I build such a library in 3 layers to keep it maintainable.

1) Class public layer - These are to be called you the user of the lib
2) Class private layer - these are helpers to implement the public methods
3) Hardware abstraction layar

3) is the only place that contains IO with the hardware e.g. read/writes on pins etc, so if there is a change in the HW you only need to change it there
2) keeps the inner logic of the class hidden for the user
1) makes the class usable.

The above function would then be written as
public byte AD5235::restoreRdac(byte nDac, value)

  return OK;

private byte AD5235::command(...) ...
private byte AD5235::enable() ...
private byte AD5235::disable() ...

command is a wrapper around the _write of course.

my 2 cents

Rob Tillaart

Nederlandse sectie -,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: