OT: Codewheel Generator for Homebrew Optical Encoders

Tom2000

Senior Member
Howdy, Folks,

I've just released a freeware Win XP/Vista program that generates and prints codewheel images that you can use to build homebrew optical encoders.

I've included one wheel type that's of particular interest to folks here who are experimenting with robotics, motor positioning and control, and, for Wrenow, even gun turret positioning. :)

The Single Track with Index wheel lets you cobble a quick and dirty position sensor without any need for precision mechanical assembly. Design and print a codewheel, grab a couple of LEDs and phototransistors and your hot glue gun, and voila! one optical encoder.

You can find the program here:

http://www.mindspring.com/~tom2000/Delphi/Codewheel.html

I'm very grateful to our beloved moderator, Dippy, for his alpha and beta test assistance, putting up with my stupidity, his encouragement, diligent testing, and excellent feedback, and his great ideas. Folks, this wouldn't be half the program it is without his hard work.

Have fun. I hope that the program will let you do something that you haven't been able to do before now.

Tom
 

moxhamj

New Member
Absolutely brilliant. That could go straight to the completed project section (or for Australians - to the pool room). Very useful for those applications where a pot will wear out or you need full circle resolution. Now I can build that weather vane project!
 
Last edited:

Dippy

Moderator
You're very welcome. You did the hard work Tom, I just did the moaning :)

Its a great piece of code, very easy to use, very versatile and will help many people.

Yes, it should go into Finished Projects otherwise it'll get lost here.
 
Last edited:

evanh

Senior Member
Nice drawings. They look correct! :) One can also compare the two absolute discs and see how Gray coding is lower bandwidth than the equivalent binary coding.

Hate to burst the bubble too much here though but there is only two useful types. The Single track and the Gray coded absolute one. Binary coding is error prone and the other multi track incrementals are all variations of the single track.

Single track encoders usually have two sensors on the one track for producing quadrature encoded data. Quadrature is itself the two most significant bits of a Gray number.

Modern absolutes are trending away from using an actual Gray encoded disc to more compact and rugged designs with less parts but adding a DSP to convert from the raw sensor info to either non-absolute quadrature or absolute SSI.


Evan
 

Dippy

Moderator
"Binary coding is error prone"
- oh my goodness, you'd better phone up the dozens of companies that still make and sell binary rotary encoders ;)
 

Tom2000

Senior Member
Actually, that makes sense.

With a Gray coded wheel, only one bit changes state at each code transition. With binary, you might have from 1 to max bits changing.

A Gray-coded wheel would be less prone to problems caused by slight mechanical misalignment than would a binary wheel.

Tom


Let me expound on the above.

Let's say that you're using a binary wheel, and driving your interrupt routine off the transitions produced by the outer (finest resolution) track.

When your interrupt occurs, you check the state of the other bits to determine the wheel's code.

If the bits don't all "fire" at the same time, you'll have an error because the interrupt's snapshot will be reading the state of one or more of the other bits incorrectly.

With a Gray coded wheel, this isn't a factor. You'd probably net all bits into a single interrupt input to the processor. Whenever one bit changes to trigger the interrupt, you know that was the *only* bit that changed state. Thus, your interrupt's snapshot of all the other bits will be accurate.
 
Last edited:

nfk

Senior Member
Absolutely blinking marvellous. What a wonderful program - I will use it for sure.

Quick practical question - why are the wheels limited to 8-bits? (I am speaking as someone who has no experience of rotary encoders) I have an application for a camera mount where a high degree of (absolute not incremental) precision is required. Is it just a practical limitation of programming (e.g. screen size, etc.) or is there some other reason?

Whatever your answer, thanks for writing it!

Cheers,
Nigel

PS Hmmm...thinking about it, I guess I could always use the 'Custom' option to creat a wheel to go around the outside
 
Last edited:

moxhamj

New Member
What a really good explanation, Tom2000. I never really understood Gray code till now. The explanation makes sense, and it makes a practical microprocessor implementation much simpler as well. :)
 

Tom2000

Senior Member
Absolutely blinking marvellous. What a wonderful program - I will use it for sure.

Quick practical question - why are the wheels limited to 8-bits? (I am speaking as someone who has no experience of rotary encoders) I have an application for a camera mount where a high degree of (absolute not incremental) precision is required. Is it just a practical limitation of programming (e.g. screen size, etc.) or is there some other reason?

Whatever your answer, thanks for writing it!

Cheers,
Nigel

PS Hmmm...thinking about it, I guess I could always use the 'Custom' option to creat a wheel to go around the outside
For the most part, the 8 track limit is an arbitrary choice.

