Post Go back to editing

AD5941 Can AD594x continuously and simultaneously generate a sine wave and process the data via ADC? if yes, can I have the code in BIA formation, please?

Category: Software
Product Number: AD5941
Software Version: AD5940 EXAMPLES

Referring to this question:

 is there way to use ad5940 without interrupt or GPIO interrupt pin? 

I'm not sure if the author ever got it to work, anyway, so I have a requirement to generate the sinewave of programmable freq continuously in BIA setup (4 wire setup), and continuously get the ADC data, not stopping ever, till I manually stop it.

The current BIA example uses a sequencer, and the WG stops and starts all the time, as I cheded on the oscilloscope. I'm okay with the interrupt to trigger to notify if the data is ready, but not sure if I should use the sequencer? I tried to write the example myself without the sequencer, but it didn't work, and hence I'm here asking for help.

So, here's a question: Can AD594x continuously and simultaneously generate a sine wave and process the data via ADC? if yes, can I have the code in BIA formation, please?

Parents
  • Hi,

    You may just remove the sleep command from all sequences in BIA code.

    That is remove the below line wherever it is called:

    AD5940_EnterSleepS();

    Also inside measure sequence, WG block is turned off. You may remove the red part below:

    AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG|AFECTRL_ADCPWR, bFALSE);  /* Stop ADC convert and DFT */

  • Thanks for the reply. I implemented the changes, however, the WG stops/starts frequently, please see the attached screenshot. Could you share the code that you got it to work?

  • Thanks for the reply, I implemented the above code, not only was I not getting the WG, but the ADC stopped working as well. There was a small typo in the code, and your attached figure shows it's not a sine wave, Im sorry am I missing something here?

    I also have a few questions regarding the code:

    1.  If the number of data points is -1 (AppBIACfg.NumOfData = -1;), why are we calling the Measure() function again in AppBIAISR()?

    2. Why are we stopping the ADC and DFT in the Measure function?

    AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_ADCPWR, bFALSE); /* Stop ADC convert and DFT */

    I wanted both the WG and ADC to go on till I manually pull the plug or send a stop command. For now I don't care for the power requirements, so might as well use high-power mode.

    3. Why are we floating the switches at the end of the Measure() function?

    If we are, there is no way we will get a continuous WG as we have floated the switches!

    4. Why are we toggling the GPIO_Pin2 in the Measure Function?

    5. Lastly, If we are not using the Sequencer for Measure function can we remove it entirely from the config function as well and thus from the code as well? I'm very happy to use SPI for everything,

  • Hi,

    Apologies for the typo.

    Infact, Waitclks must be scaled as below:

    AD5940_Delay10us(WaitClks/100); 

    instead of 

    AD5940_Delay10us(WaitClks);

    1) Since in the above code, wakeup timer is not used, measurement is not periodically triggered, Measure() need to be called for each measurement, hence called inside AppBIAISR().

    2) ADC must be turned on only for sampling the input. It should not be kept on always. Otherwise data fifo will be filled with junk data.

      In the above code, WG is kept on always.

    3) Floating switches after measurement is a good practice but optional. It is not reflected in the waveform captured above because switches are closed for a negligibly small duration.

    4) Toggling the GPIO_Pin2 helps check that measurement is happening and also to keep count of measurements, by monitoring GPIO2.

    5) Measure() is not using sequence in the above code as measurement is not required to be triggered by timer and sequence can run only at 32kHz clock.

    Hence its sequence is already removed in the above code.

    Below is the BIA measurement output I got for the above code for a 100 Ohm resistive load:

    Hello AD5940-Build Time:11:10:34
    Freq:50000.00 RzMag: 99.953804 Ohm , RzPhase: 1.029252 
    Freq:50000.00 RzMag: 99.953979 Ohm , RzPhase: 1.020536 
    Freq:50000.00 RzMag: 99.954971 Ohm , RzPhase: 1.018610 
    Freq:50000.00 RzMag: 99.958328 Ohm , RzPhase: 1.019177 
    Freq:50000.00 RzMag: 99.960709 Ohm , RzPhase: 1.021670 
    Freq:50000.00 RzMag: 99.958328 Ohm , RzPhase: 1.019177 
    Freq:50000.00 RzMag: 99.951485 Ohm , RzPhase: 1.041997 
    Freq:50000.00 RzMag: 99.960312 Ohm , RzPhase: 1.015318 
    Freq:50000.00 RzMag: 99.961296 Ohm , RzPhase: 1.013385 
    Freq:50000.00 RzMag: 99.960312 Ohm , RzPhase: 1.015318 
    Freq:50000.00 RzMag: 99.958328 Ohm , RzPhase: 1.019177 
    Freq:50000.00 RzMag: 99.958328 Ohm , RzPhase: 1.019177 
    Freq:50000.00 RzMag: 99.960709 Ohm , RzPhase: 1.021670 
    Freq:50000.00 RzMag: 99.952477 Ohm , RzPhase: 1.040064 
    Freq:50000.00 RzMag: 99.956947 Ohm , RzPhase: 1.014751 
    Freq:50000.00 RzMag: 99.961296 Ohm , RzPhase: 1.013385 
    Freq:50000.00 RzMag: 99.957932 Ohm , RzPhase: 1.012818 
    Freq:50000.00 RzMag: 99.955948 Ohm , RzPhase: 1.016677 
    Freq:50000.00 RzMag: 99.956947 Ohm , RzPhase: 1.014751 
    Freq:50000.00 RzMag: 99.956947 Ohm , RzPhase: 1.014751 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.957932 Ohm , RzPhase: 1.012818 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.947716 Ohm , RzPhase: 1.035071 
    Freq:50000.00 RzMag: 99.957932 Ohm , RzPhase: 1.012818 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.956947 Ohm , RzPhase: 1.014751 
    Freq:50000.00 RzMag: 99.946732 Ohm , RzPhase: 1.037004 
    Freq:50000.00 RzMag: 99.958923 Ohm , RzPhase: 1.010885 
    Freq:50000.00 RzMag: 99.948708 Ohm , RzPhase: 1.033138 
    Freq:50000.00 RzMag: 99.958923 Ohm , RzPhase: 1.010885 
    Freq:50000.00 RzMag: 99.958923 Ohm , RzPhase: 1.010885 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.960312 Ohm , RzPhase: 1.015318 
    Freq:50000.00 RzMag: 99.949104 Ohm , RzPhase: 1.039497 
    Freq:50000.00 RzMag: 99.956947 Ohm , RzPhase: 1.014751 
    Freq:50000.00 RzMag: 99.947716 Ohm , RzPhase: 1.035071 
    Freq:50000.00 RzMag: 99.948708 Ohm , RzPhase: 1.033138 
    Freq:50000.00 RzMag: 99.959908 Ohm , RzPhase: 1.008959 
    Freq:50000.00 RzMag: 99.957932 Ohm , RzPhase: 1.012818 
    Freq:50000.00 RzMag: 99.955948 Ohm , RzPhase: 1.016677 
    Freq:50000.00 RzMag: 99.993782 Ohm , RzPhase: 1.024464 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.958923 Ohm , RzPhase: 1.010885 
    Freq:50000.00 RzMag: 99.958923 Ohm , RzPhase: 1.010885 
    Freq:50000.00 RzMag: 99.946342 Ohm , RzPhase: 1.030645 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 
    Freq:50000.00 RzMag: 99.958923 Ohm , RzPhase: 1.010885 
    Freq:50000.00 RzMag: 99.956947 Ohm , RzPhase: 1.014751 
    Freq:50000.00 RzMag: 99.959312 Ohm , RzPhase: 1.017244 

  • Thanks, the code provided does work.

    I have removed the floating switch part, so the sine wave is continuous as checked on an oscilloscope.

    So, this is what I am trying to do now:

    I'm injecting the continuous sine wave generated between CEO and Ain1, and measuring the voltage across part of the body (forearm) between Ain2 and 3. This part works.

    I'm trying to measure the heart rate, and as you can see it is sort of working, but not quite yet

    I want to understand, does some TIA or input current or anything else is trying to stabilize or auto-calibrate periodically? The impedance values shift i.e. either increases or decreases over time as if trying to stabilize or something. Do you know why it could be happening? 

    PS: In the figure above, don't look at the values but look at the pattern i.e. the the pattern is slanting downwards to the right from left means impedance values are decreasing over time for a fixed electrode position on the body.

  • Hi,

    If the requirement is to measure heart rate, may I know why you are not using the AD5940_ECG example?

    May I know if you are testing using eval board or on your custom board?

    If using Eval-AD5940BIOZ board with ECG probes stuck on bodyAD5940_ECG example gives below measurement output:

    Note: Eval board uses AD8233 (heart rate monitor) along with AD5940.

  • Hmm, good point, I'll probably look into it, I used AD8421 as my IA, but I will check it out, thanks! 

    So coming back to the slanting issue mentioned above, could you think of anything why it could be happening?

    Also, I do appreciate your help in this matter!

    Edit: I think the methodology to measure the HRM via AD8233 vs the way I'm doing is different. I'm amplitude modulating the pulse signal vs the conventional way AD8233 acquires the ECG signal. Quick question, when AD8233 is operational, is AD594x injecting current in the body?

  • Also, whats the max Bia ODR? I can see it's 20 currently.

  • BIA ODR can go upto 3kHz. However, in Sensorpal, it is limited to 20.

  • Hi,

    No. AD594x doesn't inject any current.

  • Hi Akila,

    Could you please tell me where should I make changes in the code above to get an ODR of 3k Hz? I changed the BIAODR to 3k, but it didn't work.

    Shravan

  • Hi,

    Kindly watch the value of MAXODR for different configurations, so that you may choose the config with maximum MAXODR.

    (MAXODR is defined in the default BIA example in Github)

Reply Children