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

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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

0 Likes
3 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted
        Sorry, only 2 channels at a time. Filter needs all 'history' to work properly. At such low data rate you may filter streams in plain code.   
0 Likes
Anonymous
Not applicable

I have been using software digital filtering for that before, but now I wished to "upgrade" the code and I really like off-CPU fast filtering, even with complex filters with high orders, so I really wish to take a challenge and make this filter component to work with multiple signals.

   

About that "history", there is CSA_RAM, CSB_RAM, CFSM_RAM, DA_RAM, DB_RAM, and ACU_RAM. Is there any additional, internal cached memory and states?

0 Likes
Anonymous
Not applicable

The content of the MAC, and ALU, and the values of the ACU registers, the current execution state. It is possible to write a swappable filter, but the DFB filter code must probably be specifically written for it to be possible to swap in and out, and then it must be swapped at exactly the right place in the execution cycle, using the hardware in and out connections and/or semaphores for handshaking.

0 Likes