This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
resources:tools-software:sigmastudio:toolbox:filters:firfilter [12 Jun 2020 01:00] – Added python example code Joshua Berlin | resources:tools-software:sigmastudio:toolbox:filters:firfilter [16 Jun 2020 03:15] (current) – Minor clarifications Joshua Berlin | ||
---|---|---|---|
Line 64: | Line 64: | ||
| | ||
print_object_property(' | print_object_property(' | ||
+ | </ | ||
+ | |||
+ | ====== Controlling the FIR Filter from a Microcontroller ====== | ||
+ | The following assumes you have a working microcontroller platform, with SigmaDSP interface code based on [[resources: | ||
+ | |||
+ | |||
+ | |||
+ | ===== Reading FIR Coefficients from the SigmaDSP ===== | ||
+ | <code cpp> | ||
+ | // NOTE: This code will not work for very large filters that span multiple data memories or memory pages. | ||
+ | void print_FIR_coeffs(int fir_start_addr, | ||
+ | // Initialize a double array to hold the coefficients. | ||
+ | double fir_coeffs[fir_filter_length] = {}; | ||
+ | |||
+ | for (int i = 0; i < fir_filter_length; | ||
+ | // DSP memory holds FIR coefficients in reverse order so fill the fir_coeffs array from last to first. | ||
+ | fir_coeffs[fir_filter_length - i - 1] = SIGMA_READ_REGISTER_FLOAT(fir_start_addr + i); | ||
+ | } | ||
+ | |||
+ | // At this point you can do anything you like with fir_coeffs. We will simply print them out. | ||
+ | Serial.println(" | ||
+ | for (int i = 0; i < fir_filter_length; | ||
+ | Serial.println(fir_coeffs[i], | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Writing FIR Coefficients to the SigmaDSP ===== | ||
+ | <code cpp> | ||
+ | // NOTE: This code will not work for very large filters that span multiple data memories or memory pages. | ||
+ | void write_FIR_coeffs(int fir_start_addr, | ||
+ | for (int i = 0; i < fir_filter_length; | ||
+ | // DSP memory holds FIR coefficients in reverse order, so increment address while decrementing coefficient index. | ||
+ | SIGMA_WRITE_REGISTER_FLOAT(fir_start_addr + i, coefficients[fir_filter_length - i - 1]); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Example Usage ===== | ||
+ | If you have an FIR algorithm added to your SigmaStudio project, the exported source code will include variable information in the *PARAMS.h* file. Using these variables for addressing allows your code to automatically keep track of any changes in the filter address as your SigmaStudio project grows in complexity. | ||
+ | |||
+ | <code cpp> | ||
+ | // Print the coefficients contained in the default program | ||
+ | print_FIR_coeffs(MOD_FIR1_ALG0_FIRSIGMA300ALG1FIRCOEFF0_ADDR, | ||
+ | // Create an array of new coefficients | ||
+ | double new_coefficients[MOD_FIR1_COUNT] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; | ||
+ | // Write the new FIR coefficients to the DSP | ||
+ | write_FIR_coeffs(MOD_FIR1_ALG0_FIRSIGMA300ALG1FIRCOEFF0_ADDR, | ||
+ | // Read back the coefficients; | ||
+ | print_FIR_coeffs(MOD_FIR1_ALG0_FIRSIGMA300ALG1FIRCOEFF0_ADDR, | ||
</ | </ |