PDA

View Full Version : Using a optical coder



debutpic
- 26th December 2005, 16:04
Hello all

In my new project I will use a optical coder for to know the position of tool (lathe)
Optical coder is a 300 pulses/turn
A full rotation of my lathe is equal 5 millimetres
A pulse >>> 1,6/100 millimeters


First problem
I dont' know how to write this piece of code currently I calculate only the integer,a starting point please?

Darrel Taylor
- 27th December 2005, 11:22
Hi debutpic,

Here's one way to do it.

Pulse_Rev CON 300 ' Pulses per Rev
Dist_Rev CON 500 ' Distance per Rev in mm*100
Position VAR WORD

Position = Compteur * Dist_Rev
Position = DIV32 Pulse_Rev

And, Ingvar will be along shortly to show you how to do it with "*/" :)
<br>

debutpic
- 27th December 2005, 12:56
he he It work fine Darrel !!

perhaps a another question,the optical coder has only one output TTL.
I count the pulses with the pin RB0/INT but how to know if it turns in a direction or the other?

Darrel Taylor
- 27th December 2005, 20:34
Unless you have some other way of knowing which way it's going, I don't think you can.

If it needs to keep track of absolute position in both directions, you'll probably need a "Quadrature Encoder".
<br>

Ingvar
- 28th December 2005, 08:34
I try hard not to ...... :D

debutpic
- 28th December 2005, 09:33
Hello all

1) Which is the method of programming used for to know the directions of rotation with these optical coders?

2)the next opticals coders agree?

thank's

dmairspotter
- 28th December 2005, 15:48
2) I don't think the encoders in the picture are direction sensing (Quadrature). You need an encoder with two output signals, out of phase with each other.

1) With a quadrature signal (phase a and phase b, offset by 90 degrees) you can tell direction by watching which phase goes high first. Count pulse for distance, just like you are doing now. Google quadrature encoder ...all kinds of info available

You can get "absolute" encoders, which give a unique bit pattern for each position of rotation. I think there are some encoders which give a step and direction signal also, but I might be thinking of stepper drivers!

debutpic
- 28th December 2005, 16:56
Ok but which is the fonction of green wire called "index"?

dmairspotter
- 28th December 2005, 17:27
Index usually gives a pulse at one particular point in each turn of the encoder, like a "home" signal.

locko
- 29th December 2005, 04:00
I do not know much about lathes but how about a microswitch on the direction lever (if it has one), or current sense a wire/wires going to the motor.

Luciano
- 29th December 2005, 09:13
Your single channel encoders are unidirectional or "tachometer" encoders.
(They are used to provide speed information).

Best regards,

Luciano

debutpic
- 30th December 2005, 11:31
and this model should be appropriate ????????

Luciano
- 30th December 2005, 12:11
Yes, this is the right one.

See this thread:

Decoding quadrature encoders
http://www.picbasic.co.uk/forum/showthread.php?t=1552

Luciano

debutpic
- 30th December 2005, 15:11
thank you Luciano
I will read all the thread and if I dont' understand all
I would ask you of another questions

debutpic
- 10th January 2006, 20:20
Hello Picusers

Now I use an optical coder with 1000 pulses per turn,but the final result is not good,the PIC does not count all the pulses (~ -200 pulses)
For you it's a problem of time with the routine of the LCD?




DEFINE OSC 20 'Fréquence du quartz utilisé
ADCON1=7 'PortA et PortE en numérique

'-----------------------------------------------------------------

'Configuration LCD

DEFINE LCD_DREG PORTB ' LCD o/p on port B
DEFINE LCD_DBIT 4 ' LCD on lower 4 bits of port B
DEFINE LCD_RSREG PORTB ' LCD reset on port B
DEFINE LCD_RSBIT 3 ' LCD reset portB.3
DEFINE LCD_EREG PORTB ' LCD enable on port B
DEFINE LCD_EBIT 2 ' LCD output on PortB.2
DEFINE LCD_BITS 4 ' LCD o/p is 4 bit data
DEFINE LCD_LINES 2 ' Number of lines on LCD = 2
DEFINE LCD_COMMANDUS 1500
'-------------------------------------------------------------------

'Configuration des registres

TRISB = %00000011 ' Port B en sortie sauf B1 et B0
OPTION_REG = %01000000 ' Config registre
INTCON = %10010000 ' Config registre

'----------------------------------------------------------------------

'Déclarations des variables

