Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/01/08 14:29
Read: times


 
#152832 - For this to work...
Responding to: ???'s previous message
To implement what you want to do requires first of all for you to keep track of the previous "acceptable" value in a history variable. Next you need to establish two threshold delta values that correspond to the negative and positive direction hysteresis. These could be the same value if you wish for uniform hysteresis.

To use these you take regular sample readings from your A/D channel like normal. You may want to apply burst averaging like you showed and use the average value as the "current" reading value. Now with each reading you look to see if it is greater than the history value plus the positive threshold or if it is less than the history value minus the negative threshold value. If you find this to be the case then you use this new value as the A/D average that takes action in the program and also save its value as the new previous "acceptable" value.

When you use this scheme there are a number of things to consider. First off you have to correctly comprehend how to handle the end point readings from the A/D where the computation of the added or subtracted threshold values make the range of values longer than the range of the A/D converter. If writing in C this is typically handled by taking say 8-bit unsigned A/D values and converting them to 16-bit signed values. A second issue is that you need to be sure to read the A/D converter often enough so that your are able to track the value reasonably well as the input changes. If the input changes faster then your sample rate you can get confusing results using this simple scheme.

Lastly I want to comment that a scheme of doing A/D averaging across regularly sampled readings instead of using a burst average may be a better solution for your problem. To do this you should consider setting up a timer interrupt to schedule A/D conversions on a regular basis. The rate would relate to the bandwidth of monitoring you want to perform such as say 500Hz (every 20 milliseconds). In the timer interrupt you have the code maintain a rolling average filter for the readings. If you keep a circular array of the "N" most recent sample values the rolling average filter can be very efficient in the interrupt by keeping a running sum of the array in another variable. At each interrupt you fetch the oldest value from the circular array and subtract it from the running sum. You then plug the newest value into the circular array and add the new value to the running sum. It is then just necessary to divide the runnng sum by the "N" value to get your filtered average value. This divide can be done outside the interrupt context, at the time the average value is needed, to keep the interrupt routine as short as possible. Also if "N" is an even power of two the divide becomes a simple shift right of the running sum value.

I bring up the difference between the burst averaging and a timed averaging because with the latter you can predict the filtered bandwidth of the filter much better.

Michael Karas


List of 12 messages in thread
TopicAuthorDate
Adding hysteresis on top of my sampling            01/01/70 00:00      
   my method            01/01/70 00:00      
   For this to work...            01/01/70 00:00      
      adaptive delta ... ?            01/01/70 00:00      
      All data is keep in eeprom            01/01/70 00:00      
         What does the oscilloscope tell you?            01/01/70 00:00      
         not a good ides            01/01/70 00:00      
   Median filter ?            01/01/70 00:00      
   are you using an RC low pass before the ADC?            01/01/70 00:00      
      check here            01/01/70 00:00      
      Found a minor issue in hardware...not dealbreaker            01/01/70 00:00      
   Low Pass Filter in Software            01/01/70 00:00      

Back to Subject List