|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
filter |
Posted: Sun Aug 19, 2007 2:17 pm |
|
|
I have a PIC (Slave) that reads sensor values of different sensors. I have another Master that gets the values of the sensors from the PIC(Slave). In the slave I filter my acquisition of sensor values. I don’t want my new sensor value to be more than 5% of my previous sensor read iteration, so I use the following method.
Code: |
for(SensorNum=1;SensorNum<5;SensorNum++) // Sequences through all the 4 sensors.
{
set_adc_channel(SensorNum-1 ); // Sets the adc channel for Sensor the respective sensors.
delay_us(500);
SensorOutput[SensorNum-1] = Read_ADC(); // Reads the sensors output from the adc and saves the value in an Array
delay_us(500);
}
signed int32 filter =25;
void filterdata()
{
i=0;
for(i=0;i<4;i++) // Applies the filter to the newly acquired data.
{
SensorOutput2[i]=(((signed int32)SensorOutput[i]*(filter)) + (SensorOutput1[i]*(100-filter)))/100;
}
i=0;
for(i=0;i<4;i++) // Saves the filtered value as a signed int32 for the next iteration.
{
SensorOutput1[i]=SensorOutput2[i];
}
i=0;
for(i=0;i<4;i++) // coverts the filtered values to int16.
{
SensorOutput[i]=(int16)SensorOutput2[i];
}
}
|
I have two problems with the above method.
PROBLEM #1
I noticed that the value of the filter needs to be more than 25% for me to receive the correct output of the sensor. Values below that force me receive values lower than the real value of the sensor output. In other words, filer value less than 25 does not let the sensor value to climb to its correct value.
PROBLEM #2
If I use the filter method, I realize that the sensor values suddenly fall periodically. I notice that every 2:00mins, then 2:10mins, then 2:20 mins, etc… the value of the sensors would drastically drop for one reading, and then climb up to the regular value. If I remove the filter method, I don’t see the values dropping like that.
Any suggestions would be appreciated.
Thank You |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: filter |
Posted: Mon Aug 20, 2007 2:16 pm |
|
|
Anonymous wrote: | In the slave I filter my acquisition of sensor values. I don’t want my new sensor value to be more than 5% of my previous sensor read iteration |
This is some optimized code that does almost the same thing. The filter value is hard coded to 25% in this example but other power of 2 filter values can be used by increasing the number of shifts.
I would guess you are using floating point math and that requires a lot of computation time. It could be throwing off you timing somehow or you may have something that is zeroing your reading variable.
http://www.ccsinfo.com/forum/viewtopic.php?t=29018 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|