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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/13/05 01:15
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#93363 - Flow rate is pretty easy...
Responding to: ???'s previous message
When you make displays of something like flow rate it is rather reasonable to update the display with a new reading once per second. Any faster than that is not particularly valuable for a human that has to see the display and comprehend what it is showing.

I would setup one of the timers on the processor as a counter to accumulate a count of the pulses from the sensor. Thus if you used the Timer 1 for this purpose connect the sensor pulse to the T1 input so that it increments the count in the Timer 1 counter. Next configure the Timer 2 to generate a timed interrupt source. A feasible thing would be to look at setting the Timer 2 to interrupt once per 10 milliseconds (100 Hz). In the interrupt service routine for this Timer 2 have a software counter that you step from 0 to 99 cyclically to divide the interrupt rate to an effective once per second rate. Each time this count cycles through zero have the Timer 2 interrupt code also read the currently accululated pulse count in the Timer 1 counter and save that into some memory locations. Also set a bit flag that indicates "reading taken". Finally at that 1 second rate you clear the Timer 1 counter back to zero.

In the main line code you will arrange the main loop to poll the "reading taken" flag. When this flag is seen set it is time to compute the flow rate and update the display. The formula you would use for this would be to take the count that has been saved off in the memory locations and compute:

Liters/Second = (COUNT * 100)/752

If COUNT is managed as an unsigned 16-bit value and you multiply it by the 100 into a 32-bit product then divide by the 752 your result will be a number of Liters/Second that has an implied two decimal places of resolution. Thus in your display routine the value on the LCD screen can have a decimal point inserted between the second and third digit from the right as:

Display: NNNN.NN l/s

Note: (This should give you the general concepts. You will have to look into a number of factors which are not considered in my discussion. One of these is related to the total pulses the sensor can output in one second. If this count exceeds a 16-bit count then you will have to latch the Time 1 counter value out faster than once per second. Another thing to consider is that if the pulses come really really fast then they may exceed the maximum clocking input that the T1 input will work with. A check in the data sheet for the microcontroller will reveal the upper limit for this input. Yet another thing is that after the T1 counter value is read there is the small possibility that a pulse may show up to be counted before your code gets the counter reset to zero and re-enabled. Depending on your application this missed pulse will introduce an error of 1/752 of a liter. For the rate display this is probably not even an issue but if you were trying to totalize flow accurately to the resolution of the sensor (1.32 ml) then this may require some careful design to make sure pulses during reading are not lost).

Michael Karas


List of 12 messages in thread
TopicAuthorDate
interfacing liquid flow sensor...            01/01/70 00:00      
   Not so bad...            01/01/70 00:00      
   Flow rate is pretty easy...            01/01/70 00:00      
   Software method!            01/01/70 00:00      
   a few things            01/01/70 00:00      
   flow sensor            01/01/70 00:00      
      Search RS Stock            01/01/70 00:00      
      get this ...            01/01/70 00:00      
         Turbine type            01/01/70 00:00      
            thanks!!            01/01/70 00:00      
               inputs            01/01/70 00:00      
               Schmitts            01/01/70 00:00      

Back to Subject List