Page 1 of 1

Rotary Encoder not working as aspected help? (Solved)

Posted: Fri Jul 20, 2012 9:12 pm
by Jordy101091
Hi all,

Im testing a circuit that involves a rotary encoder, I have copied the schematic from the data sheet of the rotary encoder eblock, I checked it whit my scoop and its the signals are nice and clean.
However when I try to count pulses its not what I suspected. first of all the controller I'm using:

* PIC18F8722
* 25Mhz

I have made a one second flasher and its spot on scoop says 0.998 seconds.
First thing I've done was enabling the encoder. after that a interrupt that responds on a falling edge of RB0/INT0 Why not PORT interrupt, because it was even worse Im getting no result when using port interrupt, any-way in the interrupt I have macro that detects any changes. In the main program I have a loop and two macros one that counts the encoder and the second that displays the result.

The problem here is, Im not getting that smooth counting it jumps from 3 to 8 back to -4 and the back to 9 I don't know what going on.
Can I use a timer interrupt instead of interrupt on Port B0.

Please let me know,

Regards Jordy

PS. if you need the program just say :P

Re: Rotary Encoder not working as aspected help?

Posted: Sat Jul 21, 2012 3:41 pm
by Enamul
hi jordy,

Can you please post your program so that we can have a look what is going wrong?

Enamul

Re: Rotary Encoder not working as aspected help?

Posted: Sat Jul 21, 2012 4:12 pm
by Jordy101091
Here you go Enamul,

The rotary encoder is connected to PORTB.0 (A1)and PORTB.1 (B1)

Hope you can find something.


Regards Jordy

Re: Rotary Encoder not working as aspected help?

Posted: Sat Jul 21, 2012 8:57 pm
by Jordy101091
Email,

I have used à timer interrupt That was running ad 24xxxx MHz I think.
It was fast enough to record any movement of the rotary encoder, a little bit to fast because every dent cause a count of +4.
Slowing the interrupt down was not a success because again at every dent cause a count of +4 also when the encoder turns fast it does not record it. Don't know what I'm doing wrong here.

Hope this help you to find a possible solution.

Best regards jordy kleian

Re: Rotary Encoder not working as aspected help? (Solved)

Posted: Sat Jul 21, 2012 10:21 pm
by Jordy101091
Hi All,

I have solved this problem, the rotary encoder was working the whole time perfectly just the way it supposed to, but not the way I wanted.
The acro for this component has 4 different cases.

Code: Select all

switch (maskcheck)										//Search for current state
		{
			case ( 0 ):
				if ( %a_encoder_mask == 2 )
					%a_encoder_count = %a_encoder_count + 1;
				else
					%a_encoder_count = %a_encoder_count - 1;
				break;

			//case ( 1 ):
				//if ( %a_encoder_mask == 0 )
					//%a_encoder_count = %a_encoder_count + 1;
				//else
					//%a_encoder_count = %a_encoder_count - 1;
				//break;

			//case ( 3 ):
				//if ( %a_encoder_mask == 1 )
					//%a_encoder_count = %a_encoder_count + 1;
				//else
					//%a_encoder_count = %a_encoder_count - 1;
				//break;

			//case ( 2 ):
				//if ( %a_encoder_mask == 3 )
					//%a_encoder_count = %a_encoder_count + 1;
				//else
					//%a_encoder_count = %a_encoder_count - 1;
				//break;
		}
every time the encoder passes a dent it increments 4 times to avoid this behavior I have made the last 3 cases look like comments, now with every dent it increments 1 time ore decrements 1 time.
Problem Fixed.

Regards Jordy

Re: Rotary Encoder not working as aspected help? (Solved)

Posted: Sun Jul 22, 2012 12:31 am
by Enamul
Hi,
I didn't get time to see till now..

When I open again..you already solved the problem. That's great :D

Enamul