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 support@ccsinfo.com

reading rotary encoder without interrupts(?)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
zamzam23



Joined: 25 Aug 2010
Posts: 47

View user's profile Send private message

reading rotary encoder without interrupts(?)
PostPosted: Wed Feb 11, 2015 6:37 am     Reply with quote

I want to read my rotary encoder without interrupts. how can I do this? can you share some codes or links about this?
Thanks.
temtronic



Joined: 01 Jul 2010
Posts: 9136
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 11, 2015 6:58 am     Reply with quote

pretty sure CCS supplies an example( ex_encoder.c ??) in their generous examples folder....
..also use the 'search' feature for this forum as others will have posted their hard work in the code library.
Encoder code is easy(simple logic) though if you want/need 1024 CPR at high speed, it may be better to use a chip for that purpose( US Digital make them).


Depending on the type (mechanical, electronic) the interface/wiring can be fun or easy.

Jay
zamzam23



Joined: 25 Aug 2010
Posts: 47

View user's profile Send private message

PostPosted: Wed Feb 11, 2015 7:02 am     Reply with quote

I have searched of course. but all codes are with interrupts
temtronic



Joined: 01 Jul 2010
Posts: 9136
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 11, 2015 8:35 am     Reply with quote

Actually the CCS supplied example( ex_encod.c) does NOT use interrupts !!!

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19267

View user's profile Send private message

PostPosted: Wed Feb 11, 2015 8:47 am     Reply with quote

ex_encod.c, does not use interrupts. It reads the encoder by polling. Exactly what you are asking for.

Microchip have an application note, where you build a fairly simple external circuit to decode the encoder patterns, which then just generates a +ve, and -ve movement pulse, which can be fed to two CCP channels. The CCP's can just be read at and time to give the movements that have occurred. Better if the code cannot poll the encoder all the time.

Alternatively, several of the PIC24's/33's have a built in hardware QEI interface which handles it all for you. Gives a direct readout of a 32bit counter, reflecting the current position.

I have to ask 'why not just use interrupts'?.

I see jay posted the same comment about ex_encod.c, while I was typing....
zamzam23



Joined: 25 Aug 2010
Posts: 47

View user's profile Send private message

PostPosted: Wed Feb 11, 2015 8:51 am     Reply with quote

because my B port is used for glcd data pins. I cannot use external interrupst and B4-B7 change interrupts.

any way using interrupts for reading encoder?
Ttelmah



Joined: 11 Mar 2010
Posts: 19267

View user's profile Send private message

PostPosted: Wed Feb 11, 2015 9:03 am     Reply with quote

Because they are exactly the type of thing that is much easier with interrupts.

Remember that they could have almost any rate. From a pulse every minute, up to thousands of changes per second (multi line encoder on a shaft turning at some RPM). To sample them in software, you have to ensure you never miss a change, so must sample at least once in any possible timing of the fastest changes that can happen. This is why ex_encod, does nothing else except sit polling the bits. With the interrupt, the code to detect the changes is called when the signals do change. Perfect.

Simplest solution for you would be to use the external decoder mentioned. The complexity depends on how many of the edges you actually need to decode.

Have a look at:
<http://www.mindspring.com/~tom2000/Delphi/Codewheel.html#Decoding%20Quadrature%20Signals>

The first circuit on this page, can be used to give two outputs. Feed one to one timer input, and the other to another. The timers then count pulses for up/down for you. Provided you have a chip that has two timers with external inputs available, this solves the problem.
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Thu Feb 12, 2015 3:14 pm     Reply with quote

WHAT is the part number for your encoder and who is the manufacturer??
diode_blade



Joined: 18 Aug 2014
Posts: 53
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Sun Feb 15, 2015 2:18 am     Reply with quote

Why not use an 18f pic with built in quadrsture encoder hardware, i have used these before such as 18f4431 to control a direct digital synthisizer vfo, the hardware does all the work and the softwate justs converts the incoming encoder signal to whatever you want,
necati



Joined: 12 Sep 2003
Posts: 37
Location: istanbul

View user's profile Send private message

PIC Encoder
PostPosted: Sun Feb 15, 2015 3:23 am     Reply with quote

https://sites.google.com/site/proyectosroboticos/encoder/encoder-por-software/encoder-simple-con-16f628a

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



Joined: 11 Mar 2010
Posts: 19267

View user's profile Send private message

PostPosted: Sun Feb 15, 2015 3:30 am     Reply with quote

This is the same as ex_encod.c, and the same comment about the rate at which you have to poll applies.

This is the key thing, which is part of the question Asmboy asked about the nature of the encoder. Add to this the maximum RPM that may be involved. If (for instance), the encoder is only something like 16 lines, and spun by fingers on a large knob, so rotation above perhaps a few RPM is unlikely, then it can be soft polled, possibly even from a 'tick' interrupt. However if the potential rates go high, then the polling rate become prohibitive if the code is having to do other things....
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Sun Feb 15, 2015 5:57 pm     Reply with quote

dear zamzam,

Forum members here are really trying to help you,
but perhaps you can divine from reading the replies,
there is a consensus that you do not tell enough about your problem to
get the help you seek. You are here in the first place because
you basically don't understand what to do ......

so my suggestion:

when you are requested to provide more information,
especially if the replying member has thousands of previous posts,
that the best thing you can do in your own self interest,
is to consider answering follow up questions.
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

encoders...
PostPosted: Tue Feb 17, 2015 9:27 am     Reply with quote

Just as a point of info for those reading this post, we have used a very nice chip here at work for years on various projects which have half a dozen shaft encoders used with knobs for data input on many of the products I have designed. this is the US Digital LFL7084 chip. It puts out a clock and up/down digital lines from a standard A/B encoder input and makes it a piece of cake to write the code without interupts for multiple encoder inputs on one chip. I have five shaft encoders using these going into one PIC16F876a chip one one recent project.

Chris
temtronic



Joined: 01 Jul 2010
Posts: 9136
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 17, 2015 10:48 am     Reply with quote

Yup, Chris is right, USD make nice products. Used their shaft encoders(1024) + 7166 interfaces more than a decade ago,tied to 16F877s.
Made for real nice robotic 'plants' using CCS PCM V2.5xx, then v3.xxx
The shaft encoders were a dream to use,much better design than the HP units.

ah, the good old days....

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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