View previous topic :: View next topic |
Author |
Message |
m4hemz
Joined: 19 Mar 2025 Posts: 1
|
connecting a rotary encoder with a PIC 16F1847 |
Posted: Wed Mar 19, 2025 5:26 am |
|
|
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
|
|
Posted: Wed Mar 19, 2025 5:52 am |
|
|
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
|
|
Posted: Wed Mar 19, 2025 7:18 am |
|
|
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. |
|
 |
|