![]() |
Forum Index : Microcontroller and PC projects : MKII using encoders
Author | Message | ||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Hello all. I have not yet received my 170s yet from mouser, so I can't try this yet. Can anyone verify if using the new pull up pin configuration combined with a 100nf cap as shown in the manual will work well with an encoder as opposed to using the 10k pullups shown in the manual also. Thank you!!! |
||||
atmega8![]() Guru ![]() Joined: 19/11/2013 Location: GermanyPosts: 724 |
Yes, i can ;-), why not? There is no difference between an internal or external resistor. Both follow Mr. OHM's Law. It's working. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I have tried 0.1uF with the internal pullups to give a rise time of ~3mS 0.01uF gave a rise time of ~300uS I am using 0.1uF for push buttons and 0.01uF on a rotary encoder. The rotary encoder is an ultra-cheap unit and with the capacitor, clockwise is very good and anticlockwise gives the occasional extra kick. In my application, that is not a problem. Jim VK7JH MMedit |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Thanks Jim, I will give the internals a try with the switch and encoder. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
I've found the secret to the cheap rotary encoders is to look at all the edges and then use software to decide what is valid. The only state which guarantees that a real transition has occurred is when both inputs are active. The software then needs to establish which went active first to determine direction. The attached code is a port of something I did on picaxe. It isn't perfect enough for absolute positioning (can edges be lost during things like "print" statements?), but is pretty good and even with the very cheap mechanical encoders does not require any hardware filtering. Hope it may be of some use. Peter option default integer const false=0 const true=1 const in0=3 'encoder pins pulled high so should be reading high in detent positions, centre pin connected to ground const in1=2 'swap the pin definitions as required to get the correct sense of rotation ' init: setpin in0,intB,rint 'enable interrupts on both edges of both pins setpin in1,intB,rint rotatedright=false rotatedleft=false resetenc=true value=0 lastvalue=0 print value ' MAIN: Do if value <> lastvalue then print value lastvalue=value endif Loop end ' rint: pin0=NOT pin(in0) 'reverse sense to get positive logic pin1=NOT pin(in1) if pin0 then if pin1 and not resetenc then 'in0 and in1 both active if rotatedleft and not rotatedright then value=value-1 rotatedleft=false endif if rotatedright and not rotatedleft then value=value+1 rotatedright=false endif else 'only in0 active if resetenc and not rotatedleft then rotatedright=true resetenc=false endif endif else if pin1 then 'only in1 active if resetenc and not rotatedright then rotatedleft=true resetenc=false endif else 'both off so reset rotatedleft=false rotatedright=false resetenc=true endif endif if pin(in0)=pin0 or pin(in1)=pin1 then goto rint 're-enter if another change has happened almost immediately ireturn |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Hi Matherp, welcome to the forum and thanks for the code. I will give this a whirl once I get a board back together with encoder on it. Looks interesting... |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Hi Matherp, this code works very very well with the el cheapo encoders. Thanks for the contribution!!! |
||||
drkl![]() Senior Member ![]() Joined: 18/10/2015 Location: HungaryPosts: 102 |
Dear Mathers, You do not have a rotary encoder management software cfunction code? It works perfectly, congratulations. Have two functions, one would return the value: Rencval(), and the other only in the direction +1: clockwise, -1: anti clockwise 0: no movement. drkl |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |