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

connecting a rotary encoder with a PIC 16F1847

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



Joined: 19 Mar 2025
Posts: 1

View user's profile Send private message

connecting a rotary encoder with a PIC 16F1847
PostPosted: Wed Mar 19, 2025 5:26 am     Reply with quote

I am a student and i need to interface a rotary encoder with a pic 16f1847 but i have no idea how to. I have found a arduino version but i am unsure if i can just copy and paste the arduino code as the ccs c code.

https://arduinogetstarted.com/tutorials/arduino-rotary-encoder#google_vignette

Any help will be truly appreciated.
_________________
M A Hemani
temtronic



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

View user's profile Send private message

PostPosted: Wed Mar 19, 2025 5:52 am     Reply with quote

1st ..NO, you can't 'cut and paste'. That's like cutting a recipe written in French and pasting it into an English book and thinking the chef can make it !

Now you could 'translate' the Ardunio code into CCS code BUT it's probably easier for you to just use the encoder example that CCS supplies, in the 'examples' subfolder.

You can also search the 'code library' on this website and of course, use Google !

BTW ,1st program you need to cur/compile /run is a '1Hz LED' program. yes a sill 'blink and LED' program but it will confirm you CAN create code and the PIC will RUN.

If you do decide to translate, someone posted a "BUTTON" function in the lode library I KNOW it works, having used it several times over the years.Kinda wonder if CCS will create and include a version of it in the future ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19765

View user's profile Send private message

PostPosted: Wed Mar 19, 2025 7:18 am     Reply with quote

A huge amount depends on other factors:

1) How many lines has the encoder?.
2) What rotational speed could it reach?.
3) Do you want single step, two step, or quadrature decoding?.
4) What is the nature of the encoder (mechanical or onto)?.
5) What else does the chip have to do?.

If you can handle all other things using polling rather than interrupts, then
a very fast quadrature decoder is in this thread:
[url]
https://www.ccsinfo.com/forum/viewtopic.php?t=44491&postdays=0&postorder=asc&highlight=quad&start=15
[/url]
This I used on a 4000 line decoder at over 30000 steps per second.
This is using the interrupt on change on port B. to detect the encoder change.
There is also a slower, but possibly more useful routine also linked to
from this thread. Depending on how many edges per second need to
be handled, this may be better.
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