CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Rotary Encoder
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Nov 18, 2016 8:03 pm     Reply with quote

first comment.

if using set_tris --then declare
#use fixed IO before hand

also - using an LCD display with safety delay or
even actual hardware busy/handshake - can take
LOTs of milliseconds to execute.

you can't loop back for another look at the encoder state
at any kind of speed because your LCD display line imbedded in
the function. LCD update can be so slow as to be able to let let additional encoder states pass un-noticed.

//
if i was doing this - i'd get the encoder bits read on
a pic with portb_change interrupts.

then just call the lcd print routine from main as a separated
function to refresh the screen.
Ttelmah



Joined: 11 Mar 2010
Posts: 19589

View user's profile Send private message

PostPosted: Sat Nov 19, 2016 2:47 am     Reply with quote

He should use fast_io, not fixed_io.....

#use fast_io(D)

needs to be added.

However a huge amount depends on the actual speed of the encoder. 'Speed' here is the pulse rate per second. A 1000 line decoder, gives four changes per 'line', and if spun at even 100rpm will give:
(4000*100)/60 changes per second that have to be sampled. The loop needs to execute faster than this. 6666*per second. as asmboy says, for anything but a very slow encoder, the LCD is the big problem. Now the LCD code might well work for a really slow movement, with only a few lines on the encoder (a few RPM, on a 16 line encoder for example), but for anything faster or with higher resolution, the code won't work...

Solutions:
1) As Asmboy says, use a port with interrupt on change.
2) Add the logic, so the encoder can feed the internal CCP channels of the PIC (only requires a couple of logic gates - details on the Microchip site).
3) Decode externally (A chip like the LFLS7366R also adds signal filtering).
necati



Joined: 12 Sep 2003
Posts: 37
Location: istanbul

View user's profile Send private message

PostPosted: Sat Nov 19, 2016 10:48 am     Reply with quote

https://sites.google.com/site/proyectosroboticos/encoder/encoder-por-software
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sat Nov 19, 2016 12:16 pm     Reply with quote

I should add that your encoder table is more complex than needs be -
due to the code method of your encoder and number of bits. ( standard incremental binary)

I greatly prefer 2-bit Gray " reflected binary code" devices.

The optically coupled types have no "bad states" or glitching
at any frequency i have ever used.

For simple +/- count applications they are beyond question
the superior solution.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group