PDA

View Full Version : Reading incremental encoder interupt



RFsolution
- 13th July 2009, 22:43
Hi

I would like to make a small project to read an incremental encoder
with differencial A/B outputs and send its position on request via RS232

I need to count the pulses, determinate if it is going CW or CCW
on a serial request I need to send the number of counted pulses via RS232

Which way shall I go:

Use I/O ports for the A & B pulses and use a Hardware UART to handle the incoming request of the encoder (the request command is only 2 bytes)

Or count the pulses of the encoder with an interupt based routine ?

Any idea's are welcome

aratti
- 13th July 2009, 23:18
I need to count the pulses, determinate if it is going CW or CCW

I would use the one HCTL2000 quadrature decoder/counter interface.

See details on datasheet @ www.datasheetcatalog.org/datasheet/hp/HCTL-2000.pdf

Al.

HenrikOlsson
- 14th July 2009, 06:12
What type of frequency are we talking about here? If it's rather low frequency, like a knob used to navigate a user interface etc then perhaps using the 'Change-on-PortB' interrupt and decode and keep count in software. If we're talking higher frequencies, like for motorcontrol etc then you might want to look at the 18F24x1 series PICs as they have a QEI-module on board. In any case - use the USART for comms.

Archangel
- 14th July 2009, 06:49
Here is a couple of links . . .
http://www.picbasic.co.uk/forum/showthread.php?t=1552
http://www.picbasic.co.uk/forum/showthread.php?t=5754
http://www.picbasic.co.uk/forum/showthread.php?t=9700
http://www.picbasic.co.uk/forum/showthread.php?t=6708

RFsolution
- 14th July 2009, 09:42
Thank you

maximum frequency will be around 1000 Pulses/sec


What type of frequency are we talking about here? If it's rather low frequency, like a knob used to navigate a user interface etc then perhaps using the 'Change-on-PortB' interrupt and decode and keep count in software. If we're talking higher frequencies, like for motorcontrol etc then you might want to look at the 18F24x1 series PICs as they have a QEI-module on board. In any case - use the USART for comms.

RFsolution
- 14th July 2009, 19:17
I found some devices who can handle differential A/B quadrature encoders
and give a Direction out and CLK out LS7184
http://www.opticalencoders.com/assets/general/114_lfls7184_datasheet_1.pdf


I think this device can make the job easier

If I use this device and the USART on RB1/RB2 of an 16F628 i think I can
use a normal I/O pin to count the clk from the LS7184
Or should it be better to use RB0/INT as an interupt from the CLK signal
from the LS7184 pulse counter ?

iw2fvo
- 14th July 2009, 21:32
Hi ,
i wrote a picbasic program to read an optical incremental encoder : it used in my DDS frequency generator ( not finished at the moment ) But the encoder piece of program works very well .
Please note that I am not a software engineer and so the program is not optimized at all.
Comments are in italian but it is easy to find out the encoder piece that you need.
Pls: let me know ...
Ambrogio
IW2FVO
North Italy




Hi

I would like to make a small project to read an incremental encoder
with differencial A/B outputs and send its position on request via RS232

I need to count the pulses, determinate if it is going CW or CCW
on a serial request I need to send the number of counted pulses via RS232

Which way shall I go:

Use I/O ports for the A & B pulses and use a Hardware UART to handle the incoming request of the encoder (the request command is only 2 bytes)

Or count the pulses of the encoder with an interupt based routine ?

Any idea's are welcome

rakickv
- 24th February 2017, 19:16
Hi I have a problem with interrupts code in pbp.I want to count encoder ticks in both directions,I have done the code without interrupt routine and it works fine but it is to slow for greater speeds.So I tryed with INT on port B.0 but it is not working.I am useing PIC 16F877A, compiler 2.5. Here is the code which is not working.Where was I wrong?
8380

iw2fvo
- 1st March 2017, 12:50
I used the interrupt for my low cost mechanical encoder to control my power supply.
You can find the whole code in the attachement.
The interrupt service routin is the following:
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
if EB=0 then INC_DEC=2
IF EB=1 THEN INC_DEC=1
@ INT_RETURN

Thanks to Darrel Taylor work.

Bye
Ambrogio
Iw2fvo