When I checked the catalogs for packaged multi-channel photosensors that might be used for absolute position wheels, a quick look-see turned up two of them. One was a 7-channel package, and the other was 13.

I didn't like the sound of a 7 track limit... I don't like odd numbers for those sorts of things, and releasing the program with a 7 track limit would have sounded even more arbitrary than an 8 track limit.

And 13? Well, you can see by the screen real estate that I occupied with the "ready reference" text, I designed my screen with enough room to accommodate 13 track data entry boxes. I gave that some serious thought.

But when you consider what a 13-track wheel would actually look like, you'll see that there would be 8192 cells on the outer track.

There's no home printer on the market today that could even come close to printing a wheel that finely divided. One would have to use photolithography for production, and a wide bed printer to generate the master. That is *waaaaaaaayyyyyy* outside the scope of the capabilities of my target user base. (And, I might add, the amount of memory installed in their machines.)

All I can recommend is, if you need a whole lot more resolution than a 256 cell wheel can produce, look for a precision absolute encoder on eBay. Since everyone wants quads, the absolute position encoders should go at very attractive prices.

If you need just a skosh more resolution, set up an 8 track absolute positioning encoder the usual way (with 8 photosensors mounted on some sort of bar) and add a second sensor on the outside track, mounted with a quadrature offset with respect to the bar sensors. That, and some clever software on your part, will double your resolution to 512 steps per revolution.

And. although I haven't really worked this out because the mechanical details make this approach impractical for the amateur to construct, you could add a third sensor to the outside track, with the bar and two extra sensors adjusted for symmetrical three phase operation. That approach would give you 1024 steps per rotation. But it would be a mechanical nightmare to build and adjust, and would probably lose its calibration if the temperature changed by more than a few degrees.

So. Eight tracks it is, and eight tracks it shall remain. I'll leave higher resolution stuff to the pros.

Tom
 
Last edited:

hippy

Technical Support
Staff member
I haven't tried it yet but it sounds good - is there any particular reason it cannot install on Windows 98 ?

On your web site you might want to change the six wheel type images. With my setup ( black background, ignore page colours ) the images aren't visible. Probably down to transparency setting, showing black on transparent and expecting the white to shine through.
 

Tom2000

Senior Member
I haven't tried it yet but it sounds good - is there any particular reason it cannot install on Windows 98 ?

On your web site you might want to change the six wheel type images. With my setup ( black background, ignore page colours ) the images aren't visible. Probably down to transparency setting, showing black on transparent and expecting the white to shine through.
Hippy, it actually might run on Win 98. I'm using an older Delphi package, written for XP, but Borland was pretty good about backward compatibility back in those days. I can't test it, though. I retired my last '98 machine a few years ago.

And why, for heavens sake, have you set your browser for those settings? Sounds really goth to me. You're a hippy, not a goth. For God's sake, man, would you get your lifestyle sorted out? You're sending mixed messages, and confusing the hell out of all of us! :) :) :)

Tom
 

hippy

Technical Support
Staff member
Clicking the .MSI gives an "Incorrect command line parameter" error under 98. It's not an MsiExec problem though because other .MSI's install okay using the same click. Latest InstMsiA is installed.

As to the choice of browser colours, and the same for my desktop - For sympathy ( and guilt inducing ), to cater for visual impairment - For righteousness, a monitor with a black background uses less energy than one with white, so I'm saving the planet :)

I hate it when people don't honour system colour settings in applications and force their colour schemes or, worse still, force just some so nothing's usable. I'll accept though that the problem is usually born out of ignorance rather than malice although technically illegal under the UK's Disability Act. Microsoft on the whole have done a good job but still fail spectacularly; Visual Studio a particularly notable pain ( one reason why I still prefer VB6 ). It's a nightmare trying to set XP up to counter Microsoft over-riding what I've explicitly asked for. I have no idea how Vista fares.
 

Dippy

Moderator
Tom, better change the image as I can see hippy going into SPM.

Also, if it's not easy to sort then just put "System Requirements: XP and Vista". Then that'll remove the 0.0001% of issues with people still stubbornly using Win98 :)
 

Tom2000

Senior Member
Clicking the .MSI gives an "Incorrect command line parameter" error under 98. It's not an MsiExec problem though because other .MSI's install okay using the same click. Latest InstMsiA is installed.

As to the choice of browser colours, and the same for my desktop - For sympathy ( and guilt inducing ), to cater for visual impairment - For righteousness, a monitor with a black background uses less energy than one with white, so I'm saving the planet :)
Hippy, I'll zip up the .exe and the .chm files, and post another link on my page. That will bypass the installer. Give me a few minutes.

