Post Go back to editing

AD5940_BATImpedance Files

Category: Software
Product Number: AD5940
Software Version: 1

After writing c code for AD5940 SPI drivers that can read & write to the ad5940 registers, I am now trying to clone the necessary files to implement the full AD5940_BATImpedance system.
However while I can write my own "hardware porting file" code to provide the all the necessary low level SPI functions such as reading and writing to registers there appears a significant issue with integrating the core ad5940.c and ad5940.h files as there is confusion in regards to the functions defined in these files. 

For example the ad5940.h file suggests that only these functions need to be implemented for specific hardware controllers ?

void      AD5940_CsClr(void);
void      AD5940_CsSet(void);
void      AD5940_RstClr(void);
void      AD5940_RstSet(void);
void      AD5940_Delay10us(uint32_t time);
/* (Not used for now.)AD5940 has 8 GPIOs, some of them are connected to MCU. MCU can set or read the status of these pins. */
void      AD5940_MCUGpioWrite(uint32_t data);   /*  */
uint32_t  AD5940_MCUGpioRead(uint32_t);
void      AD5940_MCUGpioCtrl(uint32_t, BoolFlag);
void      AD5940_ReadWriteNBytes(unsigned char *pSendBuffer,unsigned char *pRecvBuff,unsigned long length);
/* Below functions are frequently used in example code but not necessary for library */
uint32_t  AD5940_GetMCUIntFlag(void);
uint32_t  AD5940_ClrMCUIntFlag(void);
uint32_t  AD5940_MCUResourceInit(void *pCfg);

However there are many other functions that are dependent on SPI functions that are not represented in the above .. these include the following ...
/* 1. Basic SPI functions */
void      AD5940_WriteReg(uint16_t RegAddr, uint32_t RegData);
uint32_t  AD5940_ReadReg(uint16_t RegAddr);
void      AD5940_FIFORd(uint32_t *pBuffer,uint32_t uiReadCount);
void      AD5940_HWReset(void);       /* Do hardware reset to AD5940 using RESET pin */
void      AD5940_Initialize(void);
static unsigned char AD5940_ReadWrite8B(unsigned char data);
static uint16_t AD5940_ReadWrite16B(uint16_t data);
static uint32_t AD5940_ReadWrite32B(uint32_t data);

Can someone please clarify exactly what functions in the ad5940.c and ad5940.h files need to be carried out externally in my "hardware porting file"

Thank you 
Collin.



  • Further to my investigation I find that the ad5940.c and ad5940.h files are bloated up with unnecessary complexities/functions with RAW SPI functions that are not required and will not work because they do not follow the ADI SPI protocol requirements. They don’t send SPICMD_SETADDR, SPICMD_READREG, or SPICMD_WRITEREG — which are mandatory protocol requirements for AD5940 register access, so what real function or purpose do they actually perform? Are they required or used by the higher level applications ( AppBATImpedance, etc.)  I cannot see how as these APP's should work even with these unnecessary functions, especially working outside the ADuCM355 ecosystem which relies on manually generated SPI CS logic unlike standard SPI control where the CS line is automatically controlled in the SPI transactions.

    The AD5940 SDK files (ad5940.c/.h) appear riddled with many abstractions that don’t match the actual ADI SPI protocol requirements? Its difficult to know which functions are actually needed. 

    Also functions are defined for 32bit writes to registers but the datasheet lists no 32 bit registers at all. They way I see it the only required RAW hardware functions that are needed to be provided are 
    1) 
    uint32_t ad5940_read_reg32(uint16_t addr)  .... read 32 bit data from 16bit address
    2) 
    void ad5940_write_reg16(uint16_t addr, uint16_t value)  ... write 16bit data to 16bit address since the chip only uses 16bits
    3)   ad5940_read_fifo()  ?

    I do not see the need for other functions .. can someone shed a light of these aspects?

    Thanks for your help.
    Collin

  • Hi,  ,

     will be able to assist you on this request.

    Best regards,
    Christian

  • Whatever functions you call in your main.c (example : main.c) are to be defined in your "hardware porting file".

    All the AD5940 functions defined in ad5940.c need to be defined in your "hardware porting file".

  • Thanks Akila,

    I already understood these matters, my hardware porting functions all work perfectly fine, that was never really an issue. I have now successfully completed this project and it is now working 100% perfectly fine now with improved response accuracy and repeatability of better than <1%. That said the AD5940 is not suitable for frequencies below 10Hz or much above 50kHz. 

    The main cause of the problems/issues I had was Linux timing issues (-50%) because the AD5940 sequencer/FIFO approach relies so much on precise timing with interrupts etc. The ADI Example Code and Quality ( -25%) where Filter/DFT setting transitions are not documented, FIFO overflow conditions not handled and "magic numbers" for settling times are empirical, and not explained.

    The AD5940 Chip Design (- 25%),  apart from the poor documentation the chip itself is well-designed, but, the sequencer is powerful but complex, the FIFO is way too small (4KB) and easy to overflow especially at low frequencies. The DFT at low frequencies with high OSR takes 20+ seconds - the examples don't emphasize this and the chip expects a "real-time" host.

    To overcome these problems I have completely re-written the Battery impedance ADI code to work completely in "manual mode, and it works in all functionality without any sequencer or FIFO" and also I have strengthened the very poor RCAL coding. My control method takes about the same execution time without using the faulty ADI sequencer and FIFO coding, so there is no lost time, the timing is more defined by the measurement parameters than anything else as you may well understand.

    The built-in AD5940 sequencer/FIFO isn't broken - it does work on dedicated microcontrollers. It's just the wrong approach for Linux or other O/S, but there are ways to overcome this as I have proved.

    That said I have now moved on from the AD5940 chip, I don't believe it has any particular use case in my projects, it doesn't have the performance, so I am in the process of designing a far superior EIS system based on discrete hardware. 

    Thanks again for your response, hope you had a great break.
    Regards,
    Collin







Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.