The MASM Forum

General => The Campus => Topic started by: nevraxSMD on March 13, 2014, 04:48:25 AM

Title: Encoder...
Post by: nevraxSMD on March 13, 2014, 04:48:25 AM
Hi i'm new around here, and also to microsoft assembly.
so.. can someone give me some pointers on how to read data from a motor encoder ?
thansk. :)
Title: Re: Encoder...
Post by: ragdog on March 13, 2014, 04:59:06 AM
Hello and wellcome

What for a  motor encoder?

any example or information?
Title: Re: Encoder...
Post by: nevraxSMD on March 13, 2014, 05:21:09 AM
this is the encoder http://www.pololu.com/product/2590
in the long run i have to implement algorithm which will enable the crontrol of the motor speed under load... but for now i wanna figure out how to read the data ill be working with...
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 06:58:30 AM
you need a little circuit to convert the phase-encoded data into direction+count signals

(http://blog.monomatic.net/files/2011/01/rotary_encoder_300px.jpg)

the 74LS14 is a Schmitt trigger inverter
they are used to convert the sine-like signals into square waves
the 74LS14 and 74LS74 are low-power TTL devices
probably ok, because the encoder runs on +5VDC
i might use B-series CMOS, because high speed is not required and they use less power
for the Schmitt trigger, you can use a CD4093B (MC14093B) or MC14584B
for the flip-flop, use a CD4013B (MC14013B)

if you use a 9V battery, you can use an LM78L05 3-terminal voltage regulator to get +5VDC

from there, you might want to use a wireless transmitter (serial mode) and a USB dongle
when you get that far, it's not hard to treat the port like a serial COMM device for communications
Title: Re: Encoder...
Post by: nevraxSMD on March 13, 2014, 07:19:37 AM
oO, well that clear;s a few things, i was wondering how get a proper signal.
umm and i have to use a paralel port, the hole thing has to be controlled with the help of a board - EVZ3
thank you  :biggrin:
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 07:25:20 AM
well - if you have to use a parallel port, you have to
i thought you might be making a remote robot or something   :P
it would really sux to have an LPT cable following it all over the place - lol

i have no experience programming for the parallel port,
but it may be very similar to a serial port
Title: Re: Encoder...
Post by: nevraxSMD on March 13, 2014, 07:41:03 AM
nope, nothing too fancy, but still as i start thinking what i need to do to make it work, and how troublesome is gonna be to program ... meh is gonna a be a challenge....
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 08:13:19 AM
74LS TTL might be a better match for a parallel port
i can't recall ever using CMOS with a parallel port - i'd have to re-visit the spec-sheets

where do you plan on getting power ?

would have been easier in the old days
the ideal situation might have been to generate interrupts for each clock pulse
can't do that so easily under NT windows

soooooo.....
you might want to add a counter to get speed in a parallel fashion
Title: Re: Encoder...
Post by: nevraxSMD on March 13, 2014, 08:20:17 AM
exactly how is the 74LS14 connected to 74LS74, cuz the datasheed shows a different pin out :D

umm a 5v, 1A phone charger, worked great on powering some 5v boards that i used :D think it should do the job
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 08:24:21 AM
you're right about the pin-out   :t

one input goes to Clk (Clock), the other goes to D (Data)
the Q output gives you direction ("Q not" gives you the opposite logic level)

a 74LS74 has 2 flip-flops per package
you can use either one - unused D/Clk lines should be grounded
Set and Clr lines may be left open (in TTL, that is interpreted as a 1)

(http://robocave.pk/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/7/4/74ls74_dual_d_flip-flop_.png)
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 08:27:46 AM
what is the maximum RPM of the motor ?

are you going to use the 12-counts-per-rev wheel or the 20-counts-per-rev wheel ?
Title: Re: Encoder...
Post by: nevraxSMD on March 13, 2014, 08:35:18 AM
1000rpm or 625rpm , i'll place the order when i know al the parts that i require.
umm and i dono.  i'm not sure whit what type of wheel the kit comes.(i'm buying from a local suplier..)
but i think i'll go with 20 counts, is it safe to assume that is gonna give a better read?
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 08:38:45 AM
the data sheet says it comes with both wheels (3 tooth, 5 tooth)
you select what you need based on desired resolution

if you used a 1000 RPM motor and a 5 tooth wheel, you'd get a maximum frequency of 20 KHz
well within the rate of CMOS devices

however, TTL devices have a little better drive capability (more compatible with a parallel port)
CMOS and LS TTL circuits can be mixed rather nicely, too   :biggrin:
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 08:44:59 AM
i think i'd use two 8-bit binary counters, with a 1 second gate
when you read the low-order counter, the data from the high-order counter would be stored with an 8-bit latch
that way, the value read in the high-order byte coincides with the low-order byte
then, write the code so you always read the low-order byte first
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 09:55:32 AM
after a little more thought.....

using a 0.5 second gate might be a little better
you'd get RPM, to 0.1 RPM resolution, updated 2 times per second
Title: Re: Encoder...
Post by: anunitu on March 13, 2014, 11:01:10 AM
Blink blink blink....damn Dave you are the hardware MAN!!
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 12:06:44 PM
that's what i do   :biggrin:

asm code is for fun, mostly
Title: Re: Encoder...
Post by: Farabi on March 13, 2014, 04:03:22 PM
Hi, you will ned to use "IN" and "Out" instruction but you will need another dll to do that which I forget the name is. Basically the dll had a function with parameter, nPortNumber as dword and data you want to send as dword, but the data it really sent is a byte data. On my OS toys, I can use "IN" and "OUT" instruction freely since my OS is the kernel, but for windows you will need a 3rd party library to do that. I think that dll is freely available somewhere, its been years since last time I used it.
Title: Re: Encoder...
Post by: dedndave on March 13, 2014, 06:30:29 PM
i was thinking he might be able to open the port with CreateFile, like you do with a serial port
maybe not   :P

i made a miscalculation, earlier
1000 RPM is 60000 RPS

using the 3-tooth wheel will get you a maximum frequency of 720 KHz
using the 5-tooth wheel will get you a maximum frequency of 1.2 MHz
1.2 MHz may be a little tough for B-series CMOS running at 5 VDC - i'll have to check the specs

in any event, you don't have to count all those bits
decide what resolution you want - and select a gate rate that will accommodate it
if 1000.0 RPM is enough resolution, that will still fit into a word,
but you'll have to use one of the control lines to read direction


Title: Re: Encoder...
Post by: TWell on March 13, 2014, 09:57:46 PM
How well IEEE-1284 parallel port works (USB to IEEE-1284)?
I have one with PL2305 IC chip info here (http://www.prolific.com.tw/us/ShowProduct.aspx?p_id=6&pcid=41)
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 01:45:42 AM
i guess it works well
most modern PC's have EPP/ECP ports
on my machine, it is configured in BIOS setup

i don't think the original centronix interface has been used much since PS/2 (windows 3.1)
i have used the parallel port as bi-directional since days of windows 95
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 02:03:36 AM
i found a DLL, which will work ok under XP
not so sure how it will go for vista, win-7, 64-bit OS's
i also saw mention of one named "giveio"

http://blogs.msdn.com/b/ericgu/archive/2006/11/02/reading-switches-from-the-parallel-port.aspx (http://blogs.msdn.com/b/ericgu/archive/2006/11/02/reading-switches-from-the-parallel-port.aspx)
http://logix4u.net/parallel-port/16-inpout32dll-for-windows-982000ntxp (http://logix4u.net/parallel-port/16-inpout32dll-for-windows-982000ntxp)
http://www.codeproject.com/Articles/20545/I-O-Ports-Programming-Parallel-port-Reading-Writin (http://www.codeproject.com/Articles/20545/I-O-Ports-Programming-Parallel-port-Reading-Writin)
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 02:05:23 AM
i can help with the counter design, but i need to know more about what you want to do
if you want RPM, totalizer, resolution, etc
need details to do much   :P
Title: Re: Encoder...
Post by: TWell on March 14, 2014, 02:51:17 AM
And WinIO from here (http://www.internals.com) for direct access.

I'm interest USB to IEEE-1284 only, as there's no LPT's in laptops.
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 03:17:05 AM
oh - i like that driver - thanks, Timppa   :t

ieee-1284 is a parallel port...

http://en.wikipedia.org/wiki/IEEE_1284 (http://en.wikipedia.org/wiki/IEEE_1284)

my understanding is that you can emulate a parallel interface over USB,
but it's not a completely compatible emulation

actually - it would probably be better to design around a USB interface, to start with
i have written some code that uses a serial-mode USB port
it's reasonably simple and works on all newer OS's without special drivers
that also gives you the wireless option
Title: Re: Encoder...
Post by: TWell on March 14, 2014, 03:44:34 AM
I like to use usbprint.sys, as here (http://msdn.microsoft.com/en-us/library/windows/hardware/ff561757(v=vs.85).aspx) without any external driver.
Just using USB001 port/handle.

Maybe it's time to open own thread for this topic ?
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 04:09:42 AM
here is a very nice description of the hardware interface for SPP, EPP, and ECP modes

http://www.ni.com/white-paper/3466/en/ (http://www.ni.com/white-paper/3466/en/)

near the top of the page, availabe as a PDF
Title: Re: Encoder...
Post by: nevraxSMD on March 14, 2014, 05:15:03 AM
i like the counter idea, unfortunatly i had class all day and didn't have the time to do any research on how it works.
the thing is i have to get a prety accuarate read of the rpm's and get it at a decent rate.
but i'm still cluless on how i can read the data in an actual asm program.
i need the rpm value to use it in a PID controller, so i can maintain the motor speed constant.

Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 05:36:56 AM
i am happy to help
but, i need some numbers to work with - lol
Quotepretty accurate read of the rpm's and get it at a decent rate
doesn't give me much to go on   :P
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 05:39:21 AM
of course, you realize - it could be done in closed-loop - no computer at all   :P
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 05:41:52 AM
if you are trying to maintain a constant speed...
you might be surprised how constant it will remain on it's own, unless the load changes

it would help if i knew more about the project - a basic description of what you're trying to control
Title: Re: Encoder...
Post by: nevraxSMD on March 14, 2014, 05:53:00 AM
i know the speed remains constant if there's no load.....
thats the hole point under different loads the motor has to stay at a specified speed.
the basic description is this:
use : http://medilab.com/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=594&virtuemart_category_id=50&Itemid=130
to maintain a constant speed for a dc motor under load :D
srry for the lack of details i just got the project and i have a week to come with a detailed plan on how to implement it
and i'm trying to figure out how to make it work as i go...
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 05:57:20 AM
feedback control systems are used in many ways
voltage regulators, phase-locked loops, etc
even oscillators are an example of a feedback system

if the gain of the loop is greater than one at any frequency where the feedback is not 90 to 270 degrees, the loop will oscillate

by introducing delays into the loop (such as computer processing), you must add additional filtering to prevent oscillation
that means a slower response time

in the drawing below, the loop filter is typically placed in the "Feedback Element" block

(http://www.pidtuning.net/img/pidloop.jpg)

http://www.pidtuning.net/pid-loop.php (http://www.pidtuning.net/pid-loop.php)
Title: Re: Encoder...
Post by: dedndave on March 14, 2014, 06:00:00 AM
if you are not running under windows 2000, XP, Vista, 7, 8 things are a lot simpler
you can talk directly to the parallel port with IN and OUT instructions   :t
Title: Re: Encoder...
Post by: nevraxSMD on March 14, 2014, 06:16:28 AM
i have a basic understanding of how the loop works,
but i never had to physically implement one
this weekend i'll try to make the PID controller
specs: i'll be using dc motor that runs at 1000rpms -6V-120mA free run and 1.6 A stall.
please let me know what other info you need :D
Title: Re: Encoder...
Post by: TWell on March 14, 2014, 06:32:56 AM
Quote from: dedndave on March 14, 2014, 06:00:00 AM
if you are not running under windows 2000, XP, Vista, 7, 8 things are a lot simpler
you can talk directly to the parallel port with IN and OUT instructions   :t
Quote// Under Windows NT/2000/XP, after calling InitializeWinIo,
      // you can call _inp/_outp instead of using GetPortVal/SetPortVal
Is this still valid ?
Title: Re: Encoder...
Post by: dedndave on March 15, 2014, 12:28:25 AM
wellllll.....

if you have a DLL, you can do it
if you have a driver, it's a bit tricky

under win2000 and xp, you can install drivers freely
under vista or newer, drivers have to be signed (google WHQL)
there are ways to boot up with unsigned drivers, but it's a little inconvenient

even so, i don't think you can use IN and OUT instructions, directly
you call a function, and it accesses the kernel-mode driver that does the work

it appears he's developing on a non-windows platform, so he should be able to use IN/OUT