Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
|
Hi I am looking at converting some values and what I need to do is determine the Log (base10) of say ten bit values in assembler. Currently the Math pack I use is a homebrew 32 bit integer one, wich has the basics, including divide and multiply. (the resolution of the AD is up to 32 bits, this ends up as 0-1000 for display) The options I got are to install a FP package or set up a lookup table with or without interpolation for a thousand points. The question is, are there any clever mathematical solutions about that can be set up in assembler? Conversion time is not a great issue, any pointers will be appreciated. Regards, Theo |
|
|
|
At 04:00 PM 5/30/04, you wrote: I am looking at converting some values and what I need to do is determine the Log (base10) of say ten bit values in assembler. >The question is, are there any clever mathematical solutions about that >can be set up in assembler? Ever consider log(base 2)? I haven't tried it, so I can't comment on it's performance, but you asked for clever, and that was about as clever as I could get offhand. Gary Olmstead Toucan Technology Ventura CA |
|
|
|
--- In , Gary Olmstead <garyolmstead@e...> wrote: Hi Gary, > I am looking at converting some values and what I need to do is determine > the Log (base10) of say ten bit values in assembler. > > >The question is, are there any clever mathematical solutions about that > >can be set up in assembler? > > Ever consider log(base 2)? I haven't tried it, so I can't comment on it's > performance, but you asked for clever, and that was about as clever as I > could get offhand. My somewhat superanuated mathematical skills tell me that that leaves me with some base conversions, is that a worthwile shift? Cheers, Theo |
|
|
|
Theo, Log base conversion is easy: Log X (base 10) = log X (base 2) / log 10 (base 2) 1 / log 10 (base 2) = 0.301029995 So the formula becomes: Log X (base 10) = 0.301029995 * log X (base 2) And a Log base conversion from base 2 to base 10 is achieved using one floating point multiply. Now in regard to the question how to implement the Log in a table (or in calculation): You just need a table of one decade: Build the table for fractions in the range of 1 to 2 ( log 1 (base 2) - log 2 (base 2) ). Then Log (base 2) of powers of 2 are whole numbers. For example Log 1 (base 2) = 0 Log 2 (base 2) = 1 Log 4 (base 2] = 2 Log 8 (base 2) = 3 Log 16 (base 2) = 4 ... Meaning, the integer part is of the result is n, when your source number X is in the range: 2^n <= X < 2^(n+1) when n is an integer. Then the fraction part of the log is determined from the look-up table for X / (2^n) . Let's take an actual example: Calculate Log 15 (base 2) according to the above method: (X = 15) 15 is between 2^3 and 2^4 so the integer part of the result is 3. The fraction that we will look up in the table will be: Fraction = 15 / 2^3 = 1.875 Then you will look up in the table: Log 1.875 (base 2) = 0.906890595 and the final result of the integer and the fraction is: Log 15 (base 2) = 3.906890595 Hope this helps, Doron Nohau Corporation HC12 In-Circuit Emulators www.nohau.com/emul12pc.html At 06:50 31/05/2004 +0000, you wrote: >--- In , Gary Olmstead <garyolmstead@e...> wrote: > >Hi Gary, > > > I am looking at converting some values and what I need to do is determine > > the Log (base10) of say ten bit values in assembler. > > > > >The question is, are there any clever mathematical solutions about that > > >can be set up in assembler? > > > > Ever consider log(base 2)? I haven't tried it, so I can't comment on it's > > performance, but you asked for clever, and that was about as clever as I > > could get offhand. > >My somewhat superanuated mathematical skills tell me that that leaves me >with some base conversions, is that a worthwile shift? > >Cheers, > >Theo > > >--------------------------------------------------------To learn more >about Motorola Microcontrollers, please visit >http://www.motorola.com/mcu >o learn more about Motorola Microcontrollers, please visit >http://www.motorola.com/mcu > >Yahoo! Groups Links [Non-text portions of this message have been removed] |
|
|
|
--- In , Doron Fael <doronf@n...> wrote: Hi Doron, That doesn't look beyond what I can implement before retirement. I have to have a mull over the floating point a bit and see if I can contain the damage in integer math, as I said, currently I have only an integer math pack, but it should do the trick anyway (I had a look at some of the FP packages and they take a fair slice of resources and several don't even get to the 32 bit accuracy required) Thanks a lot for the guidance, as I said, my math is somewhat rusty after almost fourty years:-) BTW, for those interested, I managed to help Kent out reprogramming his machine with my POD setup. Turned out he had a small power supply problem and somewhere along the line lost his Monitor. He promised to keep us informed if he manages to meet his Thursday UNI deadline. Cheers, Theo > Log base conversion is easy: > > Log X (base 10) = log X (base 2) / log 10 (base 2) > 1 / log 10 (base 2) = 0.301029995 > > So the formula becomes: > > Log X (base 10) = 0.301029995 * log X (base 2) > > And a Log base conversion from base 2 to base 10 is achieved using one > floating point multiply. > Now in regard to the question how to implement the Log in a table (or in > calculation): > You just need a table of one decade: Build the table for fractions in the > range of 1 to 2 ( log 1 (base 2) - log 2 (base 2) ). > > Then Log (base 2) of powers of 2 are whole numbers. For example > Log 1 (base 2) = 0 > Log 2 (base 2) = 1 > Log 4 (base 2] = 2 > Log 8 (base 2) = 3 > Log 16 (base 2) = 4 > ... > > Meaning, the integer part is of the result is n, when your source number X > is in the range: > 2^n <= X < 2^(n+1) > when n is an integer. > > Then the fraction part of the log is determined from the look-up table for > X / (2^n) . > > Let's take an actual example: > Calculate Log 15 (base 2) according to the above method: > (X = 15) > > 15 is between 2^3 and 2^4 so the integer part of the result is 3. > > The fraction that we will look up in the table will be: > Fraction = 15 / 2^3 = 1.875 > > Then you will look up in the table: > Log 1.875 (base 2) = 0.906890595 > > and the final result of the integer and the fraction is: > > Log 15 (base 2) = 3.906890595 > Hope this helps, > Doron > Nohau Corporation > HC12 In-Circuit Emulators > www.nohau.com/emul12pc.html > > At 06:50 31/05/2004 +0000, you wrote: > >--- In , Gary Olmstead <garyolmstead@e...> wrote: > > > >Hi Gary, > > > > > I am looking at converting some values and what I need to do is determine > > > the Log (base10) of say ten bit values in assembler. > > > > > > >The question is, are there any clever mathematical solutions about that > > > >can be set up in assembler? > > > > > > Ever consider log(base 2)? I haven't tried it, so I can't comment on it's > > > performance, but you asked for clever, and that was about as clever as I > > > could get offhand. > > > >My somewhat superanuated mathematical skills tell me that that leaves me > >with some base conversions, is that a worthwile shift? > > > >Cheers, > > > >Theo > > > > > > > > > >--------------------------------------------------------To learn more > >about Motorola Microcontrollers, please visit > >http://www.motorola.com/mcu > >o learn more about Motorola Microcontrollers, please visit > >http://www.motorola.com/mcu > > > >Yahoo! Groups Links > > > > > > > > [Non-text portions of this message have been removed] |
|
----- Original Message ----- From: "theobee00" To: <> Sent: Monday, May 31, 2004 12:46 PM Subject: [68HC12] Re: Maths > --- In , Doron Fael <doronf@n...> wrote: > > Hi Doron, > > That doesn't look beyond what I can implement before retirement. > > I have to have a mull over the floating point a bit and see if I can contain the damage in integer math, as I said, currently I have only an integer math pack, but it should do the trick anyway Theo, you don't have to have FP mul, just fixed point mul. What's desired accuracy? Only integer part of log is necessary? Then uint verycoarselog10(uint x) { int r=0; while (x>1u) { x/=10u; r++; } return r; } or uint verycoarselog10(uint x) { int r=0; while (x>1u) { x>>=1; r++; } return r/3u; // ~r*log10(2) } Try this: "Compute signal power with fixed-point calculators" http://www.embedded.com/showArticle.jhtml?articleID=14800034 Edward > (I had a look at some of the FP packages and they take a fair slice of resources and several don't even get to the 32 bit accuracy required) > > Thanks a lot for the guidance, as I said, my math is somewhat rusty after almost fourty years:-) > > BTW, for those interested, I managed to help Kent out reprogramming his machine with my POD setup. > > Turned out he had a small power supply problem and somewhere along the line lost his Monitor. > > He promised to keep us informed if he manages to meet his Thursday UNI deadline. > Cheers, > > Theo > > > Log base conversion is easy: > > > > Log X (base 10) = log X (base 2) / log 10 (base 2) > > > > > > 1 / log 10 (base 2) = 0.301029995 > > > > So the formula becomes: > > > > Log X (base 10) = 0.301029995 * log X (base 2) > > > > And a Log base conversion from base 2 to base 10 is achieved using one > > floating point multiply. > > > > > > Now in regard to the question how to implement the Log in a table (or in > > calculation): > > You just need a table of one decade: Build the table for fractions in the > > range of 1 to 2 ( log 1 (base 2) - log 2 (base 2) ). > > > > Then Log (base 2) of powers of 2 are whole numbers. For example > > Log 1 (base 2) = 0 > > Log 2 (base 2) = 1 > > Log 4 (base 2] = 2 > > Log 8 (base 2) = 3 > > Log 16 (base 2) = 4 > > ... > > > > Meaning, the integer part is of the result is n, when your source number X > > is in the range: > > 2^n <= X < 2^(n+1) > > when n is an integer. > > > > Then the fraction part of the log is determined from the look-up table for > > X / (2^n) . > > > > Let's take an actual example: > > Calculate Log 15 (base 2) according to the above method: > > (X = 15) > > > > 15 is between 2^3 and 2^4 so the integer part of the result is 3. > > > > The fraction that we will look up in the table will be: > > Fraction = 15 / 2^3 = 1.875 > > > > Then you will look up in the table: > > Log 1.875 (base 2) = 0.906890595 > > > > and the final result of the integer and the fraction is: > > > > Log 15 (base 2) = 3.906890595 > > > > > > Hope this helps, > > Doron > > Nohau Corporation > > HC12 In-Circuit Emulators > > www.nohau.com/emul12pc.html > > > > At 06:50 31/05/2004 +0000, you wrote: > > >--- In , Gary Olmstead <garyolmstead@e...> wrote: > > > > > >Hi Gary, > > > > > > > I am looking at converting some values and what I need to do is determine > > > > the Log (base10) of say ten bit values in assembler. > > > > > > > > >The question is, are there any clever mathematical solutions about that > > > > >can be set up in assembler? > > > > > > > > Ever consider log(base 2)? I haven't tried it, so I can't comment on it's > > > > performance, but you asked for clever, and that was about as clever as I > > > > could get offhand. > > > > > >My somewhat superanuated mathematical skills tell me that that leaves me > > >with some base conversions, is that a worthwile shift? > > > > > >Cheers, > > > > > >Theo |
|
|
|
If you want transcendental functions with fixpoint maths, it is worth to look at CORDIC. Simple and reasonably quick. Uses only adds and shifts. A transcendental function takes about the same code space and runtime as an integer division (on the same number bits). If you can't find it on the 'Net easily, I can send you a very good description in PDF. Zoltan |
|
|
|
Not long ago a friend that does imbedded stuff needed to do a very fast, but low accuracy log. We tinkered around with some ideas and ended up basing it on the following approximation-- ln(1 + x) = x - (x**2)/2 + (x**3)/3 ... For his app the first term was all that was necessary. He accomplished this on a Power PC in just five (which I must say were *very* cleverly crafted) assembly language instructions (and no loops)! On this processor there is an instruction that determines the leading zeros in a register in just one machine cycle (at 80 Mhz), which gives it a enormous advantage over the '11 or '12 machines. To use the approximation determine the number of binary points in the whole part of the number (shift lefts as shown in the C code of the earlier posts, (which was base 10 so the shifting was done by dividing by 10)). The number of binary points minus 1 gives the whole number part of the log and the remaining number the fraction (i.e. the first term of the approximation). (I'm doing this from memory...so doing some pencil and paper examples is recommended ;) He did a run/printout to check the deviation of abbreviated approximation versus the full precision library result. It was a few percent except for small numbers. For the app being talked about here, the second term would probably be needed to improved the accuracy. Note that at the points where the fraction of log(x) is zero, the approximation is exact. Between these points one can interpolate with a straight line, which of course is merely the first term, and improve the interpolation with a 2nd order curve, which is the first two terms. As mentioned earlier the change of base is easily accomplished by a scale factor, which can be done in fixed point Regards, Donald E Haselwood |
|
|
|
Hi all, Lately whenever I've had to do quadrature support I must admit I've been kind of spoiled. In the past we've used an LSI chip that takes quad A,B in and produces a count and an UP/DOWN signal. That device was selected because the 80C51 counter could take a count and up/down input. That was the ATMEL 8051CCO1 with built in CAN. Then the TMS320F2812 has not just 1 but 2 quadrature inputs dedicated to dealing with two separate encoders. No need for external signals to do the direction handling. Real nice. Enter this project with the 9S12 and I thought I read somewhere that it too could deal with quadrature A,B inputs and handle encoder direction. Have I lost track of an application note for this or is it just not possible without interrupting on edges and checking the other signals level? The old fashioned PIC micro-processor way. Thanks, John Dammeyer Wireless CAN with the CANRF module now available. http://www.autoartisans.com/products Automation Artisans Inc. Ph. 1 250 544 4950 |
|
|
|
John, I too have found this very annoying shortcoming on HC12 counters. The 320F24x is far nicer ;-) The only solution I have thought of, but not tested is to use a PIC12C508 or ATtiny12 (I have code for the PIC) to decode the quadrature into count and direction. The outputs of this device are up-clock/down-clock. Then feed these clocks to the alternate pulse accumulators (PA and PB) on a 9S12D device. The pulse accumulator difference is the current count. The tricky bit seems to be that you would need to reset these counters before they overflow (no big deal), but making the read-reset operation indivisible to the external clock may lead to lost counts. My application can require 10KHz to 20KHz counting, so interrupts put a very heavy load on the processor. I will be curious to know how you solve the problem. Jonathan Masters JEMTECH Pty Ltd -----Original Message----- From: John Dammeyer [mailto:] Sent: Tuesday, June 01, 2004 1:23 PM To: Subject: [68HC12] 9S12DG256 Quadrature Encoder Support. Hi all, Lately whenever I've had to do quadrature support I must admit I've been kind of spoiled. In the past we've used an LSI chip that takes quad A,B in and produces a count and an UP/DOWN signal. That device was selected because the 80C51 counter could take a count and up/down input. That was the ATMEL 8051CCO1 with built in CAN. Then the TMS320F2812 has not just 1 but 2 quadrature inputs dedicated to dealing with two separate encoders. No need for external signals to do the direction handling. Real nice. Enter this project with the 9S12 and I thought I read somewhere that it too could deal with quadrature A,B inputs and handle encoder direction. Have I lost track of an application note for this or is it just not possible without interrupting on edges and checking the other signals level? The old fashioned PIC micro-processor way. Thanks, John Dammeyer Wireless CAN with the CANRF module now available. http://www.autoartisans.com/products Automation Artisans Inc. Ph. 1 250 544 4950 --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Sponsor ADVERTISEMENT <http://rd.yahoo.com/SIG=12940080p/M=295196.4901138.6071305.3001176/D=gr oups/S=1706554205:HM/EXP=1086146742/A=2128215/R=0/SIG=10se96mf6/*http:/c ompanion.yahoo.com> click here <http://us.adserver.yahoo.com/l?M=295196.4901138.6071305.3001176/D=group s/S=:HM/A=2128215/rand=440386676> _____ > Service. [Non-text portions of this message have been removed] |
|
|
|
----- Original Message ----- From: "theobee00" <> To: <> Sent: Monday, May 31, 2004 11:44 PM Subject: [68HC12] Re: Maths > --- In , "Edward Karpicz" <karpicz@a...> wrote: > > > Theo, you don't have to have FP mul, just fixed point > > mul. > > What's desired accuracy? Only integer part of log is > > necessary? Then > > > > uint verycoarselog10(uint x) > > Thanks for that, but we talk fast handcrafted assembly code here:-) But you are able to handcraft C code, aren't you :-) ? > As it is I can only do ten conversion per second, maybe for display purposes that can be dropped a bit further. HC12 is able to compute accurate single precision FP log in <0.5ms @ 8MHz ECLK. > The accuracy I try to attain is 1 in 1000, (the display is 100.0), the device curently shows a thing called Obscuration and I am toying with the idea to give the option to display optical density. > > There is a Log relation ship between the two. > If you are curious, the math and standards involved are on the techy website www.OM80.com, under Ringelman I think. > > > Try this: > > "Compute signal power with fixed-point calculators" > > > > http://www.embedded.com/showArticle.jhtml?articleID=14800034 > > That is a good link thanks, I had a poke around embedded before but didn't find that article. > > For some reason the listing is not available at present but I try a few more times. Maybe it's your firewall or smth. is blocking any ftp traffic? It's still available here ftp://ftp.embedded.com/pub/2003/10probert_listing.htm There's another method, never used it though. Google for "bitlog logarithm". Here it's probably : http://www.emesystems.com/BS2math3.htm Determine leftmost nonzero bits position n, assuming LSB's n is 0. Then log2~ (n*2^n + (x-2^n))/2^n or ~ ((n-1)*2^n +x)/2^n. log2(150)=log2(0b10010110) n is 7, 2^n is 128. ((7-1)*128+150)/128=7.171875 , correct log2(150) is ~7.22881. log2(1234) n is 10 ((10-1)*1024+1234)/1024=10.205078125, correct log2(1234) is ~10.269 Edward > Looks like with your and Dorons help I am getting there. > > Interestingly I find that another thing that seems needed is a revision of my math skills, manipulating logs and exponents doesn't appear as fluent as it used to be. > > A good oppertunity here for my son to practice his high school skills:-) > Thanks again > > Theo > > > > Cheers, > > > > > > Theo > > > > > > > Log base conversion is easy: > > > > > > > > Log X (base 10) = log X (base 2) / log 10 (base 2) > > > > > > > > > > > > 1 / log 10 (base 2) = 0.301029995 > > > > > > > > So the formula becomes: > > > > > > > > Log X (base 10) = 0.301029995 * log X (base 2) > > > > > > > > And a Log base conversion from base 2 to base 10 is > > achieved using one > > > > floating point multiply. > > > > > > > > > > > > Now in regard to the question how to implement the Log > > in a table (or in > > > > calculation): > > > > You just need a table of one decade: Build the table for > > fractions in the > > > > range of 1 to 2 ( log 1 (base 2) - log 2 (base 2) ). > > > > > > > > Then Log (base 2) of powers of 2 are whole numbers. For > > example > > > > Log 1 (base 2) = 0 > > > > Log 2 (base 2) = 1 > > > > Log 4 (base 2] = 2 > > > > Log 8 (base 2) = 3 > > > > Log 16 (base 2) = 4 > > > > ... > > > > > > > > Meaning, the integer part is of the result is n, when > > your source number X > > > > is in the range: > > > > 2^n <= X < 2^(n+1) > > > > when n is an integer. > > > > > > > > Then the fraction part of the log is determined from the > > look-up table for > > > > X / (2^n) . > > > > > > > > Let's take an actual example: > > > > Calculate Log 15 (base 2) according to the above method: > > > > (X = 15) > > > > > > > > 15 is between 2^3 and 2^4 so the integer part of the > > result is 3. > > > > > > > > The fraction that we will look up in the table will be: > > > > Fraction = 15 / 2^3 = 1.875 > > > > > > > > Then you will look up in the table: > > > > Log 1.875 (base 2) = 0.906890595 > > > > > > > > and the final result of the integer and the fraction is: > > > > > > > > Log 15 (base 2) = 3.906890595 > > > > > > > > > > > > Hope this helps, > > > > Doron > > > > Nohau Corporation > > > > HC12 In-Circuit Emulators > > > > www.nohau.com/emul12pc.html > > > > > > > > At 06:50 31/05/2004 +0000, you wrote: > > > > >--- In , Gary Olmstead > > <garyolmstead@e...> wrote: > > > > > > > > > >Hi Gary, > > > > > > > > > > > I am looking at converting some values and what I > > need to do is determine > > > > > > the Log (base10) of say ten bit values in assembler. > > > > > > > > > > > > >The question is, are there any clever mathematical > > solutions about that > > > > > > >can be set up in assembler? > > > > > > > > > > > > Ever consider log(base 2)? I haven't tried it, so I > > can't comment on it's > > > > > > performance, but you asked for clever, and that was > > about as clever as I > > > > > > could get offhand. > > > > > > > > > >My somewhat superanuated mathematical skills tell me > > that that leaves me > > > > >with some base conversions, is that a worthwile shift? > > > > > > > > > >Cheers, > > > > > > > > > >Theo |
|
All: There are a couple of solutions that I have used in the past with good success. One is the HP HCTL2016 series quadrature decoder IC. It is basically a counter, which is fed filtered and processed quadrature pulses from an encoder. You can simply read the counter in either 8 bit or 16 bit format. The device is made to reside on the Data Bus, but if you are not using expanded mode you can run it off an 8 bit port. Just read the counter value on a timed interrupt, a few to a few hundred milliseconds, depending on your encoder speed. The device will keep track of all movements in either direction in the meantime. Also has the advantage of multiplying quadrature resolution by X4. The other is the LSI Inc. LS7082/3/4 series quadrature converters. These 8 pin chips convert quadrature encoder inputs to either pulse and direction, or up clock and down clock signals. They are configurable to X1, X2, or X4 operation, and are very simple to use. However, they have no internal counter, so the pulses must be processed immediately. > I too have found this very annoying shortcoming on HC12 counters. > The 320F24x is far nicer ;-) > > The only solution I have thought of, but not tested is to use a > PIC12C508 or ATtiny12 (I have code for the PIC) to decode the > quadrature into count and direction. The outputs of this device > are up-clock/down-clock. Then feed these clocks to the alternate > pulse accumulators (PA and PB) on a 9S12D device. The pulse > accumulator difference is the current count. The tricky bit seems > to be that you would need to reset these counters before they > overflow (no big deal), but making the read-reset operation > indivisible to the external clock may lead to lost counts. > > My application can require 10KHz to 20KHz counting, so interrupts > put a very heavy load on the processor. Regards, Darrell Norquay Datalog Technology Inc. Calgary, Alberta, Canada Voice: (403) 243-2220 Fax: (403) 243-2872 Email: Web: www.datalog.ab.ca |
|
The data sheet for the HP HCTL2000/16/20 gives a comprehensive description of the hidden mechanisms and internal secrets of their chip including examples of interfacing to the 'HC11. The only quibble that I have with the HP decoder is its parallel interface so you may have to do a bit of interface design. Just treat its data port as a ram chip. Once you understand the operation of quad encoders you should be able to interface it directly to the 'HC12 FOR LOW FREQUENCY OPERATION. Just invest the time needed to learn IC and OC operations and have at it. Actually, the quadrature decoding only takes a couple of XOR gates and perhaps a couple of inverters after the digital filtering that is inherent in the HCTL2000 encoders. THIS FILTERING IS IMPORTANT, especially in industrial environments. The actual decoding is almost trivial in software. Just build yourself a little state machine to determine whether you just had an up or a down transition and bump the counter the right direction. Its a fun little project to play with. Best wishes, Bob Smith --- Avoid computer viruses, Practice safe hex --- -- Specializing in small, cost effective embedded control systems -- http://www.smithmachineworks.com/embedprod.html Robert L. (Bob) Smith Smith Machine Works, Inc. 9900 Lumlay Road Richmond, VA 23236 804/745-2608 ----- Original Message ----- From: "Darrell N." <> To: <> Sent: Tuesday, June 01, 2004 12:50 PM Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > All: > > There are a couple of solutions that I have used in the past > with good success. One is the HP HCTL2016 series quadrature > decoder IC. It is basically a counter, which is fed filtered > and processed quadrature pulses from an encoder. You can simply > read the counter in either 8 bit or 16 bit format. The device > is made to reside on the Data Bus, but if you are not using > expanded mode you can run it off an 8 bit port. Just read the > counter value on a timed interrupt, a few to a few hundred > milliseconds, depending on your encoder speed. The device will > keep track of all movements in either direction in the meantime. > Also has the advantage of multiplying quadrature resolution by > X4. > > The other is the LSI Inc. LS7082/3/4 series quadrature > converters. These 8 pin chips convert quadrature encoder inputs > to either pulse and direction, or up clock and down clock > signals. They are configurable to X1, X2, or X4 operation, and > are very simple to use. However, they have no internal counter, > so the pulses must be processed immediately. > > I too have found this very annoying shortcoming on HC12 counters. > > The 320F24x is far nicer ;-) > > > > The only solution I have thought of, but not tested is to use a > > PIC12C508 or ATtiny12 (I have code for the PIC) to decode the > > quadrature into count and direction. The outputs of this device > > are up-clock/down-clock. Then feed these clocks to the alternate > > pulse accumulators (PA and PB) on a 9S12D device. The pulse > > accumulator difference is the current count. The tricky bit seems > > to be that you would need to reset these counters before they > > overflow (no big deal), but making the read-reset operation > > indivisible to the external clock may lead to lost counts. > > > > My application can require 10KHz to 20KHz counting, so interrupts > > put a very heavy load on the processor. > Regards, > Darrell Norquay > > Datalog Technology Inc. Calgary, Alberta, Canada > Voice: (403) 243-2220 Fax: (403) 243-2872 > Email: Web: www.datalog.ab.ca > > --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > > Yahoo! Groups Sponsor > ADVERTISEMENT > -------------------------------------------------------------------------- ------ > Yahoo! Groups Links > > a.. To |
|
|
|
Yes, on the last project I did we used the LS7084 and chose a processor (the Temic now
Atmel 8051) that had Count and Direction inputs. On overflow/underflow interrupts, we decrement the external 8 bit high order byte to give us a 24 bit counter. With a 400 line counter and x4 we don't miss a pulse. I was just hoping that I had really seen an app note from Motorola on configuring their counters to do quadrature like the TI devices. Ah well such is life. Thanks for the info. John Wireless CAN with the CANRF module now available. http://www.autoartisans.com/products Automation Artisans Inc. Ph. 1 250 544 4950 > -----Original Message----- > From: Bob Smith [mailto:] > Sent: Tuesday, June 01, 2004 10:04 AM > To: > Subject: Re: [68HC12] 9S12DG256 Quadrature Encoder Support. > The data sheet for the HP HCTL2000/16/20 gives a > comprehensive description > of the hidden mechanisms and internal secrets of their chip including > examples of interfacing to the 'HC11. The only quibble that > I have with the > HP decoder is its parallel interface so you may have to do a bit of > interface design. Just treat its data port as a ram chip. > > Once you understand the operation of quad encoders you should > be able to > interface it directly to the 'HC12 FOR LOW FREQUENCY > OPERATION. Just invest > the time needed to learn IC and OC operations and have at it. > > Actually, the quadrature decoding only takes a couple of XOR gates and > perhaps a couple of inverters after the digital filtering > that is inherent > in the HCTL2000 encoders. THIS FILTERING IS IMPORTANT, especially in > industrial environments. The actual decoding is almost > trivial in software. > Just build yourself a little state machine to determine > whether you just had > an up or a down transition and bump the counter the right > direction. Its a > fun little project to play with. > > Best wishes, Bob Smith > --- Avoid computer viruses, Practice safe hex --- > > -- Specializing in small, cost effective > embedded control systems -- > > http://www.smithmachineworks.com/embedprod.html > Robert L. (Bob) Smith > Smith Machine Works, Inc. > 9900 Lumlay Road > Richmond, VA 23236 804/745-2608 > > ----- Original Message ----- > From: "Darrell N." <> > To: <> > Sent: Tuesday, June 01, 2004 12:50 PM > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > > All: > > > > There are a couple of solutions that I have used in the past > > with good success. One is the HP HCTL2016 series quadrature > > decoder IC. It is basically a counter, which is fed filtered > > and processed quadrature pulses from an encoder. You can simply > > read the counter in either 8 bit or 16 bit format. The device > > is made to reside on the Data Bus, but if you are not using > > expanded mode you can run it off an 8 bit port. Just read the > > counter value on a timed interrupt, a few to a few hundred > > milliseconds, depending on your encoder speed. The device will > > keep track of all movements in either direction in the meantime. > > Also has the advantage of multiplying quadrature resolution by > > X4. > > > > The other is the LSI Inc. LS7082/3/4 series quadrature > > converters. These 8 pin chips convert quadrature encoder inputs > > to either pulse and direction, or up clock and down clock > > signals. They are configurable to X1, X2, or X4 operation, and > > are very simple to use. However, they have no internal counter, > > so the pulses must be processed immediately. > > > > > > > I too have found this very annoying shortcoming on HC12 counters. > > > The 320F24x is far nicer ;-) > > > > > > The only solution I have thought of, but not tested is to use a > > > PIC12C508 or ATtiny12 (I have code for the PIC) to decode the > > > quadrature into count and direction. The outputs of this device > > > are up-clock/down-clock. Then feed these clocks to the alternate > > > pulse accumulators (PA and PB) on a 9S12D device. The pulse > > > accumulator difference is the current count. The tricky bit seems > > > to be that you would need to reset these counters before they > > > overflow (no big deal), but making the read-reset operation > > > indivisible to the external clock may lead to lost counts. > > > > > > My application can require 10KHz to 20KHz counting, so interrupts > > > put a very heavy load on the processor. > > > > > > Regards, > > Darrell Norquay > > > > Datalog Technology Inc. Calgary, Alberta, Canada > > Voice: (403) 243-2220 Fax: (403) 243-2872 > > Email: Web: www.datalog.ab.ca > > > > > > > > --------------------------------------------------------To > learn more > about Motorola Microcontrollers, please visit > > http://www.motorola.com/mcu > > o learn more about Motorola Microcontrollers, please visit > > http://www.motorola.com/mcu > > > > > > > > Yahoo! Groups Sponsor > > ADVERTISEMENT > > > > > > > > > > > > > -------------------------------------------------------------- > ------------ > ------ > > Yahoo! Groups Links > > > > a.. To > > > > > > ------------------------ Yahoo! Groups Sponsor > --------------------~--> > Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar. > Now with Pop-Up Blocker. Get it for free! > http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/dN_tlB/TM > -------------------------------------------------------------- > ------~-> > > --------------------------------------------------------To > learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > > Yahoo! Groups Links |
|
Theo, Omitting, but not ignoring previous parts of (interesting) message thread ;o) On Monday, May 31, 2004 12:00 AM you were: - >looking at converting some values and what I need to do is determine the Log (base10) of say ten bit values in assembler. I take it you have a signal that varies exponentially and you want to linerise it. Could you not use a log amplifier? This would avoid the math(s) and has the added advantage of providing greater dynamic range. I have used the Burr Brown LOG100, which did 3-4 decades, but don't think this is available any more (and was expensive++). This could operate in log ratio mode where you have a reference input in addition to a measuring input. You would have to get your (HC12?) ADC into bipolar mode (another amplifier?) to read ratios that are less than one. The log of anything less than 1 is negative, but the log of nought is naughty (the British are famous for their puns). Take a look at the ADL5310. As you mentioned 'optical density', this device has 2 independent channels optimised for photodiode interfacing. I have no experience with this device and don't know if it would work for you. Regards, Mike. |
|
|
|
Theo, For more in this line, and some other methods see: "Math Toolkit for Real-Time Programming" by Jack W. Crenshaw, ISBN: 1-929629-09-5 See: http://www.cmpbooks.com/product/1054 Chapter 7 covers log calculation methods, including "bitlog", a fast 16-bit integer to integer log approximation. Hope this helps, Steve Russell Nohau Emulators At 12:55 AM 5/31/2004, Doron Fael wrote: >Theo, > >Log base conversion is easy: > >Log X (base 10) = log X (base 2) / log 10 (base 2) >1 / log 10 (base 2) = 0.301029995 > >So the formula becomes: > >Log X (base 10) = 0.301029995 * log X (base 2) > >And a Log base conversion from base 2 to base 10 is achieved using one >floating point multiply. >Now in regard to the question how to implement the Log in a table (or in >calculation): >You just need a table of one decade: Build the table for fractions in the >range of 1 to 2 ( log 1 (base 2) - log 2 (base 2) ). > >Then Log (base 2) of powers of 2 are whole numbers. For example >Log 1 (base 2) = 0 >Log 2 (base 2) = 1 >Log 4 (base 2] = 2 >Log 8 (base 2) = 3 >Log 16 (base 2) = 4 >... > >Meaning, the integer part is of the result is n, when your source number X >is in the range: >2^n <= X < 2^(n+1) >when n is an integer. > >Then the fraction part of the log is determined from the look-up table for >X / (2^n) . > >Let's take an actual example: >Calculate Log 15 (base 2) according to the above method: >(X = 15) > >15 is between 2^3 and 2^4 so the integer part of the result is 3. > >The fraction that we will look up in the table will be: >Fraction = 15 / 2^3 = 1.875 > >Then you will look up in the table: >Log 1.875 (base 2) = 0.906890595 > >and the final result of the integer and the fraction is: > >Log 15 (base 2) = 3.906890595 >Hope this helps, >Doron >Nohau Corporation >HC12 In-Circuit Emulators >www.nohau.com/emul12pc.html > >At 06:50 31/05/2004 +0000, you wrote: > >--- In , Gary Olmstead <garyolmstead@e...> wrote: > > > >Hi Gary, > > > > > I am looking at converting some values and what I need to do is determine > > > the Log (base10) of say ten bit values in assembler. > > > > > > >The question is, are there any clever mathematical solutions about that > > > >can be set up in assembler? > > > > > > Ever consider log(base 2)? I haven't tried it, so I can't comment on > it's > > > performance, but you asked for clever, and that was about as clever as I > > > could get offhand. > > > >My somewhat superanuated mathematical skills tell me that that leaves me > >with some base conversions, is that a worthwile shift? > > > >Cheers, > > > >Theo |
|
|
|
I'm not clear on what the big deal is. Two inputs, one interrupt. At every (choose one) falling/rising edge, generate an interrupt which examines the level of the other input. One level increments a counter, the other level decrements the count. Shouldn't take long, even at 20K Hz. And the problem is.....? Gary Olmstead Toucan Technology Ventura CA At 09:05 PM 5/31/04, you wrote: >John, > >I too have found this very annoying shortcoming on HC12 counters. The >320F24x is far nicer ;-) > >The only solution I have thought of, but not tested is to use a >PIC12C508 or ATtiny12 (I have code for the PIC) to decode the quadrature >into count and direction. The outputs of this device are >up-clock/down-clock. Then feed these clocks to the alternate pulse >accumulators (PA and PB) on a 9S12D device. The pulse accumulator >difference is the current count. The tricky bit seems to be that you >would need to reset these counters before they overflow (no big deal), >but making the read-reset operation indivisible to the external clock >may lead to lost counts. > >My application can require 10KHz to 20KHz counting, so interrupts put a >very heavy load on the processor. > >I will be curious to know how you solve the problem. |
|
|
|
The problem is that a valid "count" consists of a complete sequence of A
and B pulses - you can't just take an arbitrary edge and be done with it! There are a bunch of pathological cases that real encoders produce have that will mess up the "simple" solution. (This would be the voice of experience.) Consider an encoder sitting still -- well actually slightly vibrating like everything really does. You have a A and a B output which are generally produced by something blocking a light. Since the output is mechanically generated, you can easily have the start of a count pulse say A -- then the encoder direction reverses and A drops - -there is no B pulse at all! Valid Counts::: A__---------______ B____---------____ or in the other direction A____---------____ B__---------______ Singleton, non- count events...... A____---------____ B_______________ or in the other direction A_______________ B____---------____ Of course you can get a zillion of these if the encoder is just sitting on the edge of a transition.. Depending on you implementation each one may show up as a count! But wait there's still more. You can also get non-overlapped A-B pulses if the encoder rotates little further before backing up.. This will lead to: A __|-------------|_____ B_____------_________ or in the other direction... A_____------_________ B __|-------------|_____ There are other cases as well -- In short, there is a reason for the special encoder chips (like the LSI7183, which I use) and others mentioned which take care of these bizarre cases. Also remember that the pulse width will decrease with the speed of the encoder.. In extreme (high speed) cases, the pulse width will dip below the "allowable" pulse width (300ns on the 7183) and be considered noise and thrown out! If your encoder moves really fast in one direction and slow in the other, the position will appear to back up, each time the machine cycles! Bill ----- Original Message ----- From: "Gary Olmstead" <> To: <> Sent: Friday, June 04, 2004 11:03 AM Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > I'm not clear on what the big deal is. Two inputs, one interrupt. At > every (choose one) falling/rising edge, generate an interrupt which > examines the level of the other input. One level increments a counter, the > other level decrements the count. Shouldn't take long, even at 20K Hz. > > And the problem is.....? > > Gary Olmstead > Toucan Technology > Ventura CA > At 09:05 PM 5/31/04, you wrote: > >John, > > > >I too have found this very annoying shortcoming on HC12 counters. The > >320F24x is far nicer ;-) > > > >The only solution I have thought of, but not tested is to use a > >PIC12C508 or ATtiny12 (I have code for the PIC) to decode the quadrature > >into count and direction. The outputs of this device are > >up-clock/down-clock. Then feed these clocks to the alternate pulse > >accumulators (PA and PB) on a 9S12D device. The pulse accumulator > >difference is the current count. The tricky bit seems to be that you > >would need to reset these counters before they overflow (no big deal), > >but making the read-reset operation indivisible to the external clock > >may lead to lost counts. > > > >My application can require 10KHz to 20KHz counting, so interrupts put a > >very heavy load on the processor. > > > >I will be curious to know how you solve the problem. > --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > > Yahoo! Groups Links |
|
|
|
Hi William, Well written! And even doing all this with a Micro and interrupts means that the maximum jitter or encoder speed can't exceed the entire interrupt routine latency. John > -----Original Message----- > From: William M. Derby Jr. [mailto:] > Sent: Friday, June 04, 2004 11:30 AM > To: > Subject: Re: [68HC12] 9S12DG256 Quadrature Encoder Support. > The problem is that a valid "count" consists of a complete > sequence of A and > B pulses - you can't just take an arbitrary edge and be done > with it! There > are a bunch of pathological cases that real encoders produce > have that will > mess up the "simple" solution. (This would be the voice of > experience.) > > Consider an encoder sitting still -- well actually slightly > vibrating like > everything really does. You have a A and a B output which are > generally > produced by something blocking a light. Since the output is > mechanically > generated, you can easily have the start of a count pulse say > A -- then the > encoder direction reverses and A drops - -there is no B pulse at all! > > Valid Counts::: > A__---------______ > B____---------____ > > or in the other direction > > A____---------____ > B__---------______ > > Singleton, non- count events...... > > A____---------____ > B_______________ > > or in the other direction > > A_______________ > B____---------____ > Of course you can get a zillion of these if the encoder is > just sitting on > the edge of a transition.. > Depending on you implementation each one may show up as a > count! But wait > there's still more. > You can also get non-overlapped A-B pulses if the encoder > rotates little > further before backing up.. > This will lead to: > > A __|-------------|_____ > B_____------_________ > > or in the other direction... > > A_____------_________ > B __|-------------|_____ > > There are other cases as well -- In short, there is a reason > for the special > encoder chips (like the > LSI7183, which I use) and others mentioned which take care of > these bizarre > cases. Also remember that the pulse width will decrease with > the speed of > the encoder.. In extreme (high speed) cases, the pulse width > will dip below > the "allowable" pulse width (300ns on the 7183) and be > considered noise and > thrown out! If your encoder moves really fast in one > direction and slow in > the other, the position will appear to back up, each time the machine > cycles! > > Bill > ----- Original Message ----- > From: "Gary Olmstead" <> > To: <> > Sent: Friday, June 04, 2004 11:03 AM > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > > I'm not clear on what the big deal is. Two inputs, one > interrupt. At > > every (choose one) falling/rising edge, generate an interrupt which > > examines the level of the other input. One level > increments a counter, > the > > other level decrements the count. Shouldn't take long, > even at 20K Hz. > > > > And the problem is.....? > > > > Gary Olmstead > > Toucan Technology > > Ventura CA > > > > > > At 09:05 PM 5/31/04, you wrote: > > >John, > > > > > >I too have found this very annoying shortcoming on HC12 > counters. The > > >320F24x is far nicer ;-) > > > > > >The only solution I have thought of, but not tested is to use a > > >PIC12C508 or ATtiny12 (I have code for the PIC) to decode > the quadrature > > >into count and direction. The outputs of this device are > > >up-clock/down-clock. Then feed these clocks to the alternate pulse > > >accumulators (PA and PB) on a 9S12D device. The pulse accumulator > > >difference is the current count. The tricky bit seems to > be that you > > >would need to reset these counters before they overflow > (no big deal), > > >but making the read-reset operation indivisible to the > external clock > > >may lead to lost counts. > > > > > >My application can require 10KHz to 20KHz counting, so > interrupts put a > > >very heavy load on the processor. > > > > > >I will be curious to know how you solve the problem. > > > > > > > > > > > > --------------------------------------------------------To > learn more > about Motorola Microcontrollers, please visit > > http://www.motorola.com/mcu > > o learn more about Motorola Microcontrollers, please visit > > http://www.motorola.com/mcu > > > > Yahoo! Groups Links > > > > > > > > > > > > > ------------------------ Yahoo! Groups Sponsor > --------------------~--> > Yahoo! Domains - Claim yours for only $14.70 > http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/dN_tlB/TM > -------------------------------------------------------------- > ------~-> > > --------------------------------------------------------To > learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > > Yahoo! Groups Links |
|
Gary, Scaleability. Probably unfair to have thrown in the 20Khz figure. But by way of example, my first application uses a 2.5mm pitch belt running over a 16 tooth pulley: 40mm linear belt movement/rev. This is coupled to a 500ppr encoder and maximum linear speed is specified at 200mm/sec or 5 revs/sec = 2500counts/sec. Since a quadrature device provides four edges per count this is 10Khz. An AVR design at 8Mhz handles this and some actual control functions OK. Suddenly I have a customer trying to use the device with a 2000ppr encoder because this is the only encoder available on the machine and there is nowhere else to mount one and he wants to use hundreds and can't I do something. This failed on the AVR and certainly the 10Khz won't work on my HC12 design which is busy also trying to talk CAN to another HC12, manage 96IO points (80 of which are interface by three SPI ports and all tested at 1ms intervals) and RS232 to my host etc etc. A little bit of hardware help here goes a long way! Regards, Jonathan. -----Original Message----- From: Gary Olmstead [mailto:] Sent: Saturday, June 05, 2004 1:04 AM To: Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. I'm not clear on what the big deal is. Two inputs, one interrupt. At every (choose one) falling/rising edge, generate an interrupt which examines the level of the other input. One level increments a counter, the other level decrements the count. Shouldn't take long, even at 20K Hz. And the problem is.....? Gary Olmstead Toucan Technology Ventura CA At 09:05 PM 5/31/04, you wrote: >John, > >I too have found this very annoying shortcoming on HC12 counters. The >320F24x is far nicer ;-) > >The only solution I have thought of, but not tested is to use a >PIC12C508 or ATtiny12 (I have code for the PIC) to decode the quadrature >into count and direction. The outputs of this device are >up-clock/down-clock. Then feed these clocks to the alternate pulse >accumulators (PA and PB) on a 9S12D device. The pulse accumulator >difference is the current count. The tricky bit seems to be that you >would need to reset these counters before they overflow (no big deal), >but making the read-reset operation indivisible to the external clock >may lead to lost counts. > >My application can require 10KHz to 20KHz counting, so interrupts put a >very heavy load on the processor. > >I will be curious to know how you solve the problem. --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Sponsor ADVERTISEMENT <http://rd.yahoo.com/SIG=129kbf85o/M=298184.5022502.6152625.3001176/D=gr oups/S=1706554205:HM/EXP=1086447635/A=2164330/R=0/SIG=11eamf8g4/*http:/w ww.netflix.com/Default?mqso=60183350> click here <http://us.adserver.yahoo.com/l?M=298184.5022502.6152625.3001176/D=group s/S=:HM/A=2164330/rand=506941908> _____ > Service. [Non-text portions of this message have been removed] |
|
There is a really good Agilent app-note describing their decoder chips. It describes a state machine used for handling and filtering these sequences. I use that machine in my soft decoders. Regards, Jonathan. -----Original Message----- From: William M. Derby Jr. [mailto:] Sent: Saturday, June 05, 2004 4:30 AM To: Subject: Re: [68HC12] 9S12DG256 Quadrature Encoder Support. The problem is that a valid "count" consists of a complete sequence of A and B pulses - you can't just take an arbitrary edge and be done with it! There are a bunch of pathological cases that real encoders produce have that will mess up the "simple" solution. (This would be the voice of experience.) Consider an encoder sitting still -- well actually slightly vibrating like everything really does. You have a A and a B output which are generally produced by something blocking a light. Since the output is mechanically generated, you can easily have the start of a count pulse say A -- then the encoder direction reverses and A drops - -there is no B pulse at all! Valid Counts::: A__---------______ B____---------____ or in the other direction A____---------____ B__---------______ Singleton, non- count events...... A____---------____ B_______________ or in the other direction A_______________ B____---------____ Of course you can get a zillion of these if the encoder is just sitting on the edge of a transition.. Depending on you implementation each one may show up as a count! But wait there's still more. You can also get non-overlapped A-B pulses if the encoder rotates little further before backing up.. This will lead to: A __|-------------|_____ B_____------_________ or in the other direction... A_____------_________ B __|-------------|_____ There are other cases as well -- In short, there is a reason for the special encoder chips (like the LSI7183, which I use) and others mentioned which take care of these bizarre cases. Also remember that the pulse width will decrease with the speed of the encoder.. In extreme (high speed) cases, the pulse width will dip below the "allowable" pulse width (300ns on the 7183) and be considered noise and thrown out! If your encoder moves really fast in one direction and slow in the other, the position will appear to back up, each time the machine cycles! Bill ----- Original Message ----- From: "Gary Olmstead" <> To: <> Sent: Friday, June 04, 2004 11:03 AM Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > I'm not clear on what the big deal is. Two inputs, one interrupt. At > every (choose one) falling/rising edge, generate an interrupt which > examines the level of the other input. One level increments a counter, the > other level decrements the count. Shouldn't take long, even at 20K Hz. > > And the problem is.....? > > Gary Olmstead > Toucan Technology > Ventura CA > At 09:05 PM 5/31/04, you wrote: > >John, > > > >I too have found this very annoying shortcoming on HC12 counters. The > >320F24x is far nicer ;-) > > > >The only solution I have thought of, but not tested is to use a > >PIC12C508 or ATtiny12 (I have code for the PIC) to decode the quadrature > >into count and direction. The outputs of this device are > >up-clock/down-clock. Then feed these clocks to the alternate pulse > >accumulators (PA and PB) on a 9S12D device. The pulse accumulator > >difference is the current count. The tricky bit seems to be that you > >would need to reset these counters before they overflow (no big deal), > >but making the read-reset operation indivisible to the external clock > >may lead to lost counts. > > > >My application can require 10KHz to 20KHz counting, so interrupts put a > >very heavy load on the processor. > > > >I will be curious to know how you solve the problem. > --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > > > Service. [Non-text portions of this message have been removed] |
|
|
|
Hi Jonathan, Any chance you know of the link to that app note? Thanks, John Wireless CAN with the CANRF module now available. http://www.autoartisans.com/products Automation Artisans Inc. Ph. 1 250 544 4950 > -----Original Message----- > From: Jonathan Masters [mailto:] > Sent: Friday, June 04, 2004 3:10 PM > To: > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > There is a really good Agilent app-note describing their > decoder chips. > It describes a state machine used for handling and filtering these > sequences. I use that machine in my soft decoders. > > Regards, > > Jonathan. > > -----Original Message----- > From: William M. Derby Jr. [mailto:] > Sent: Saturday, June 05, 2004 4:30 AM > To: > Subject: Re: [68HC12] 9S12DG256 Quadrature Encoder Support. > > The problem is that a valid "count" consists of a complete > sequence of A > and > B pulses - you can't just take an arbitrary edge and be done with it! > There > are a bunch of pathological cases that real encoders produce have that > will > mess up the "simple" solution. (This would be the voice of > experience.) > > Consider an encoder sitting still -- well actually slightly vibrating > like > everything really does. You have a A and a B output which are > generally > produced by something blocking a light. Since the output is > mechanically > generated, you can easily have the start of a count pulse say > A -- then > the > encoder direction reverses and A drops - -there is no B pulse at all! > > Valid Counts::: > A__---------______ > B____---------____ > > or in the other direction > > A____---------____ > B__---------______ > > Singleton, non- count events...... > > A____---------____ > B_______________ > > or in the other direction > > A_______________ > B____---------____ > Of course you can get a zillion of these if the encoder is > just sitting > on > the edge of a transition.. > Depending on you implementation each one may show up as a count! But > wait > there's still more. > You can also get non-overlapped A-B pulses if the encoder rotates > little > further before backing up.. > This will lead to: > > A __|-------------|_____ > B_____------_________ > > or in the other direction... > > A_____------_________ > B __|-------------|_____ > > There are other cases as well -- In short, there is a reason for the > special > encoder chips (like the > LSI7183, which I use) and others mentioned which take care of these > bizarre > cases. Also remember that the pulse width will decrease with the speed > of > the encoder.. In extreme (high speed) cases, the pulse width will dip > below > the "allowable" pulse width (300ns on the 7183) and be > considered noise > and > thrown out! If your encoder moves really fast in one > direction and slow > in > the other, the position will appear to back up, each time the machine > cycles! > > Bill > ----- Original Message ----- > From: "Gary Olmstead" <> > To: <> > Sent: Friday, June 04, 2004 11:03 AM > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > > I'm not clear on what the big deal is. Two inputs, one > interrupt. At > > every (choose one) falling/rising edge, generate an interrupt which > > examines the level of the other input. One level increments a > counter, > the > > other level decrements the count. Shouldn't take long, even at 20K > Hz. > > > > And the problem is.....? > > > > Gary Olmstead > > Toucan Technology > > Ventura CA > > > > > > At 09:05 PM 5/31/04, you wrote: > > >John, > > > > > >I too have found this very annoying shortcoming on HC12 > counters. The > > >320F24x is far nicer ;-) > > > > > >The only solution I have thought of, but not tested is to use a > > >PIC12C508 or ATtiny12 (I have code for the PIC) to decode the > quadrature > > >into count and direction. The outputs of this device are > > >up-clock/down-clock. Then feed these clocks to the alternate pulse > > >accumulators (PA and PB) on a 9S12D device. The pulse accumulator > > >difference is the current count. The tricky bit seems to > be that you > > >would need to reset these counters before they overflow (no big > deal), > > >but making the read-reset operation indivisible to the > external clock > > >may lead to lost counts. > > > > > >My application can require 10KHz to 20KHz counting, so > interrupts put > a > > >very heavy load on the processor. > > > > > >I will be curious to know how you solve the problem. > > > > > > > > > > > > --------------------------------------------------------To > learn more > about Motorola Microcontrollers, please visit > > http://www.motorola.com/mcu > > o learn more about Motorola Microcontrollers, please visit > > http://www.motorola.com/mcu > > > > > Service. [Non-text portions of this message have been removed] --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Links |
|
|
|
John, Look at the HCTL-2000 data sheet, it has some great details in it. Darren Moore > -----Original Message----- > From: John Dammeyer [mailto:] > Sent: Saturday, 5 June 2004 08:31 > To: > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > Hi Jonathan, > > Any chance you know of the link to that app note? > > Thanks, > > John |
|
|
|
John, From my memory, this came from an old HP Optoelectronics Designers Catalog (1982-1984?). I think Darren's suggestion of the HCTL-2000 Data Sheet is a good start, but I am sure then information I used was a note on how to apply the HCTL-2000. Rgds, Jonathan. -----Original Message----- From: Darren [mailto:] Sent: Saturday, June 05, 2004 10:27 AM To: Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. John, Look at the HCTL-2000 data sheet, it has some great details in it. Darren Moore > -----Original Message----- > From: John Dammeyer [mailto:] > Sent: Saturday, 5 June 2004 08:31 > To: > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > Hi Jonathan, > > Any chance you know of the link to that app note? > > Thanks, > > John --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Sponsor ADVERTISEMENT <http://rd.yahoo.com/SIG=12902es9f/M=298184.5022502.6152625.3001176/D=gr oups/S=1706554205:HM/EXP=1086481688/A=2164330/R=0/SIG=11eamf8g4/*http:/w ww.netflix.com/Default?mqso=60183350> click here <http://us.adserver.yahoo.com/l?M=298184.5022502.6152625.3001176/D=group s/S=:HM/A=2164330/rand=233273975> _____ > Service. [Non-text portions of this message have been removed] |
|
|
|
John all, The 1988-1988 Optoelectronic designers catalog is the data book I have. Show a logic diagram of the input filter etc.. Darren Moore > -----Original Message----- > From: Jonathan Masters [mailto:] > Sent: Saturday, 5 June 2004 11:52 > John, > > >From my memory, this came from an old HP Optoelectronics Designers > Catalog (1982-1984?). I think Darren's suggestion of the > HCTL-2000 Data > Sheet is a good start, but I am sure then information I used > was a note > on how to apply the HCTL-2000. > > Rgds, > > Jonathan. > > -----Original Message----- > From: Darren [mailto:] > Sent: Saturday, June 05, 2004 10:27 AM > To: > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > John, > > Look at the HCTL-2000 data sheet, it has some > great details in it. > > Darren Moore > > -----Original Message----- > > From: John Dammeyer [mailto:] > > Sent: Saturday, 5 June 2004 08:31 > > To: > > Subject: RE: [68HC12] 9S12DG256 Quadrature Encoder Support. > > > > > > Hi Jonathan, > > > > Any chance you know of the link to that app note? > > > > Thanks, > > > > John > > --------------------------------------------------------To learn more > about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > > Yahoo! Groups Sponsor > ADVERTISEMENT > > <http://rd.yahoo.com/SIG=12902es9f/M=298184.5022502.6152625.30 > 01176/D=gr > oups/S=1706554205:HM/EXP=1086481688/A=2164330/R=0/SIG=11eamf8g > 4/*http:/w > ww.netflix.com/Default?mqso=60183350> click here <http://us.adserver.yahoo.com/l?M=298184.5022502.6152625.3001176/D=group s/S=:HM/A=2164330/rand=233273975> _____ > Service. [Non-text portions of this message have been removed] --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Links |