3 Replies Latest reply on Nov 16, 2016 11:40 PM by MagnusLundin

    Saving state of Filter component for filtering multiple (>2) signals

    bojan.potocnik

      Hello,

         

      I want to filter a multiple constant data streams (data rate <= 2 kHz) with Filter component. However, only one Filter component with only 2 channels is able to exist in one PSoC 5 LP design. Therefore I want to save state of the Filter channel, load state of next signal (data stream), switch signal, save state of this signal,... and so on for multiple signals. In the other words, I want to multiplex Filter components to achieve the same effect as having e.g. 8 Filter components with the same parameters.

         

      I am wondering if this is enough (idea taken from Filter_SaveConfig(void), pasted more as a pseudo code using polling):

         
      #include <project.h>  Filter_backupStruct filterBackup[NUMBER_OF_SIGNALS] = {0};  static void Filter_SaveCustomConfig(Filter_backupStruct * const backupStruct); static void Filter_LoadCustomConfig(const Filter_backupStruct * const backupStruct);  void Filter_Signal(const int signal, const uint16_t sample, uint16_t * const resultA, uint16_t * const resultB) {     const uint8_t SR_DATA_PROCESSED = Filter_CHANNEL_A_INTR | Filter_CHANNEL_B_INTR;      /* Load Filter state for specified signal */     Filter_LoadCustomConfig(&filterBackup[signal]);      /* Filter signal */     Filter_Write16(Filter_CHANNEL_A, sample); /*< Load sample to Channel A */     Filter_Write16(Filter_CHANNEL_B, sample); /*< Load sample to Channel B */     while((Filter_SR_REG & SR_DATA_PROCESSED) != SR_DATA_PROCESSED); /*< Wait for data to be processed */     *resultA = Filter_Read16(Filter_CHANNEL_A); /*< Read processed data from Channel A */     *resultB = Filter_Read16(Filter_CHANNEL_B); /*< Read processed data from Channel B */      /* Save Filter state for specified signal */     Filter_SaveCustomConfig(&filterBackup[signal]); }   static void Filter_SaveCustomConfig(Filter_backupStruct * const backupStruct) {     backupStruct->sr = Filter_SR_REG;     backupStruct->sema = Filter_SEMA_REG;          /* Put DFB RAM on the bus */     Filter_RAM_DIR_REG = Filter_RAM_DIR_BUS;      /* Save the ACU RAM */     (void)memcpy(backupStruct->saveAcu, Filter_ACU_RAM, Filter_ACU_RAM_SIZE);       /* Take DFB RAM off the bus */     Filter_RAM_DIR_REG = Filter_RAM_DIR_DFB; }  static void Filter_LoadCustomConfig(const Filter_backupStruct *backupStruct) {     Filter_SR_REG = backupStruct->sr;     Filter_SEMA_REG = backupStruct->sema;      /* Put DFB RAM on the bus */     Filter_RAM_DIR_REG = Filter_RAM_DIR_BUS;      /* Restore ACU RAM */     (void)memcpy(Filter_ACU_RAM, backupStruct->saveAcu, Filter_ACU_RAM_SIZE);       /* Take DFB RAM off the bus */     Filter_RAM_DIR_REG = Filter_RAM_DIR_DFB; }
         

       

         

      Should I save any additional registers or DFB data (all arrays declared in Filter_RAM_Data.c are declared as const), or is the code above enough to achieve desired functionality?

         

      Thanks,

         

      Bojan