<?xml version="1.0" encoding="utf-8" ?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
				<channel rdf:about="http://www.8051projects.net/">
				<title>8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes : Forum / topic</title>
				<link>http://www.8051projects.net/</link>
				<description>Learn to make simple microcontroller projects, pic, 8051, avr and arm projects. download 8051 projects, tutorials, libraries, sample codes. join the microcontroller discussion forum and ask doubts regarding electronics. the best source for 8051 over internet.</description>
				<dc:language>en-gb</dc:language>
				<dc:date>2009-01-07T18:15:13-08:00</dc:date>
				<dc:creator>contact@nospam.com</dc:creator>
				<admin:generatorAgent rdf:resource="http://e107.org" />
				<admin:errorReportsTo rdf:resource="mailto:contact@nospam.com" />
				<sy:updatePeriod>hourly</sy:updatePeriod>
				<sy:updateFrequency>1</sy:updateFrequency>
				<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
				<items>
				<rdf:Seq>
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10071.html" />
				</rdf:Seq>
				</items>
				</channel>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator></dc:creator>
						<dc:subject></dc:subject>
						<description>Hi,I have problem writing a code for the shaft encoder to decode for my PIC to read the direction.Can some one please give me a sample code of the shaft encoder decodes the direction?thanks.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>like you have done in C already, here also you need to make a look up table for encoder to detect the change in direction.or... what you can do is.. create three states (CLOCK, ANTICLOCK, NOCHANGE)like this:CODE:CLOCK equ 1H<br />ANTICLOCK equ 2H<br />NOCHANGE equ 3H<br />&nbsp;if encoder can be connected to interrupt pins of controller or periodic polling on any two pins, then whenever you sense a change in encoder o/p you can switch between states according to current state of encoder bits.hence in your main loop when a state changes you can do work according to that state.I hope you have got my idea?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>Ajay, i know you already told me about this...but i try to work it out on ASM code...it doesnot work..can u give me a sample code of how to decode the shaft encoder direction?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>GPIO 4 is the channel A of the shaft encoderGPIO 5 is the channel B of the shaft encoderbelow is part of the program code for the encoder to decode the 4 binary bit to determine the direction.shaft encoder used Bourns ECW- Digital Contacting EncoderCODE:<br />START<br />&nbsp; &nbsp; &nbsp; &nbsp; btfsc&nbsp; &nbsp;GPIO,4; &nbsp; &nbsp;waiting for the encoder changes<br />&nbsp; &nbsp; &nbsp; &nbsp; goto START; keep check for the changes<br />&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; SHAFT_0; changes detected<br />SHAFT_0:<br />&nbsp; &nbsp; &nbsp; &nbsp; CLRF&nbsp; &nbsp; A11&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ; clear memory A11<br />&nbsp; &nbsp; &nbsp; &nbsp; CLRF&nbsp; &nbsp; A21&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ; clear memory A21<br />&nbsp; &nbsp; &nbsp; &nbsp; BCF&nbsp; &nbsp; &nbsp;STATUS,C; clear carry flag incase there is carry<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC&nbsp; &nbsp;GPIO,4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; check on the changes, 0 or 1<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_A11&nbsp; &nbsp; &nbsp;; if 1 go savebitA11<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_A10&nbsp; &nbsp; &nbsp;;if 0 go savebit A10<br />SHAFT_1<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC&nbsp; &nbsp;GPIO,5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; check on gpio 5 changes, channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_B11&nbsp; &nbsp; &nbsp;;if 1 go savebit B11<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_B10&nbsp; &nbsp; &nbsp;;if 0 go savebit B10<br />SHAFT_2<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC&nbsp; &nbsp;GPIO,4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;same as above to check to the 4th bit<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_A21&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_A20&nbsp; &nbsp; &nbsp;;<br />SHAFT_3<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC&nbsp; &nbsp;GPIO,5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_B21&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SAVEBIT_B20&nbsp; &nbsp; &nbsp;;<br />SAVEBIT_A11<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000001'&nbsp; &nbsp; &nbsp;; if 1 received on shaft channel A move 1 to A11 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVWF&nbsp; &nbsp;A11&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF&nbsp; &nbsp; &nbsp;A11,1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ; rotate left to make bit 0 avaible for channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SHAFT_1&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_A10<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000000'&nbsp; &nbsp; &nbsp;;if 0 received on shaft channel A move 1 to A11 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVWF&nbsp; &nbsp;A11&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF&nbsp; &nbsp; &nbsp;A11,1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;rotate left to make bit 0 avaible for channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SHAFT_1&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_B11<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000001'&nbsp; &nbsp; &nbsp;; if 1 received on shaft channel B move 1 to A11 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF&nbsp; &nbsp;A11,1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;added up with channel B to form 1 complete bit for <br />&nbsp; &nbsp; &nbsp; &nbsp; RLF&nbsp; &nbsp; &nbsp;A11,1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;each turn, rotate left 2 times for next bit of turn <br />&nbsp; &nbsp; &nbsp; &nbsp; RLF A11,1&nbsp; &nbsp; &nbsp; &nbsp;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;of the encoder<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SHAFT_2&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_B10<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000000'&nbsp; &nbsp; &nbsp;; same as above ...for 0 bit on channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF&nbsp; &nbsp;A11,1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF&nbsp; &nbsp; &nbsp;A11,1&nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF A11,1<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SHAFT_2&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_A21<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000001'&nbsp; &nbsp; &nbsp;;if 1 received on shaft channel A move 1 to A21 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVWF&nbsp; &nbsp;A21&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF&nbsp; &nbsp; &nbsp;A21,1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;rotate left to make bit 0 avaible for channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SHAFT_3&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_A20<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000000'&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVWF&nbsp; &nbsp;A21&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;same as above<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF&nbsp; &nbsp; &nbsp;A21,1&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; SHAFT_3&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_B21<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000001'&nbsp; &nbsp; &nbsp;;bit 1 , added up with channel A to form 1 complete bit for<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF&nbsp; &nbsp;A21,0&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;each turn<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF&nbsp; &nbsp;A11,0&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;at here, add up 2 complete bit to determine the <br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; DIRECTION&nbsp; &nbsp; &nbsp; &nbsp;; direction of the shaft encoder...<br />SAVEBIT_B20<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW&nbsp; &nbsp;b'00000000'&nbsp; &nbsp; &nbsp;;same as above, but 0 bit received from previous action<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF&nbsp; &nbsp;A21,0&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF&nbsp; &nbsp;A11,0&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; DIRECTION&nbsp; &nbsp; &nbsp; &nbsp;;<br />DIRECTION<br />&nbsp; &nbsp; &nbsp; &nbsp; CALL&nbsp; &nbsp; TABLE_1&nbsp;; call table to check on the direction after the total 4bit added<br />ANTI_CLOCKWISE<br />&nbsp; &nbsp; &nbsp; &nbsp; BSF&nbsp; &nbsp; &nbsp;GPIO, 0; set gpio 0 high<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BCF &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GPIO,1; clear gpio 1<br />&nbsp; &nbsp; &nbsp; &nbsp; goto&nbsp; &nbsp; START;<br />CLOCKWISE<br />&nbsp; &nbsp; &nbsp; &nbsp; BSF&nbsp; &nbsp; &nbsp;GPIO,1;set gpio 1 high<br />&nbsp; &nbsp; &nbsp; &nbsp; BCF&nbsp; &nbsp; &nbsp;GPIO,0;clear gpio 0<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; START;<br />RESTART_PWM<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; START; no changes go back to start<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; RETURN<br />;************************************************<br />;**** DIRECTION TABLE****************************<br />;************************************************<br /><br />TABLE_1:<br />&nbsp; &nbsp; &nbsp; &nbsp; ADDWF&nbsp; &nbsp;PCL,1&nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; ANTI_CLOCKWISE&nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; CLOCKWISE&nbsp; &nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; CLOCKWISE&nbsp; &nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; ANTI_CLOCKWISE&nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; ANTI_CLOCKWISE&nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; CLOCKWISE&nbsp; &nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; CLOCKWISE&nbsp; &nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; ANTI_CLOCKWISE&nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO&nbsp; &nbsp; RESTART_PWM&nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; RETURN<br />&nbsp;</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>hihi, ajay,my application is for the LED dimmer, i need to know when i am turning clockwise or anti clockwise of the encoder, the light is either dimmer or brighter.i want to know the changes of direction, so i can set the PWM.ThanksAjay, the main problem i m having now is, how to detect the changes of the encoder signal bits, and how to save them efficiently and bring them to determine the direction using IOR table i am using.thanks...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>Welcome back nich well in your program you have used so many returns.. i really have no idea where you're returning  Well minute changes will make your program work..like..CODE:<br />START<br />&nbsp; &nbsp; &nbsp; &nbsp; btfsc&nbsp; &nbsp;GPIO,4; &nbsp; &nbsp;waiting for the encoder changes<br />&nbsp; &nbsp; &nbsp; &nbsp; goto START; keep check for the changes<br />&nbsp; &nbsp; &nbsp; &nbsp; ;call&nbsp; &nbsp;SHAFT_0; changes detected<br />&nbsp; &nbsp; &nbsp; &nbsp; ;No need to call the next statement is same you are going to execute<br />&nbsp;I found that there is no while(1) kind of loop in your program.please tell me what your application is or what you are trying to do in your program, so that i can optimize it better. and please review your code and remove the unwanted returns, because they will make your program to go mad and hang!!</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>I was using both of your idea in my design, i make it working on hardware now...but littlt buggy is that...when u over turned the shaft encoder, the light from the dimmest will changed to Brightest ...lol...little buggy with my code here...need to prevent it to overshoot....thanks anyway...i will figure it out...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>Hi Shyam, wat is mean by wait until states are 1,1 , 0,1  or 1,0 ?is it i need to test the both bit in order to enter the loop for testing the direction?off topic: i havent start to look for job now...i will start this weekend. do u know any job related in UK? thanks...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>shyam</dc:creator>
						<dc:subject></dc:subject>
						<description>hinicholastycif u had searched the forum u wud have found an earlier post on the similar topic.still  lemme tell u one technique which i use..u get two o/p linessay A and Bu get data  in gray code format (cyclic).thhere will be two sets of data1.  clockwise  (depends on what pin A or B is)A|B0|00|11|11|0and2. anticlockwiseA|B0|01|01|10|1now u wud have observed the difference just compare   any two occurance of data and u will find the direction...hope that helps...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>i think something is wrong with my code that its only detects 1 direction!!i have made my program on interrupt on change  to the both input port,the will go into the ISR to save the bit data...but its still failed to detect the correct direction.why?thanks Shyam for your times...i still failed..</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>CODE:<br />for example:<br /><br />START<br />&nbsp; &nbsp; &nbsp; &nbsp; btfss &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GPIO,4; check encoder changes<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto&nbsp; &nbsp; &nbsp; &nbsp;START<br />&nbsp; &nbsp; &nbsp; &nbsp; clrf&nbsp; &nbsp; SWDAT2; clear reg<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;btfss &nbsp; GPIO,4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; if bit A lo<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bsf &nbsp; &nbsp; SWDAT2,0 &nbsp; &nbsp; &nbsp; &nbsp; ; set SWDAT2 bit 0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;btfss &nbsp; GPIO,5 &nbsp;; if bit B lo<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bsf &nbsp; &nbsp; SWDAT2,1 &nbsp; &nbsp; &nbsp; &nbsp; ; set SWDAT2 bit 1<br />&nbsp; &nbsp; &nbsp; &nbsp; movf &nbsp; &nbsp;SWDAT2,W &nbsp; &nbsp; &nbsp; &nbsp;; load switch data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|B0<br />&nbsp; &nbsp; &nbsp; &nbsp; andlw &nbsp; b'00000011' &nbsp; &nbsp; ; mask encoder B and A switches &nbsp; |B0<br />&nbsp; &nbsp; &nbsp; &nbsp; xorwf &nbsp; ENCOLD,W &nbsp; &nbsp; &nbsp; &nbsp;; same as last reading? &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |B0<br />&nbsp; &nbsp; &nbsp; &nbsp; bz &nbsp; &nbsp; &nbsp;START &nbsp; &nbsp; ; yes, branch (no change), else &nbsp; |B0<br />&nbsp; &nbsp; &nbsp; &nbsp; xorwf &nbsp; ENCOLD,W &nbsp; &nbsp; &nbsp; &nbsp;; restore encoder bits in W &nbsp; &nbsp; &nbsp; |B0<br />&nbsp; &nbsp; &nbsp; &nbsp; rrf &nbsp; &nbsp; ENCOLD,f &nbsp; &nbsp; &nbsp; &nbsp;; prep for B-old ^ A-new &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|B0<br />&nbsp; &nbsp; &nbsp; &nbsp; xorwf &nbsp; ENCOLD,f &nbsp; &nbsp; &nbsp; &nbsp;; ENCOLD bit 0 = direction &nbsp; &nbsp; &nbsp; &nbsp;|B0<br />&nbsp; &nbsp; &nbsp; &nbsp; rrf &nbsp; &nbsp; ENCOLD,f &nbsp; &nbsp; &nbsp; &nbsp;; now Carry bit = direction &nbsp; &nbsp; &nbsp; |B0<br />&nbsp; &nbsp; &nbsp; &nbsp; movwf &nbsp; ENCOLD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; update ENCOLD (new BA bits) &nbsp; &nbsp; |B0<br />&nbsp; &nbsp; &nbsp; &nbsp; btfss&nbsp; &nbsp;STATUS,C;<br />&nbsp; &nbsp; &nbsp; &nbsp; goto&nbsp; &nbsp; ANTI_CLOCKWISE;<br />&nbsp; &nbsp; &nbsp; &nbsp; goto&nbsp; &nbsp; CLOCKWISE;<br />&nbsp;i m using pic12f629... can some one suggest me a WORKED code?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>nicholastyc</dc:creator>
						<dc:subject></dc:subject>
						<description>Shyam , Ajay...Arun...i really need help on the encoder part...please help..i already tried my best !i still cant get the right direction ... i m using pic12f629 ...i am using Gpio,4 and gpio,5 as Bit A and Bit B of encoder. 1. clockwise A|B0|00|11|11|0and2. anticlockwiseA|B0|01|01|10|1how to make a correct table? i m trying to make 1...its works on the simulation but failed on hardware...dunno y...do i need the interrupt routine? because i m using the btfss gpio,4 to enter the direction loop and then check on the bit on A and B. same as the code in the thread above...pplease have a look...or give me a code to try...i m so so so depressed!thanks</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>shyam</dc:creator>
						<dc:subject></dc:subject>
						<description>hi nic,well   u do need those A and B pin as interrupt pins..  or else u may miss the step changes..or u can try one thing....   wait until   states are   1,1wait for either  0,1  or 1,0accordigly  u wud come 2 know the direction of rotation..one more point to note..the shaft is usually very sensitive...if u are rotating by self  (ur hand) well u might observe  both the direction    so dont panic .. stay calm cause u are using the right procedure..off topic: any new development regarding your job searh?all the best.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>shyam</dc:creator>
						<dc:subject></dc:subject>
						<description>is it i need to test the both bit in order to enter the loop for testing the direction?nic,take a variable  say int EncCount_int.int EncStateClk_int[]= {3,2,0,1}; int EncStateAntiClk_int[]= {3,1,0,2}; since the encoder is fast enough  ..  there is no harm in waiting for that particular stste that u can mark as START.  case1.  if u r not using the pins as interrupt.start loop.now u will have to make the uC idle untill the next state change..   i.e.  keep checking for the pins untill u notice a change in  either of the pin.read the pins and store in a vriable int Pinval_int;int index =1;now check if  Pinval_int =  EncStateClk_int[index]//  clock wise rotation//decrease  EncCount_int EncCount_int = EncCount_int -1;else//  anticlock wise rotation//increase  EncCount_int EncCount_int=  EncCount_int+1;//increment index; if ( index ==4)index =0;get back to the loopsorry for not being clear enough...   am  amidst a project needing some attention...please se if it helps...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>can i see your code again?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>shyam</dc:creator>
						<dc:subject></dc:subject>
						<description>yes lets see the code again..  the interrupt one.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>sashijoseph</dc:creator>
						<dc:subject></dc:subject>
						<description>Hi Nic,This is a small adaptation of your polling routine using a single variable A11.It savs the current and previous  AB values in this manner as a nibble.... CODE:START<br />&nbsp; &nbsp; &nbsp; &nbsp; CLRF &nbsp; &nbsp;A11 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; clear memory A11<br />&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; BCF &nbsp; &nbsp; STATUS,C; clear carry flag incase there is carry<br /><br />SHAFT_0 &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC &nbsp; GPIO,4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; check on the changes, 0 or 1<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_A11 &nbsp; &nbsp; ; if 1 go savebitA11<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_A10 &nbsp; &nbsp; ;if 0 go savebit A10<br />SHAFT_1<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC &nbsp; GPIO,5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; check on gpio 5 changes, channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_B11 &nbsp; &nbsp; ;if 1 go savebit B11<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_B10 &nbsp; &nbsp; ;if 0 go savebit B10<br />SHAFT_2<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC &nbsp; GPIO,4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;same as above to check to the 4th bit<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_A21 &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_A20 &nbsp; &nbsp; ;<br />SHAFT_3<br />&nbsp; &nbsp; &nbsp; &nbsp; BTFSC &nbsp; GPIO,5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_B21 &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SAVEBIT_B20 &nbsp; &nbsp; ;<br />SAVEBIT_A11<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000001' &nbsp; &nbsp; ; if 1 received on shaft channel A move 1 to A11 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVWF &nbsp; A11 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF &nbsp; &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; rotate left to make bit 0 avaible for channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SHAFT_1 &nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_A10<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000000' &nbsp; &nbsp; ;if 0 received on shaft channel A move 1 to A11 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVWF &nbsp; A11 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF &nbsp; &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;rotate left to make bit 0 avaible for channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SHAFT_1 &nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_B11<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000001' &nbsp; &nbsp; ; if 1 received on shaft channel B move 1 to A11 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;added up with channel B to form 1 complete bit for<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF &nbsp; &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;each turn, rotate left 2 times for next bit of turn<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; of the encoder<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SHAFT_2 &nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_B10<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000000' &nbsp; &nbsp; ; same as above ...for 0 bit on channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF &nbsp; &nbsp; A11,1 &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SHAFT_2 &nbsp; &nbsp; &nbsp; &nbsp; ;<br /><br />SAVEBIT_A21<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000001' &nbsp; &nbsp; ;if 1 received on shaft channel A move 1 to A21 memory<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF &nbsp; &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;rotate left to make bit 0 avaible for channel B<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SHAFT_3 &nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_A20<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000000' &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;same as above<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF &nbsp; &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SHAFT_3 &nbsp; &nbsp; &nbsp; &nbsp; ;<br />SAVEBIT_B21<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000001' &nbsp; &nbsp; ;bit 1 , added up with channel A to form 1 complete bit for<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF &nbsp; A11,1<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;DIRECTION &nbsp; &nbsp; &nbsp; ; direction of the shaft encoder...<br />SAVEBIT_B20<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000000' &nbsp; &nbsp; ;same as above, but 0 bit received from previous action<br />&nbsp; &nbsp; &nbsp; &nbsp; IORWF &nbsp; A11,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;DIRECTION &nbsp; &nbsp; &nbsp; ;<br /><br /><br />RET_FROM_DIRECTION<br />&nbsp; &nbsp; &nbsp; &nbsp; RLF &nbsp; &nbsp; A11,1<br />&nbsp; &nbsp; &nbsp; &nbsp; MOVLW &nbsp; b'00000110'<br />&nbsp; &nbsp; &nbsp; &nbsp; ANDWF &nbsp; A11,1<br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO &nbsp; &nbsp;SHAFT_2<br /><br /><br /><br /><br /><br /><br /><br />DIRECTION<br />&nbsp; &nbsp; &nbsp; &nbsp; ......<br />&nbsp; &nbsp; &nbsp; &nbsp; ......<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; GOTO RET_FROM_DIRECTION</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>sashijoseph</dc:creator>
						<dc:subject></dc:subject>
						<description>Now for the nibble A11 you can have the following valid values0x01,0x07,0x08 and 0x0E representing clockwise directionand0x2,0x04,0x0B,0x0D representing anticlock direction.Thus you need to check the nibble for 1,7,8 or E (hex) for a clockwise rot and 2,4,B or D for anti.Any other value means either no change or invalid... so you need to ignore.In the 'direction' part of the code you need to implement this logic.After that the nibble is rotated left once and 'anded' with 00000110 to save the current AB value(which will now become the previous AB value) and the loop is started again for acquiring  the current AB value.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10071.html">
						<title>Re: a code for the shaft encoder</title>
						<link>http://www.8051projects.net/forum-t10071.html</link>
						<dc:date>2009-01-07T18:15:13-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>Hi nic, i think SJ nailed it !Arun</description>
						</item>
				</rdf:RDF>