I'm trying implement a fairy basic filter, and right now I have just some simple test code for me to enter in values. It errors out on the line when it gets to where I call the function I have written. I am fairly certain my error is coming from how I am using the pointers but I just don't understand pointers well enough to know what I'm doing wrong. Any thoughts on what I am doing wrong?
If it helps to understand what the filter should be doing: when a new value is input it is added to the to the buffer and the old state of what the average of the buffer was at is subtracted from the the buffer. the new average of the buffer is returned.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,a_buffer,b_buffer,valueToPrinta,valueToPrintb;
printf("a value: ");
scanf("%d",&a);
printf("b value: ");
scanf("%d",&b);
valueToPrinta = integrate_filter_data_16bit(a, a_buffer, 2);
valueToPrintb = integrate_filter_data_16bit(b, b_buffer, 2);
printf("%d and %d", a_buffer,b_buffer);
return 0;
}
int integrate_filter_data_16bit(int integrator_buffer_16bit, volatile int *pintegrator_accumulator16bit, int integrator_size_16bit)
{
int temp_integrator_accumulator_16bit = *pintegrator_accumulator16bit;
/* compute the new value of the IIR filter accumulator */
*pintegrator_accumulator16bit = (int)integrator_buffer_16bit + (temp_integrator_accumulator_16bit - (temp_integrator_accumulator_16bit >> integrator_size_16bit));
return((int)(*pintegrator_accumulator16bit >> integrator_size_16bit));
}
volatile int *instead of passing by value? All this does is to slow down the program. \$\endgroup\$