Post Go back to editing

Use of the Sequencer

Category: Software
Product Number: AD5940

We want to be able to have the AD5940 sample impedance 7 times at one frequency, 1 sample at another frequency, then repeat the cycle without needing the microcontroller to manage the transitions. A few of us on the team can't quite figure out the best way to do that in the Sequencer.  Would we use slots A - H and sequence between them then have the wake-up timer repeat? Would we just put all the command with SEQ_WAIT in 1 slot and use the wake-up timer? Some other way?

Also, when our code grabs the samplse, what would the best way be to identify which sample goes with with frequency? Do we always have to wait for 8 samples in the FIFO, or could we put data in the FIFO to indicate a change in frequency for internal coding?

Thank you for any support. 

  • Hi  ,

    Could you or your team please help look into this query?
    Thanks.

    Regards,
    Francis

  • Hi,

    Below modifications may be done for your application.

    1) Configure

     fifo_cfg.FIFOThresh = 16;//AppIMPCfg.FifoThresh;        /* DFT result. One pair for RCAL, another 7 pairs for Rz. One DFT result have real part and imaginary part */

    in AD5940Main.c

    2) Add variables

    uint32_t WaitClks1, WaitClks2;

    in Impedance.c

     

    3) Refer to lines with comments

    //added for taking 7 samples in 1 frequency and 1 sample in next frequency

    in below functions:

    static AD5940Err AppIMPSeqMeasureGen(void)
    {
      AD5940Err error = AD5940ERR_OK;
      const uint32_t *pSeqCmd;
      uint32_t SeqLen;
      
      SWMatrixCfg_Type sw_cfg;
      ClksCalInfo_Type clks_cal;
    
      clks_cal.DataType = DATATYPE_DFT;
      clks_cal.DftSrc = AppIMPCfg.DftSrc;
      clks_cal.DataCount = 1L<<(AppIMPCfg.DftNum+2); /* 2^(DFTNUMBER+2) */
      clks_cal.ADCSinc2Osr = AppIMPCfg.ADCSinc2Osr;
      clks_cal.ADCSinc3Osr = AppIMPCfg.ADCSinc3Osr;
      clks_cal.ADCAvgNum = AppIMPCfg.ADCAvgNum;
      clks_cal.RatioSys2AdcClk = AppIMPCfg.SysClkFreq/AppIMPCfg.AdcClkFreq;
      AD5940_ClksCalculate(&clks_cal, &WaitClks1);
    
      AD5940_SEQGenCtrl(bTRUE);
      AD5940_SEQGpioCtrlS(AGPIO_Pin2); /* Set GPIO1, clear others that under control */
      AD5940_SEQGenInsert(SEQ_WAIT(16*250));  /* @todo wait 250us? */
      sw_cfg.Dswitch = SWD_RCAL0;
      sw_cfg.Pswitch = SWP_RCAL0;
      sw_cfg.Nswitch = SWN_RCAL1;
      sw_cfg.Tswitch = SWT_RCAL1|SWT_TRTIA;
      AD5940_SWMatrixCfgS(&sw_cfg);
    	AD5940_AFECtrlS(AFECTRL_HSTIAPWR|AFECTRL_INAMPPWR|AFECTRL_EXTBUFPWR|\
                    AFECTRL_WG|AFECTRL_DACREFPWR|AFECTRL_HSDACPWR|\
                    AFECTRL_SINC2NOTCH, bTRUE);
      AD5940_AFECtrlS(AFECTRL_WG|AFECTRL_ADCPWR, bTRUE);  /* Enable Waveform generator */
      //delay for signal settling DFT_WAIT
      AD5940_SEQGenInsert(SEQ_WAIT(16*10));
      AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT, bTRUE);  /* Start ADC convert and DFT */
      AD5940_SEQGenInsert(SEQ_WAIT(WaitClks1));
      //wait for first data ready
      AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG, bFALSE);  /* Stop ADC convert and DFT */
      
      clks_cal.DataCount = 7*(1L<<(AppIMPCfg.DftNum+2)); /* 2^(DFTNUMBER+2) */                                      //added for taking 7 samples in 1 frequency and 1 sample in next frequency
      AD5940_ClksCalculate(&clks_cal, &WaitClks2);                                                                  //added for taking 7 samples in 1 frequency and 1 sample in next frequency
    
      /* Configure matrix for external Rz */
      sw_cfg.Dswitch = AppIMPCfg.DswitchSel;
      sw_cfg.Pswitch = AppIMPCfg.PswitchSel;
      sw_cfg.Nswitch = AppIMPCfg.NswitchSel;
      sw_cfg.Tswitch = SWT_TRTIA|AppIMPCfg.TswitchSel;
      AD5940_SWMatrixCfgS(&sw_cfg);
      AD5940_AFECtrlS(AFECTRL_ADCPWR|AFECTRL_WG, bTRUE);  /* Enable Waveform generator */
      AD5940_SEQGenInsert(SEQ_WAIT(16*10));  //delay for signal settling DFT_WAIT
      AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT, bTRUE);  /* Start ADC convert and DFT */
      AD5940_SEQGenFetchSeq(NULL, &AppIMPCfg.SeqWaitAddr[0]); /* Record the start address of the next command. */  //added for taking 7 samples in 1 frequency and 1 sample in next frequency
      AD5940_SEQGenInsert(SEQ_WAIT(WaitClks2));  /* wait for first data ready */
      AD5940_AFECtrlS(AFECTRL_ADCCNV|AFECTRL_DFT|AFECTRL_WG|AFECTRL_ADCPWR, bFALSE);  /* Stop ADC convert and DFT */
        AD5940_AFECtrlS(AFECTRL_HSTIAPWR|AFECTRL_INAMPPWR|AFECTRL_EXTBUFPWR|\
                    AFECTRL_WG|AFECTRL_DACREFPWR|AFECTRL_HSDACPWR|\
                    AFECTRL_SINC2NOTCH, bFALSE);
      AD5940_SEQGpioCtrlS(0); /* Clr GPIO1 */
    
      AD5940_EnterSleepS();/* Goto hibernate */
    
      /* Sequence end. */
      error = AD5940_SEQGenFetchSeq(&pSeqCmd, &SeqLen);
      AD5940_SEQGenCtrl(bFALSE); /* Stop sequencer generator */
    
      if(error == AD5940ERR_OK)
      {
        AppIMPCfg.MeasureSeqInfo.SeqId = SEQID_0;
        AppIMPCfg.MeasureSeqInfo.SeqRamAddr = AppIMPCfg.InitSeqInfo.SeqRamAddr + AppIMPCfg.InitSeqInfo.SeqLen ;
        AppIMPCfg.MeasureSeqInfo.pSeqCmd = pSeqCmd;
        AppIMPCfg.MeasureSeqInfo.SeqLen = SeqLen;
        /* Write command to SRAM */
        AD5940_SEQCmdWrite(AppIMPCfg.MeasureSeqInfo.SeqRamAddr, pSeqCmd, SeqLen);
      }
      else
        return error; /* Error */
      return AD5940ERR_OK;
    }

    /* Modify registers when AFE wakeup */
    int32_t AppIMPRegModify(int32_t * const pData, uint32_t *pDataCount)
    {
      FIFOCfg_Type fifo_cfg;
      if(AppIMPCfg.NumOfData > 0)
      {
        AppIMPCfg.FifoDataCount += *pDataCount/4;
        if(AppIMPCfg.FifoDataCount >= AppIMPCfg.NumOfData)
        {
          AD5940_WUPTCtrl(bFALSE);
          return AD5940ERR_OK;
        }
      }
      if(AppIMPCfg.StopRequired == bTRUE)
      {
        AD5940_WUPTCtrl(bFALSE);
        return AD5940ERR_OK;
      }
      if(AppIMPCfg.SweepCfg.SweepEn) /* Need to set new frequency and set power mode */
      {
        AD5940_WGFreqCtrlS(AppIMPCfg.SweepNextFreq, AppIMPCfg.SysClkFreq);
        SRAMAddr = AppIMPCfg.MeasureSeqInfo.SeqRamAddr + AppIMPCfg.SeqWaitAddr[0];       //added for taking 7 samples in 1 frequency and 1 sample in next frequency
        SeqCmdBuff[0] =SEQ_WAIT(WaitClks1);                                               //added for taking 7 samples in 1 frequency and 1 sample in next frequency
        AD5940_SEQCmdWrite(SRAMAddr, SeqCmdBuff, 1);                                     //added for taking 7 samples in 1 frequency and 1 sample in next frequency
        
        /* Step2. Configure FIFO and Sequencer*/
      fifo_cfg.FIFOEn = bFALSE;
      fifo_cfg.FIFOThresh = 4;//AppIMPCfg.FifoThresh;        /* DFT result. One pair for RCAL, another for Rz. One DFT result have real part and imaginary part */
      AD5940_FIFOCfg(&fifo_cfg);
      fifo_cfg.FIFOEn = bTRUE;
      AD5940_FIFOCfg(&fifo_cfg);
      }
      return AD5940ERR_OK;
    }

    //Impedance.h
    typedef struct
    {
    /* Common configurations for all kinds of Application. */
      BoolFlag bParaChanged;        /* Indicate to generate sequence again. It's auto cleared by AppBIAInit */
      uint32_t SeqStartAddr;        /* Initialaztion sequence start address in SRAM of AD5940  */
      uint32_t MaxSeqLen;           /* Limit the maximum sequence.   */
      uint32_t SeqStartAddrCal;     /* Measurement sequence start address in SRAM of AD5940 */
      uint32_t SeqWaitAddr[1];      //added for taking 7 samples in 1 frequency and 1 sample in next frequency
     ......
     ......
    }AppIMPCfg_Type;

  • Akila,

    The code you are modifying in your above response, where is it from? Our code has a slightly different structure, so I'd like to know what example code you are using to start.