CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

filter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








filter
PostPosted: Sun Aug 19, 2007 2:17 pm     Reply with quote

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 Smile
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: filter
PostPosted: Mon Aug 20, 2007 2:16 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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