WorldWide Drilling Resource
20 SEPTEMBER 2015 WorldWide Drilling Resource ® You’ve heard the phrase “timing is everything”. It’s really true when it comes to microprocessors. Microprocessors are great at timing things. There are two basic timing routines. One is called “real time”. This means clock time like what time of day it is. The other is called “elapsed time”. It’s like a stop watch that times events. It starts and stops, then records the amount of time that has elapsed in between. We will deal with elapsed time here. As we learned in last month’s article, all microprocessors have an oscillator of some sort. This is a device that produces a voltage that goes high, then low over and over again at precise intervals. A voltage that goes high and then back low again once is called one cycle. If this happens in 1 second, we would have 1 cycle per second or 1 Hertz (Hz). This is also called one “clock cycle”. Another thing microprocessors are really good at is counting. You can set-up a microprocessor to count the number of clock cycles coming from the oscillator. Rather than having the microprocessor stop what it is doing to evaluate each clock cycle as it happens, we usually route the clock cycles into a binary “up counter”. The up counter increments - or adds 1 to - the accumulated total every clock cycle. There are many types of up counters, but we will assume this up counter is an 8-bit up counter. This means it can count up to a maximum of 255 decimal or 1111 1111 binary. This up counter keeps on counting as long as it gets clock cycles until it reaches decimal 255, then checks to see if the counter “flips over” (much like a mechanical odometer) from decimal 255 to 0, then starts counting up again. So if your clock oscillator “oscillates” at 256 cycles per second (the actual value is offset by 1 because 0 is included), we know when the up counter goes from 255 to all 0s the elapsed time for this function is 1 second. Most of the time, the oscillators run much faster than 256 cycles per second (like megahertz or millions of cycles per second), but it isn’t a problem. The clock signal(s) can be divided down so the up counter gets a cycle once every 256 clock cycles, or even less than that. This up counter is called a “timebase” and is very useful for quite a number of microprocessor functions. Most micro- processors maintain several different timebases to time different events. These timebases are very inexpensive, costing literally pennies for what can be a very accurate timer. We could even make a “real time” (time of day) timer with one, but real time is difficult to track because clock time is different in different parts of the world, and must be adjusted at the right times for standard and daylight savings time which varies from place to place. A simple event timer could be made by pressing a button when a race starts, then pressing the button again when it stops. To do this with a microprocessor, we would select a timebase that isn’t being used for anything else and reset it to all 0s. When the button (switch) is pressed to start the race, we would allow the timer to start counting up until the button is pressed again when the race ended, which would also stop the timer. The accumulated “count” would repre- sent the elapsed time of the race. With a microprocessor, very accu- rate times can be recorded or maintained. In fact, the external inputs (like switches) used to record microprocessor time very likely introduce more error than does the microprocessor operation itself. But what do you expect for a few dollars? Britt Britt Storkson may be contacted via e-mail to michele@ worldwidedrillingresource.com & ! $ # & # " ! $ # & # & " & ! " &
" $ # & & ! & " & & "! " ! & " " !
! ! !% $ # "! !
Timing is Everything by Britt Storkson Owner, P2FlowLLC To “Billy Bob Smith”: I enjoy your commonsense old- school articles in the Wor ldWi de Dr i ll ing magazine and agree with them. Keep up the good work. Thanks, Mike’s Well Drilling
RkJQdWJsaXNoZXIy NDk4Mzk=