And I'm very sorry about my comment. I was going for humor, and not trying to be insensitive. I didn't know about your visual impairment. I apologize.


Tom
 

hippy

Technical Support
Staff member
Absolutely amazing; thanks. Works perfectly on 98.

And honestly don't worry about your earlier riposte - I thought the Goth imagery was very funny :)

The great advantage of a white on black screen is that most people are scared to go anywhere near it because they aren't quite sure what it is, if it's windows or something else. I have a Sinclair Scientific calculator from way back which is reverse polish notation so no "=" key. For some reason it never got borrowed or stolen at school.
 

Tom2000

Senior Member
Absolutely amazing; thanks. Works perfectly on 98.

And honestly don't worry about your earlier riposte - I thought the Goth imagery was very funny :)

The great advantage of a white on black screen is that most people are scared to go anywhere near it because they aren't quite sure what it is, if it's windows or something else. I have a Sinclair Scientific calculator from way back which is reverse polish notation so no "=" key. For some reason it never got borrowed or stolen at school.
Thanks, Hippy. That's great to know. I'll update the info to reflect Win98 capability, and label the Alternate Installation section as the one folks should use for Win98 systems.

I'm very happy that you weren't insulted.

I remember the Sinclair Scientifics. I'm sort of an RPN fan. Matter of fact, I've got an HP-11C sitting right next to this compuer right now.

Enjoy the program!

Tom
 

hippy

Technical Support
Staff member
HP calculators ... remember this one ?

http://www.hpmuseum.org/98xx/9810n3qs.jpg

My first ever electronics project was designing one of these ( or something very much like it ) using TTL logic. It was never going to work, far too ambitious for my abilities and pocket money supply ! but I had hours of fun with A1-sized circuit diagrams drawn up and it's probably my first ever venture into real electronics and programming logic. Happy days.
 

Dippy

Moderator
Sinclair Scientific, I remember those.
A friend had one of those and also the Sinclair prgrammable version.
I think both took over 20 seconds to work out logs or tans or something like that.
And RPN, yes.
Wasn't here also a 'flashy' PC (Pocket Calculator) called the Sinclair Executive in a shiny metal case (or shiny platic?).
And the 'Black Watch' of course.

Talking of watched, I was given an Intex (Hughs Air Corp) LED watch in it's presentation box. Circa 1973 and £30? Still worked last year, but obv not on the original batteries :) Almost an antique.

I was also given a Bowmar calculator. Still works. Again circa 1973 and that cost nearly £40. Interferes with AM radio at close range.

20 years BC (Before China).
 

Tom2000

Senior Member
Black Watch???? Hmmm.... that sounds very familiar, but I can't pull up a mental image of it. A Sinclair product, right? Ol' Clive Sinclair sure had some neat ideas about features, functions, design, and some really slick packaging.

The HP-11C is fun, once in a while, to pull out of my briefcase when I visit clients' sites.

In one meeting, I pulled it out to figure something. One young programmer's eyes got really big, and he said "Hey! My dad had one of those!" Occasionally, it draws attention from some of the older guys who might have used one in college.

But most folks, if they notice it at all, probably sneer at it because it doesn't have enough buttons.

I suppose I could carry my TI-83, but I think that would be pretentious. :)

Tom
 

Tom2000

Senior Member
Absolutely brilliant. That could go straight to the completed project section (or for Australians - to the pool room). Very useful for those applications where a pot will wear out or you need full circle resolution. Now I can build that weather vane project!
Dr, I wasn't ignoring you. I just ran out of time yesterday morning.

I think a weather vane application would be really slick. I hadn't considered that. (I've considered a wheel's use for an antenna rotor, but didn't think of the obvious tower-mounted apparatus.)

Many thanks for the idea!

Tom
 

Tom2000

Senior Member
Ah, yes, now I remember it.

Thanks for the link to that nifty site. I'd forgotten about much of their equipment.

I owned a ZX-81 computer. I'd just had my first article published in an industry trade publication, and received an honorarium of $130. Coincidentally, the ZX-81 kit had just been released. $80 for the kit, $50 for a 16 k memory module. I couldn't resist.

It was an amazing computer. No, not as a computer, but how they were able to sell the kits for $80 and still make a profit. Sinclair really put a kink in the price/performance curve with that little machine.

I still remember the flakiness of that external memory module, though. The connector was horrible; any little jiggle and power to the memory module glitched, causing you to lose everything.

I tried all sorts of ways to keep that module attached to the case. I never totally solved the problem. About the time I was contemplating a hot glue gun, I started building my own wire-wrapped 6502 and 6802 machines, with the ZX-81 relegated to the closet shelf.

Ah, yes, that site brings back memories.

Thanks!

Tom
 
Top