Go Down

Topic: Library for AD5321, problem (Read 754 times) previous topic - next topic

natanel

Hi
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

but
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

noticed
_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

thanks

robtillaart

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

example:
Code: [Select]

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

Rationale:
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
Code: [Select]

public byte AD5235::restoreRdac(byte nDac, value)
{
  enable();
  command( RESTORE_EEMEM_TO_RDAC_COMMAND, nDac, 0);
  disable();

  return OK;
}

// HAL LAYER
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 - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up