Pulse_Rev VAR WORD ' Pulses par Rev
Pulse_Rev = 0

'-----------------------------------------------------------------------------



On Interrupt Goto ISR ' Si appui sur le BP saut en "ISR"

Main:

Lcdout$fe,1
Lcdout #Pulse_Rev," pulses" 'Affiche valeur variable incrément
pause 1
goto Main
Disable 'interdit toute interruption

'-------------------------------------------------------------------------------

'Routine d'interruption + comptage

ISR:


Pulse_Rev = Pulse_Rev +1 'Incrémente de 1 la valeur de la variable
INTCON.1 = 0 'Remet le flag d'interruptio à 0
Resume 'fin de l'interruption
Enable 'Autorise à nouveau une interruption



End

Ioannis
- 10th January 2006, 20:51
How fast is the encoder turning?

Even in assembler there is a limit in the speed a PIC can respond.

As a suggestion, try to put the LCD commands inside your ISR handler. If they are executed within the main, lot of time is wasted with no reason. If you don't move the encoder, LCD will still be accessed.

Ioannis

debutpic
- 11th January 2006, 05:26
Ioannis

Speed max 6 turn sec --> 6 KHz

Ioannis
- 11th January 2006, 08:47
Hmm, I think it is very fast for the PIC to respond and also display to LCD. I guess that you might try use second PIC to display and get the data through a fast connection either parallel (PIC to PIC with 8 bit ports) or serial the fastest possible. This way the main PIC will have all the time to read the encoder and send the data to the second PIC or terminal device.

Also the first PIC should run as fast as you can, 20MHz xtal, or in assembly. I don't have the time to do the math right now to calculate how fast it has to run.

Ioannis

nedtron
- 11th January 2006, 14:36
Greetings,

Scott Shumate of Shumatech http://www.shumatech.com has designed a 3 axis Digital ReadOut for lathes and mills based on a single PIC microcontroller.

Full documentation is available on his web site and he sells bare circuit boards at very reasonable prices.

The Shumatech DRO has advanced features such as bolt hole patterns, tool offsets and RPM.

The Shumatech DRO will work with Chinese linear scales and / or rotary encoders simultaneously.

I bought the circuit board from Shumatech and built my 3 axis DRO for about $125 in parts which is a tremendous savings when comparable DROs cost $1,200+.

My Shumatech DRO:

http://users.rcn.com/seiths/projects/electronics/pages/RPM_DRO.html

http://users.rcn.com/seiths/projects/electronics/pages/RPM_DRO.html

I had started designing a PIC based DRO for my milling machine when I discovered the Shumatech DRO.

I abandoned the design, as it didn't make sense for me to attempt to reinvent a DRO when an excellent advanced featured DRO was available for the cost of a circuit board and parts.

Ned

debutpic
- 6th February 2006, 19:13
Hello everyone

Currently I have one quadrature optical coder and my code works fine (increase and reduction according to the sense of rotation)

I have two questions

1) I want to increase the resolution (x4) of the optical codeur while decoding the fronts high and low of two channels A and B (see the picture in blue)

2) When I start the code if I decrease immediately the value displayed is 65535 65534.9 65534.8 etc....
but I will want -0.1 -0.2 -0.3 etc

Do you have an idea to begin?

RodSTAR
- 12th October 2007, 21:35
Hello all

1) Which is the method of programming used for to know the directions of rotation with these optical coders?

2)the next opticals coders agree?

thank's

The encoder in the photo is not a quadrature encoder. quadrature encoders have two channels (usually called A and B) and sometimes also an index as full revolution reference, and as you see (read) in the photo, it has only the full revolution reference (index) and 1 channel (channel A). you can get nice and cheap motors with quadrature encoders in the surplus market.

GrandPa
- 13th October 2007, 15:35
You may want to have a look at US Digital website (http://www.usdigital.com/), to find appropriate encoders.

I would also suggest you to use PIC18FXX31 family. They have built-in quadrature encoder interface module with distance, direction and speed. Much easier to deal with and with extra features like noise protection too. I'm personally using PIC18F4331 and it work great with stepper + quad. encoder.

Hope this can help!

J-P

Huh? Last question was 8 months ago ? (Ooooooops)

RodSTAR
- 16th October 2007, 04:57
Hello all

1) Which is the method of programming used for to know the directions of rotation with these optical coders?

2)the next opticals coders agree?

thank's

That one in the photo won't let you get rotation direction, has only one channel and that doesn't output quadrature code.